sider.list
— List objects¶
See also
- Redis Data Types
- The Redis documentation that explains about its data types: strings, lists, sets, sorted sets and hashes.
-
class
sider.list.
List
(session, key, value_type=<class 'sider.types.ByteString'>)¶ The Python-side representaion of Redis list value. It behaves alike built-in Python
list
object. More exactly, it implementscollections.MutableSequence
protocol.Mappings of Redis commands– List
methods¶Redis commands List
methodsLLEN len()
(List.__len__()
)LPUSH List.insert()
LPUSHX N/A LPOP List.pop()
RPUSH List.append()
,List.extend()
RPUSHX N/A RPOP List.pop()
RPOPLPUSH N/A LINDEX List.__getitem__()
,LINSERT N/A LRANGE iter()
(List.__iter__()
),List.__getitem__()
,LREM N/A LTRIM del
(List.__delitem__()
)DEL del
(List.__delitem__()
)LSET =
(List.__setitem__()
)BLPOP N/A BRPOP N/A BRPOPLPUSH N/A -
append
(*args, **kwargs)¶ Inserts the
value
at the tail of the list.Parameters: value – an value to insert
-
extend
(iterable)¶ Extends the list with the
iterable
.Parameters: iterable ( collections.Iterable
) – an iterable object that extend the list withRaises: exceptions.TypeError – if the given iterable
is not iterableWarning
Appending multiple values is supported since Redis 2.4.0. This may send RPUSH multiple times in a transaction if Redis version is not 2.4.0 nor higher.
-
insert
(index, value)¶ Inserts the
value
right after the offsetindex
.Parameters: - index (
numbers.Integral
) – the offset of the next before the place wherevalue
would be inserted to - value – the value to insert
Raises: exceptions.TypeError – if the given
index
is not an integerWarning
Redis does not provide any primitive operations for random insertion. You only can prepend or append a value into lists. If index is 0 it’ll send LPUSH command, but otherwise it inefficiently LRANGE the whole list to manipulate it in offline, and then DEL the key so that empty the whole list, and then RPUSH the whole result again. Moreover all the commands execute in a transaction.
So you should not treat this method as the same method of Python built-in
list
object. It is just for being compatible tocollections.MutableSequence
protocol.If it faced the case, it also will warn you
PerformanceWarning
.- index (
-
pop
(index=-1, _stacklevel=1)¶ Removes and returns an item at
index
. Negative index meanslen(list) + index
(counts from the last).Parameters: - index (
numbers.Integral
) – an index of an item to remove and return - _stacklevel (
numbers.Integral
) – internal use only. base stacklevel for warning. default is 1
Returns: the removed element
Raises: - exceptions.IndexError – if the given
index
doesn’t exist - exceptions.TypeError – if the given
index
is not an integer
Warning
Redis doesn’t offer any primitive operations for random deletion. You can pop only the last or the first. Other middle elements cannot be popped in a command, so it emulates the operation inefficiently.
Internal emulation routine to pop an other index than -1 or 0 consists of three commands in a transaction:
- LINDEX
- LTRIM
- RPUSH (In worst case, this command would be sent N times where N is the cardinality of elements placed after popped index. Because multiple operands for RPUSH was supported since Redis 2.4.0.)
So you should not treat this method as the same method of Python built-in
list
object. It is just for being compatible tocollections.MutableSequence
protocol.If it faced the case, it also will warn you
PerformanceWarning
.- index (
-
value_type
= None¶ (
sider.types.Bulk
) The type of list values.
-