Class: Matching::RedisIndex
- Inherits:
-
Object
- Object
- Matching::RedisIndex
- Defined in:
- lib/matching/redis_index.rb
Instance Method Summary collapse
-
#get(attr, val) ⇒ Object
Return an array of object ids for a given attribute and value.
-
#initialize(db_num = 8) ⇒ RedisIndex
constructor
A new instance of RedisIndex.
-
#put(attr, val, id) ⇒ Object
Add a value to the index for a given attribute and object id.
Constructor Details
#initialize(db_num = 8) ⇒ RedisIndex
Returns a new instance of RedisIndex.
6 7 8 9 10 |
# File 'lib/matching/redis_index.rb', line 6 def initialize(db_num=8) @redis = Redis.new @redis.select(db_num) @redis.flushdb end |
Instance Method Details
#get(attr, val) ⇒ Object
Return an array of object ids for a given attribute and value
20 21 22 23 |
# File 'lib/matching/redis_index.rb', line 20 def get(attr, val) str_ids = @redis.smembers("#{attr}:#{val}") (str_ids.any? ? str_ids.map { |a| a.to_i } : nil) end |
#put(attr, val, id) ⇒ Object
Add a value to the index for a given attribute and object id
13 14 15 16 17 |
# File 'lib/matching/redis_index.rb', line 13 def put(attr, val, id) unless val.nil? @redis.sadd("#{attr}:#{val}",id) end end |