class Matching::RedisIndex
Public Class Methods
new(db_num=8)
click to toggle source
# File lib/matching/redis_index.rb, line 6 def initialize(db_num=8) @redis = Redis.new @redis.select(db_num) @redis.flushdb end
Public Instance Methods
get(attr, val)
click to toggle source
Return an array of object ids for a given attribute and value
# 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)
click to toggle source
Add a value to the index for a given attribute and object id
# File lib/matching/redis_index.rb, line 13 def put(attr, val, id) unless val.nil? @redis.sadd("#{attr}:#{val}",id) end end