Class: Maxwell::Agent::RedisObjects::SortedSet
- Inherits:
-
Object
- Object
- Maxwell::Agent::RedisObjects::SortedSet
- Includes:
- Maxwell::Agent::RedisObjects
- Defined in:
- lib/maxwell/agent/redis_objects/sorted_set.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #add(score, object) ⇒ Object
- #all ⇒ Object
- #count ⇒ Object
- #first ⇒ Object
-
#initialize(name) ⇒ SortedSet
constructor
A new instance of SortedSet.
- #remove(item) ⇒ Object
Methods included from Maxwell::Agent::RedisObjects
Constructor Details
#initialize(name) ⇒ SortedSet
Returns a new instance of SortedSet.
8 9 10 |
# File 'lib/maxwell/agent/redis_objects/sorted_set.rb', line 8 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/maxwell/agent/redis_objects/sorted_set.rb', line 6 def name @name end |
Instance Method Details
#add(score, object) ⇒ Object
12 13 14 |
# File 'lib/maxwell/agent/redis_objects/sorted_set.rb', line 12 def add(score, object) redis { |redis| redis.zadd name, score, object.to_json } end |
#all ⇒ Object
20 21 22 |
# File 'lib/maxwell/agent/redis_objects/sorted_set.rb', line 20 def all redis {|redis| redis.zrange name, 0, -1 } end |
#count ⇒ Object
16 17 18 |
# File 'lib/maxwell/agent/redis_objects/sorted_set.rb', line 16 def count redis {|redis| redis.zcard name } end |
#first ⇒ Object
24 25 26 |
# File 'lib/maxwell/agent/redis_objects/sorted_set.rb', line 24 def first redis { |redis| redis.zrange(name, 0, 0)[0] } end |
#remove(item) ⇒ Object
28 29 30 |
# File 'lib/maxwell/agent/redis_objects/sorted_set.rb', line 28 def remove(item) redis { |redis| redis.zrem name, item.to_json } end |