module Redis::Commands::List

Direct including types

Defined in:

commands/list.cr

Instance Method Summary

Instance Method Detail

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 llen(key : String) #

[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, finish : String) #

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

[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

[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]