module Redis::Commands::List

Direct including types

Defined in:

commands/list.cr

Instance Method Summary

Instance Method Detail

def 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)

[View source]
def 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)

[View source]
def 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)

[View source]
def 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)

[View source]
def brpop(keys : Enumerable(String), timeout : Int) #

[View source]
def 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)

[View source]
def 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)

[View source]
def 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)

[View source]
def brpoplpush(source : String, destination : String, timeout : Time::Span) #

[View source]
def brpoplpush(source : String, destination : String, timeout : Int | String) #

[View source]
def llen(key : String) #

[View source]
def 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

[View source]
def 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

[View source]
def lpush(key : String, values : Enumerable(String)) #

[View source]
def 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

[View source]
def lrange(key : String, start : String | Int, finish : String | Int) #

[View source]
def lrem(key : String, count : Int, value : String) #

[View source]
def 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

[View source]
def 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

[View source]
def 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

[View source]
def 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

[View source]
def 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

DEPRECATED Use the #lmove method instead. See the Redis docs for more inforamtion.


[View source]
def rpush(key : String, values : Enumerable(String)) #

[View source]
def 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

[View source]