Class: Maxwell::Agent::RedisObjects::SortedSet

Inherits:
Object
  • Object
show all
Includes:
Maxwell::Agent::RedisObjects
Defined in:
lib/maxwell/agent/redis_objects/sorted_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Maxwell::Agent::RedisObjects

included, #redis

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

#nameObject (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

#allObject



20
21
22
# File 'lib/maxwell/agent/redis_objects/sorted_set.rb', line 20

def all
  redis {|redis| redis.zrange name, 0, -1 }
end

#countObject



16
17
18
# File 'lib/maxwell/agent/redis_objects/sorted_set.rb', line 16

def count
  redis {|redis| redis.zcard name }
end

#firstObject



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