Class: MessageQueue

Inherits:
RedisConnection show all
Defined in:
lib/redis_store.rb

Direct Known Subclasses

ObjectQueue

Instance Attribute Summary collapse

Attributes inherited from RedisConnection

#redis

Instance Method Summary collapse

Methods inherited from RedisConnection

#counters

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

#keyObject (readonly)

Returns the value of attribute key.



25
26
27
# File 'lib/redis_store.rb', line 25

def key
  @key
end

Instance Method Details

#delObject

end push



44
45
46
# File 'lib/redis_store.rb', line 44

def del
  @redis.del @key
end

#infoObject



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

#popObject



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

#sizeObject



48
49
50
# File 'lib/redis_store.rb', line 48

def size
  @redis.llen @key
end

#to_sObject



63
64
65
# File 'lib/redis_store.rb', line 63

def to_s
  @key
end