Created
October 10, 2013 12:34
-
-
Save deltheil/6917586 to your computer and use it in GitHub Desktop.
Use Ohm to illustrate how to manage an index within Redis. See http://stackoverflow.com/a/19289987/1688185.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "ohm" | |
class Doc < Ohm::Model | |
attribute :colour | |
index :colour | |
end | |
Doc.create(:colour => "red") | |
Doc.create(:colour => "green") | |
Doc.create(:colour => "red") | |
# redis> SMEMBERS "Doc:indices:colour:red" | |
# 1) "1" | |
# 2) "3" | |
Doc.create(:colour => "red") | |
# redis> SMEMBERS "Doc:indices:colour:red" | |
# 1) "1" | |
# 2) "3" | |
# 3) "4" | |
Doc.find(:colour => "red").each {|d| puts d.id} | |
# 1 | |
# 3 | |
# 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment