Class: RediSet::Client
- Inherits:
-
Object
- Object
- RediSet::Client
- Defined in:
- lib/redi_set/client.rb
Instance Attribute Summary collapse
-
#redis ⇒ Object
readonly
Returns the value of attribute redis.
Instance Method Summary collapse
-
#initialize(redis: nil, redis_config: nil) ⇒ Client
constructor
A new instance of Client.
- #match(constraint_hash) ⇒ Object
- #set_all!(attribute_name, quality_name, ids) ⇒ Object
-
#set_details!(id, details) ⇒ Object
details here is a three-layer hash: attribute_name => quality_name => boolean.
Constructor Details
#initialize(redis: nil, redis_config: nil) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 10 11 12 13 |
# File 'lib/redi_set/client.rb', line 5 def initialize(redis: nil, redis_config: nil) if redis @redis = redis elsif redis_config @redis = Redis.new(redis_config) else fail ArgumentError, "redis or redis_config must be supplied to the RediSet::Client" end end |
Instance Attribute Details
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
3 4 5 |
# File 'lib/redi_set/client.rb', line 3 def redis @redis end |
Instance Method Details
#match(constraint_hash) ⇒ Object
15 16 17 |
# File 'lib/redi_set/client.rb', line 15 def match(constraint_hash) RediSet::Query.from_hash(constraint_hash).execute(@redis) end |
#set_all!(attribute_name, quality_name, ids) ⇒ Object
19 20 21 22 23 |
# File 'lib/redi_set/client.rb', line 19 def set_all!(attribute_name, quality_name, ids) attribute = Attribute.new(name: attribute_name) quality = Quality.new(attribute: attribute, name: quality_name) quality.set_all!(@redis, ids) end |
#set_details!(id, details) ⇒ Object
details here is a three-layer hash: attribute_name => quality_name => boolean. only specified attribute/qualities will be updated.
27 28 29 30 31 32 33 |
# File 'lib/redi_set/client.rb', line 27 def set_details!(id, details) possessed_qualities, lacked_qualities = Quality.collect_from_details(details) @redis.multi do possessed_qualities.each { |q| @redis.sadd(q.key, id) } lacked_qualities.each { |q| @redis.srem(q.key, id) } end end |