class Collectr::RedisArray
Public Class Methods
new(name, options={})
click to toggle source
# File lib/collectr/redis/redis_array.rb, line 7 def initialize(name, options={}) @title = name @max_size = options[:max_size] if options.has_key?(:max_size) @datastore = options[:datastore] if options.has_key?(:datastore) end
Public Instance Methods
<<(obj)
click to toggle source
# File lib/collectr/redis/redis_array.rb, line 17 def <<(obj) add obj end
[](n)
click to toggle source
# File lib/collectr/redis/redis_array.rb, line 29 def [](n) deserialize(datastore.lindex @title, n) end
add(obj)
click to toggle source
# File lib/collectr/redis/redis_array.rb, line 21 def add(obj) datastore.rpush @title, serialize(obj) len = size if @max_size and len>@max_size datastore.ltrim @title, len-@max_size, -1 end end
clear()
click to toggle source
# File lib/collectr/redis/redis_array.rb, line 49 def clear datastore.ltrim @title, 0, 0 datastore.lpop @title end
datastore()
click to toggle source
# File lib/collectr/redis/redis_array.rb, line 13 def datastore @datastore ||= Redis.current end
delete(obj)
click to toggle source
# File lib/collectr/redis/redis_array.rb, line 37 def delete(obj) datastore.lrem @title, 0, serialize(obj) end
pop()
click to toggle source
# File lib/collectr/redis/redis_array.rb, line 33 def pop deserialize(datastore.lpop @title) end
size()
click to toggle source
# File lib/collectr/redis/redis_array.rb, line 41 def size datastore.llen @title end
to_a()
click to toggle source
# File lib/collectr/redis/redis_array.rb, line 45 def to_a datastore.lrange(@title, 0, -1).collect{ |i| deserialize(i) } end