module Redis::Commands::List
Direct including types
Defined in:
commands/list.crInstance Method Summary
-
#blpop(keys : Enumerable(String), timeout : Time::Span)
Remove and return an element from the end of the given list.
-
#blpop(*keys : String, timeout : Time::Span)
Remove and return an element from the end of the given list.
-
#blpop(*keys : String, timeout : Int | Float)
Remove and return an element from the end of the given list.
-
#blpop(*keys : String, timeout : String)
Remove and return an element from the end of the given list.
- #brpop(keys : Enumerable(String), timeout : Int)
-
#brpop(*keys : String, timeout : Time::Span)
Remove and return an element from the end of the given list.
-
#brpop(*keys : String, timeout : Number)
Remove and return an element from the end of the given list.
-
#brpop(*keys : String, timeout : String)
Remove and return an element from the end of the given list.
- #brpoplpush(source : String, destination : String, timeout : Time::Span)
- #brpoplpush(source : String, destination : String, timeout : Int | String)
- #llen(key : String)
-
#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.
-
#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. - #lpush(key : String, values : Enumerable(String))
-
#lpush(key, *values : String)
Insert an item at the beginning of a list, returning the number of items in the list after the insert.
- #lrange(key : String, start : String | Int, finish : String | Int)
- #lrem(key : String, count : Int, value : String)
-
#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. -
#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. -
#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. -
#rpop(key : String)
Remove and return an element from the end of the given list.
-
#rpoplpush(source : String, destination : String)
Atomically remove an item from the end of a list and insert it at the beginning of another.
DEPRECATED Use the
#lmove
method instead. See the Redis docs for more inforamtion. - #rpush(key : String, values : Enumerable(String))
-
#rpush(key, *values : String)
Insert an item at the end of a list, returning the number of items in the list after the insert.
Instance Method Detail
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)
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)
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)
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)
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)
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)
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)
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
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
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
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
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
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
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
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.
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