module Lite::Redis::ListHelper
Public Instance Methods
all(key)
click to toggle source
# File lib/lite/redis/helpers/list_helper.rb, line 29 def all(key) client.lrange(key.to_s, 0, -1) end
between(key, start = 1, finish = 0)
click to toggle source
# File lib/lite/redis/helpers/list_helper.rb, line 25 def between(key, start = 1, finish = 0) client.lrange(key.to_s, start - 1, finish - 1) end
count(key)
click to toggle source
# File lib/lite/redis/helpers/list_helper.rb, line 33 def count(key) client.llen(key.to_s) end
create(key, value, order = :prepend)
click to toggle source
# File lib/lite/redis/helpers/list_helper.rb, line 37 def create(key, value, order = :prepend) if append?(order) client.rpush(key.to_s, value) else client.lpush(key.to_s, value) end end
create!(key, value, order = :prepend)
click to toggle source
# File lib/lite/redis/helpers/list_helper.rb, line 45 def create!(key, value, order = :prepend) if append?(order) client.rpushx(key.to_s, value) else client.lpushx(key.to_s, value) end end
create_after(key, pivot, value)
click to toggle source
# File lib/lite/redis/helpers/list_helper.rb, line 77 def create_after(key, pivot, value) client.linsert(key.to_s, :after, pivot, value) end
create_before(key, pivot, value)
click to toggle source
# File lib/lite/redis/helpers/list_helper.rb, line 73 def create_before(key, pivot, value) client.linsert(key.to_s, :before, pivot, value) end
create_limit(key, value, limit, order = :prepend)
click to toggle source
# File lib/lite/redis/helpers/list_helper.rb, line 53 def create_limit(key, value, limit, order = :prepend) if append?(order) client.rpush(key.to_s, value) else client.lpush(key.to_s, value) end client.ltrim(key.to_s, 0, limit - 1) end
create_limit!(key, value, limit, order = :prepend)
click to toggle source
# File lib/lite/redis/helpers/list_helper.rb, line 63 def create_limit!(key, value, limit, order = :prepend) if append?(order) client.rpushx(key.to_s, value) else client.lpushx(key.to_s, value) end client.ltrim(key.to_s, 0, limit - 1) end
destroy(key, count, value)
click to toggle source
# File lib/lite/redis/helpers/list_helper.rb, line 93 def destroy(key, count, value) client.lrem(key.to_s, count, value) end
destroy_all(key)
click to toggle source
# File lib/lite/redis/helpers/list_helper.rb, line 109 def destroy_all(key) client.ltrim(key.to_s, -1, 0) end
destroy_except(key, start, finish)
click to toggle source
# File lib/lite/redis/helpers/list_helper.rb, line 105 def destroy_except(key, start, finish) client.ltrim(key.to_s, start - 1, finish - 1) end
destroy_first(key, limit = 1)
click to toggle source
# File lib/lite/redis/helpers/list_helper.rb, line 97 def destroy_first(key, limit = 1) client.ltrim(key.to_s, limit, -1) end
destroy_last(key, limit = 1)
click to toggle source
# File lib/lite/redis/helpers/list_helper.rb, line 101 def destroy_last(key, limit = 1) client.ltrim(key.to_s, 0, -(limit + 1)) end
find(key, position = 1)
click to toggle source
# File lib/lite/redis/helpers/list_helper.rb, line 7 def find(key, position = 1) client.lindex(key.to_s, position - 1) end
first(key, limit = 1)
click to toggle source
# File lib/lite/redis/helpers/list_helper.rb, line 11 def first(key, limit = 1) value = client.lrange(key.to_s, 0, -1) return value.first if limit == 1 value.first(limit) end
last(key, limit = 1)
click to toggle source
# File lib/lite/redis/helpers/list_helper.rb, line 18 def last(key, limit = 1) value = client.lrange(key.to_s, 0, -1) return value.last if limit == 1 value.last(limit) end
move(key, desination)
click to toggle source
# File lib/lite/redis/helpers/list_helper.rb, line 85 def move(key, desination) client.rpoplpush(key.to_s, desination.to_s) end
move_blocking(key, desination)
click to toggle source
# File lib/lite/redis/helpers/list_helper.rb, line 89 def move_blocking(key, desination) brpoplpush(key.to_s, desination.to_s) end
pop(key, order = :prepend)
click to toggle source
# File lib/lite/redis/helpers/list_helper.rb, line 113 def pop(key, order = :prepend) if append?(order) client.rpop(key) else client.lpop(key) end end
pop_blocking(keys, opts = {})
click to toggle source
# File lib/lite/redis/helpers/list_helper.rb, line 121 def pop_blocking(keys, opts = {}) timeout = opts[:timeout] || 0 if append?(opts[:order] || :prepend) client.brpop(keys, timeout) else client.blpop(keys, timeout) end end
update(key, index, value)
click to toggle source
# File lib/lite/redis/helpers/list_helper.rb, line 81 def update(key, index, value) client.lset(key.to_s, index, value) end