module

Redis::Commands::List

Instance methods

blpop(keys : Enumerable(String), timeout : Time::Span)

Remove and return an element from the end of the given list. If the list is empty or the key does not exist, this method waits the specified amount of time for an element to be added to it by another connection. If the element is added by another connection within that amount of time, this method will return it immediately. If it is not, then this method returns nil.

keys = %w[foo bar]
redis.rpush "foo", "first"
spawn do
  sleep 100.milliseconds
  redis.rpush "foo", "second"
end
redis.blpop keys, 1.second # => "first"
redis.blpop keys, 1.second # => "second" (after 100 milliseconds)
redis.blpop keys, 1.second # => nil (after 1 second)
Source
blpop(*keys : String, timeout : Time::Span)

Remove and return an element from the end of the given list. If the list is empty or the key does not exist, this method waits the specified amount of time for an element to be added to it by another connection. If the element is added by another connection within that amount of time, this method will return it immediately. If it is not, then this method returns nil.

redis.rpush "foo", "first"
spawn do
  sleep 100.milliseconds
  redis.rpush "foo", "second"
end
redis.blpop "foo", 1.second # => "first"
redis.blpop "foo", 1.second # => "second" (after 100 milliseconds)
redis.blpop "foo", 1.second # => nil (after 1 second)
Source
blpop(*keys : String, timeout : Int | Float)

Remove and return an element from the end of the given list. If the list is empty or the key does not exist, this method waits the specified number of seconds for an element to be added to it by another connection. If the element is added by another connection within that number of seconds, this method will return it immediately. If it is not, then this method returns nil.

redis.lpush "foo", "first"
spawn do
  sleep 100.milliseconds
  redis.lpush "foo", "second"
end
redis.blpop "foo", 1 # => "first"
redis.blpop "foo", 1 # => "second" (after 100 milliseconds)
redis.blpop "foo", 1 # => nil (after 1 second)
Source
blpop(*keys : String, timeout : String)

Remove and return an element from the end of the given list. If the list is empty or the key does not exist, this method waits the specified number of seconds for an element to be added to it by another connection. If the element is added by another connection within that number of seconds, this method will return it immediately. If it is not, then this method returns nil.

redis.lpush "foo", "first"
spawn do
  sleep 100.milliseconds
  redis.lpush "foo", "second"
end
redis.blpop "foo", "1" # => "first"
redis.blpop "foo", "1" # => "second" (after 100 milliseconds)
redis.blpop "foo", "1" # => nil (after 1 second)
Source
brpop(keys : Enumerable(String), timeout : Int)
Source
brpop(*keys : String, timeout : Time::Span)

Remove and return an element from the end of the given list. If the list is empty or the key does not exist, this method waits the specified amount of time for an element to be added to it by another connection. If the element is added by another connection within that amount of time, this method will return it immediately. If it is not, then this method returns nil.

redis.lpush "foo", "first"
spawn do
  sleep 100.milliseconds
  redis.lpush "foo", "second"
end
redis.brpop "foo", 1.second # => "first"
redis.brpop "foo", 1.second # => "second" (after 100 milliseconds)
redis.brpop "foo", 1.second # => nil (after 1 second)
Source
brpop(*keys : String, timeout : Number)

Remove and return an element from the end of the given list. If the list is empty or the key does not exist, this method waits the specified number of seconds for an element to be added to it by another connection. If the element is added by another connection within that number of seconds, this method will return it immediately. If it is not, then this method returns nil.

redis.lpush "foo", "first"
spawn do
  sleep 100.milliseconds
  redis.lpush "foo", "second"
end
redis.brpop "foo", 1 # => "first"
redis.brpop "foo", 1 # => "second" (after 100 milliseconds)
redis.brpop "foo", 1 # => nil (after 1 second)
Source
brpop(*keys : String, timeout : String)

Remove and return an element from the end of the given list. If the list is empty or the key does not exist, this method waits the specified number of seconds for an element to be added to it by another connection. If the element is added by another connection within that number of seconds, this method will return it immediately. If it is not, then this method returns nil.

redis.lpush "foo", "first"
spawn do
  sleep 100.milliseconds
  redis.lpush "foo", "second"
end
redis.brpop "foo", "1" # => "first"
redis.brpop "foo", "1" # => "second" (after 100 milliseconds)
redis.brpop "foo", "1" # => nil (after 1 second)
Source
brpoplpush(source : String, destination : String, timeout : Time::Span)
Source
brpoplpush(source : String, destination : String, timeout : Int | String)
Source
llen(key : String)
Source
lmove(from source : String, to destination : String, from_side source_side : Side, to_side destination_side : Side)

Atomically remove an item from the end of a list and insert it at the beginning of another. Returns that list item. If the first list is empty, nothing happens and this method returns nil.

redis.del "foo"
redis.lpush "foo", "hello", "world"
redis.lmove "foo", "bar" # => "hello"
redis.lmove "foo", "bar" # => "world"
redis.lmove "foo", "bar" # => nil
Source
lpop(key : String, count : String | Nil = nil)

Remove an item from the beginning of a list, returning the item or nil if the list was empty.

redis.del "my-list" # Delete so we know it's empty
redis.lpush "my-list", "foo"
redis.lpop "my-list" # => "foo"
redis.lpop "my-list" # => nil
Source
lpush(key : String, values : Enumerable(String))
Source
lpush(key, *values : String)

Insert an item at the beginning of a list, returning the number of items in the list after the insert.

redis.del "my-list"                 # Delete so we know it's empty
redis.lpush "my-list", "foo", "bar" # => 2
redis.lpush "my-list", "foo", "bar" # => 4
Source
lrange(key : String, start : String | Int, finish : String | Int)
Source
lrem(key : String, count : Int, value : String)
Source
ltrim(key : String, start : String | Int, stop : String | Int)

Trim the list contained in key so that it contains only the values at the indices in the given range.

redis.rpush "ids", %w[0 1 2 3 4 5 6 7 8 9]
redis.ltrim "ids", 1, 2
Source
ltrim(key : String, range : Range(String, String))

Trim the list contained in key so that it contains only the values at the indices in the given range.

redis.rpush "ids", %w[0 1 2 3 4 5 6 7 8 9]
start, stop = "1,2".split(',')
redis.ltrim "ids", start..stop
Source
ltrim(key : String, range : Range(Int32, Int32))

Trim the list contained in key so that it contains only the values at the indices in the given range.

redis.rpush "ids", %w[0 1 2 3 4 5 6 7 8 9]
redis.ltrim "ids", 1..2
Source
rpop(key : String)

Remove and return an element from the end of the given list. If the list is empty or the key does not exist, this method returns nil

redis.lpush "foo", "hello"
redis.rpop "foo" # => "hello"
redis.rpop "foo" # => nil
Source
rpoplpush(source : String, destination : String)

Atomically remove an item from the end of a list and insert it at the beginning of another. Returns that list item. If the first list is empty, nothing happens and this method returns nil.

redis.del "foo"
redis.lpush "foo", "hello", "world"
redis.rpoplpush "foo", "bar" # => "hello"
redis.rpoplpush "foo", "bar" # => "world"
redis.rpoplpush "foo", "bar" # => nil
Source
rpush(key : String, values : Enumerable(String))
Source
rpush(key, *values : String)

Insert an item at the end of a list, returning the number of items in the list after the insert.

redis.del "my-list"                 # Delete so we know it's empty
redis.rpush "my-list", "foo", "bar" # => 2
redis.rpush "my-list", "foo", "bar" # => 4
Source

Nested types