Class: Conflow::Redis::SortedSetField Private
- Defined in:
- lib/conflow/redis/sorted_set_field.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Represents Redis sorted set. Closest Ruby representation is a Hash where keys are elements of the set and values represent score.
Instance Attribute Summary
Attributes inherited from Field
Instance Method Summary collapse
-
#[](value) ⇒ String
private
Access score of given element.
-
#add(hash) ⇒ String
private
Adds one or more keys to the set.
-
#delete(value) ⇒ Integer
private
Remove element from the set.
-
#overwrite(hash) ⇒ String
private
Removes old values from the set and overrides them with new.
-
#size ⇒ Integer
private
Number of elements in the set.
-
#to_h ⇒ Hash
private
Creates regular Ruby Hash based on Redis values.
Methods inherited from Field
Constructor Details
This class inherits a constructor from Conflow::Redis::Field
Instance Method Details
#[](value) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Access score of given element.
25 26 27 |
# File 'lib/conflow/redis/sorted_set_field.rb', line 25 def [](value) command :zscore, [key, value] end |
#add(hash) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Adds one or more keys to the set.
15 16 17 |
# File 'lib/conflow/redis/sorted_set_field.rb', line 15 def add(hash) command :zadd, [key, hash_to_array(hash)] end |
#delete(value) ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Remove element from the set.
44 45 46 |
# File 'lib/conflow/redis/sorted_set_field.rb', line 44 def delete(value) command :zrem, [key, value] end |
#overwrite(hash) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Removes old values from the set and overrides them with new.
57 58 59 60 61 62 63 64 |
# File 'lib/conflow/redis/sorted_set_field.rb', line 57 def overwrite(hash) redis.with do |conn| conn.pipelined do conn.del(key) conn.zadd(key, hash_to_array(hash)) end end end |
#size ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Number of elements in the set
34 35 36 |
# File 'lib/conflow/redis/sorted_set_field.rb', line 34 def size command :zcard, [key] end |
#to_h ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates regular Ruby Hash based on Redis values.
50 51 52 |
# File 'lib/conflow/redis/sorted_set_field.rb', line 50 def to_h Hash[command :zrange, [key, 0, -1, with_scores: true]] end |