Class: MessageQueue
- Inherits:
-
RedisConnection
- Object
- RedisConnection
- MessageQueue
- Defined in:
- lib/redis_store.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Attributes inherited from RedisConnection
Instance Method Summary collapse
-
#del ⇒ Object
end push.
- #info ⇒ Object
-
#initialize(key) ⇒ MessageQueue
constructor
A new instance of MessageQueue.
- #pop ⇒ Object
-
#push(item) ⇒ Object
end pop.
- #size ⇒ Object
- #to_s ⇒ Object
Methods inherited from RedisConnection
Constructor Details
#initialize(key) ⇒ MessageQueue
Returns a new instance of MessageQueue.
27 28 29 30 |
# File 'lib/redis_store.rb', line 27 def initialize key @key = key super end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
25 26 27 |
# File 'lib/redis_store.rb', line 25 def key @key end |
Instance Method Details
#del ⇒ Object
end push
44 45 46 |
# File 'lib/redis_store.rb', line 44 def del @redis.del @key end |
#info ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/redis_store.rb', line 52 def info out = "items in list:".ljust(25) + size.to_s + "\n" out += "number of keys:".ljust(25) + @redis.dbsize.to_s + "\n" %w{ used_memory_human used_memory_peak_human total_commands_processed}.each do |w| out += "#{w.gsub("_", " ")}:".ljust(25) out += @redis.info[w] out += "\n" end return out end |
#pop ⇒ Object
32 33 34 |
# File 'lib/redis_store.rb', line 32 def pop() @redis.blpop(@key)[1] end |
#push(item) ⇒ Object
end pop
36 37 38 39 40 41 42 |
# File 'lib/redis_store.rb', line 36 def push(item) redis.pipelined do @redis.hincrby "counters", @key, 1 #@redis.hincrby "ts:counters", keygen+"_count", 1 @redis.rpush(@key, item ) end end |
#size ⇒ Object
48 49 50 |
# File 'lib/redis_store.rb', line 48 def size @redis.llen @key end |
#to_s ⇒ Object
63 64 65 |
# File 'lib/redis_store.rb', line 63 def to_s @key end |