module RedisLike::Lists
Mixin containing redis-like list operations for Moneta
stores.
Public Instance Methods
blpop(list)
click to toggle source
# File lib/redislike/lists.rb, line 27 def blpop(list) block_while_empty list lpop list end
brpop(list)
click to toggle source
# File lib/redislike/lists.rb, line 40 def brpop(list) block_while_empty list rpop list end
brpoplpush(source, destination)
click to toggle source
# File lib/redislike/lists.rb, line 51 def brpoplpush(source, destination) block_while_empty source rpoplpush source, destination end
lindex(list, item)
click to toggle source
# File lib/redislike/lists.rb, line 56 def lindex(list, item) fetch(list, []).at item end
linsert(list, location, pivot, item)
click to toggle source
# File lib/redislike/lists.rb, line 60 def linsert(list, location, pivot, item) return 0 unless exists list return -1 unless lrange(list, 0, -1).include? pivot items = fetch list, [] index = items.index pivot index += 1 if location == :before items.insert(index, item) store list, items llen list end
llen(list)
click to toggle source
# File lib/redislike/lists.rb, line 71 def llen(list) fetch(list, []).length end
lpop(list)
click to toggle source
# File lib/redislike/lists.rb, line 32 def lpop(list) dequeue list, from: :head end
lpush(list, item)
click to toggle source
# File lib/redislike/lists.rb, line 11 def lpush(list, item) enqueue list, item, to: :head end
lpushx(list, item)
click to toggle source
# File lib/redislike/lists.rb, line 15 def lpushx(list, item) enqueue list, item, to: :head, allow_create: false end
lrange(list, start, stop)
click to toggle source
# File lib/redislike/lists.rb, line 75 def lrange(list, start, stop) fetch(list, [])[(start..stop)] || [] end
lrem(list, count, item)
click to toggle source
# File lib/redislike/lists.rb, line 79 def lrem(list, count, item) case when count > 0 remove_count list, count, item, from: :head when count < 0 remove_count list, count.abs, item, from: :tail when count == 0 remove_all list, item end end
lset(list, index, item)
click to toggle source
# File lib/redislike/lists.rb, line 90 def lset(list, index, item) fail KeyError, 'ERR no such key' unless exists(list) fail IndexError, 'ERR index out of range' unless lindex(list, index) items = fetch list, [] items[index] = item 'OK' if store list, items end
ltrim(list, start, stop)
click to toggle source
# File lib/redislike/lists.rb, line 98 def ltrim(list, start, stop) 'OK' if store list, lrange(list, start, stop) end
rpop(list)
click to toggle source
# File lib/redislike/lists.rb, line 36 def rpop(list) dequeue list, from: :tail end
rpoplpush(source, destination)
click to toggle source
# File lib/redislike/lists.rb, line 45 def rpoplpush(source, destination) item = rpop source lpush destination, item item end
rpush(list, item)
click to toggle source
# File lib/redislike/lists.rb, line 19 def rpush(list, item) enqueue list, item, to: :tail end
rpushx(list, item)
click to toggle source
# File lib/redislike/lists.rb, line 23 def rpushx(list, item) enqueue list, item, to: :tail, allow_create: false end