Skip to content

Instantly share code, notes, and snippets.

@deltheil
Created October 10, 2013 12:34
Show Gist options
  • Save deltheil/6917586 to your computer and use it in GitHub Desktop.
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.
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