Class: Conflow::Redis::SetField
- Includes:
- Enumerable
- Defined in:
- lib/conflow/redis/set_field.rb
Overview
Represents Redis list. It’s methods mirror most used Set methods.
Instance Attribute Summary
Attributes inherited from Field
Instance Method Summary collapse
-
#add(*values) ⇒ String
Adds one or more elements to the set.
-
#overwrite(enumerable) ⇒ String
Removes old values from the set and overrides them with new.
-
#size ⇒ Integer
Number of elements in the set.
-
#to_a ⇒ Array
(also: #to_ary)
Returns array with set values.
Methods inherited from Field
Constructor Details
This class inherits a constructor from Conflow::Redis::Field
Instance Method Details
#add(*values) ⇒ String
Adds one or more elements to the set.
15 16 17 |
# File 'lib/conflow/redis/set_field.rb', line 15 def add(*values) command :sadd, [key, values] end |
#overwrite(enumerable) ⇒ String
Removes old values from the set and overrides them with new.
27 28 29 30 31 32 33 34 |
# File 'lib/conflow/redis/set_field.rb', line 27 def overwrite(enumerable) redis.with do |conn| conn.pipelined do conn.del(key) conn.sadd(key, enumerable) end end end |
#size ⇒ Integer
Returns Number of elements in the set.
20 21 22 |
# File 'lib/conflow/redis/set_field.rb', line 20 def size command :scard, [key] end |
#to_a ⇒ Array Also known as: to_ary
Returns array with set values
38 39 40 |
# File 'lib/conflow/redis/set_field.rb', line 38 def to_a command :smembers, [key] end |