2
2
import hashlib
3
3
import time
4
4
import warnings
5
- from typing import List , Optional
5
+ from typing import List , Optional , Union
6
6
7
7
from redis .exceptions import ConnectionError , DataError , NoScriptError , RedisError
8
8
@@ -1864,7 +1864,7 @@ class ListCommands:
1864
1864
see: https://redis.io/topics/data-types#lists
1865
1865
"""
1866
1866
1867
- def blpop (self , keys , timeout = 0 ) :
1867
+ def blpop (self , keys : List , timeout : Optional [ int ] = 0 ) -> List :
1868
1868
"""
1869
1869
LPOP a value off of the first non-empty list
1870
1870
named in the ``keys`` list.
@@ -1883,7 +1883,7 @@ def blpop(self, keys, timeout=0):
1883
1883
keys .append (timeout )
1884
1884
return self .execute_command ("BLPOP" , * keys )
1885
1885
1886
- def brpop (self , keys , timeout = 0 ) :
1886
+ def brpop (self , keys : List , timeout : Optional [ int ] = 0 ) -> List :
1887
1887
"""
1888
1888
RPOP a value off of the first non-empty list
1889
1889
named in the ``keys`` list.
@@ -1902,7 +1902,9 @@ def brpop(self, keys, timeout=0):
1902
1902
keys .append (timeout )
1903
1903
return self .execute_command ("BRPOP" , * keys )
1904
1904
1905
- def brpoplpush (self , src , dst , timeout = 0 ):
1905
+ def brpoplpush (
1906
+ self , src : str , dst : str , timeout : Optional [int ] = 0
1907
+ ) -> Optional [str ]:
1906
1908
"""
1907
1909
Pop a value off the tail of ``src``, push it on the head of ``dst``
1908
1910
and then return it.
@@ -1957,7 +1959,7 @@ def lmpop(
1957
1959
1958
1960
return self .execute_command ("LMPOP" , * args )
1959
1961
1960
- def lindex (self , name , index ) :
1962
+ def lindex (self , name : str , index : int ) -> Optional [ str ] :
1961
1963
"""
1962
1964
Return the item from list ``name`` at position ``index``
1963
1965
@@ -1968,7 +1970,7 @@ def lindex(self, name, index):
1968
1970
"""
1969
1971
return self .execute_command ("LINDEX" , name , index )
1970
1972
1971
- def linsert (self , name , where , refvalue , value ) :
1973
+ def linsert (self , name : str , where : str , refvalue : str , value : str ) -> int :
1972
1974
"""
1973
1975
Insert ``value`` in list ``name`` either immediately before or after
1974
1976
[``where``] ``refvalue``
@@ -1980,15 +1982,15 @@ def linsert(self, name, where, refvalue, value):
1980
1982
"""
1981
1983
return self .execute_command ("LINSERT" , name , where , refvalue , value )
1982
1984
1983
- def llen (self , name ) :
1985
+ def llen (self , name : str ) -> int :
1984
1986
"""
1985
1987
Return the length of the list ``name``
1986
1988
1987
1989
For more information check https://redis.io/commands/llen
1988
1990
"""
1989
1991
return self .execute_command ("LLEN" , name )
1990
1992
1991
- def lpop (self , name , count = None ):
1993
+ def lpop (self , name : str , count : Optional [ int ] = None ) -> Union [ str , List , None ] :
1992
1994
"""
1993
1995
Removes and returns the first elements of the list ``name``.
1994
1996
@@ -2003,23 +2005,23 @@ def lpop(self, name, count=None):
2003
2005
else :
2004
2006
return self .execute_command ("LPOP" , name )
2005
2007
2006
- def lpush (self , name , * values ) :
2008
+ def lpush (self , name : str , * values : List ) -> int :
2007
2009
"""
2008
2010
Push ``values`` onto the head of the list ``name``
2009
2011
2010
2012
For more information check https://redis.io/commands/lpush
2011
2013
"""
2012
2014
return self .execute_command ("LPUSH" , name , * values )
2013
2015
2014
- def lpushx (self , name , * values ) :
2016
+ def lpushx (self , name : str , * values : List ) -> int :
2015
2017
"""
2016
2018
Push ``value`` onto the head of the list ``name`` if ``name`` exists
2017
2019
2018
2020
For more information check https://redis.io/commands/lpushx
2019
2021
"""
2020
2022
return self .execute_command ("LPUSHX" , name , * values )
2021
2023
2022
- def lrange (self , name , start , end ) :
2024
+ def lrange (self , name : str , start : int , end : int ) -> List :
2023
2025
"""
2024
2026
Return a slice of the list ``name`` between
2025
2027
position ``start`` and ``end``
@@ -2031,7 +2033,7 @@ def lrange(self, name, start, end):
2031
2033
"""
2032
2034
return self .execute_command ("LRANGE" , name , start , end )
2033
2035
2034
- def lrem (self , name , count , value ) :
2036
+ def lrem (self , name : str , count : int , value : str ) -> int :
2035
2037
"""
2036
2038
Remove the first ``count`` occurrences of elements equal to ``value``
2037
2039
from the list stored at ``name``.
@@ -2045,15 +2047,15 @@ def lrem(self, name, count, value):
2045
2047
"""
2046
2048
return self .execute_command ("LREM" , name , count , value )
2047
2049
2048
- def lset (self , name , index , value ) :
2050
+ def lset (self , name : str , index : int , value : str ) -> str :
2049
2051
"""
2050
- Set ``position `` of list ``name`` to ``value``
2052
+ Set element at ``index `` of list ``name`` to ``value``
2051
2053
2052
2054
For more information check https://redis.io/commands/lset
2053
2055
"""
2054
2056
return self .execute_command ("LSET" , name , index , value )
2055
2057
2056
- def ltrim (self , name , start , end ) :
2058
+ def ltrim (self , name : str , start : int , end : int ) -> str :
2057
2059
"""
2058
2060
Trim the list ``name``, removing all values not within the slice
2059
2061
between ``start`` and ``end``
@@ -2065,7 +2067,7 @@ def ltrim(self, name, start, end):
2065
2067
"""
2066
2068
return self .execute_command ("LTRIM" , name , start , end )
2067
2069
2068
- def rpop (self , name , count = None ):
2070
+ def rpop (self , name : str , count : Optional [ int ] = None ) -> Union [ str , List , None ] :
2069
2071
"""
2070
2072
Removes and returns the last elements of the list ``name``.
2071
2073
@@ -2080,7 +2082,7 @@ def rpop(self, name, count=None):
2080
2082
else :
2081
2083
return self .execute_command ("RPOP" , name )
2082
2084
2083
- def rpoplpush (self , src , dst ) :
2085
+ def rpoplpush (self , src : str , dst : str ) -> str :
2084
2086
"""
2085
2087
RPOP a value off of the ``src`` list and atomically LPUSH it
2086
2088
on to the ``dst`` list. Returns the value.
@@ -2089,23 +2091,30 @@ def rpoplpush(self, src, dst):
2089
2091
"""
2090
2092
return self .execute_command ("RPOPLPUSH" , src , dst )
2091
2093
2092
- def rpush (self , name , * values ) :
2094
+ def rpush (self , name : str , * values : List ) -> int :
2093
2095
"""
2094
2096
Push ``values`` onto the tail of the list ``name``
2095
2097
2096
2098
For more information check https://redis.io/commands/rpush
2097
2099
"""
2098
2100
return self .execute_command ("RPUSH" , name , * values )
2099
2101
2100
- def rpushx (self , name , value ) :
2102
+ def rpushx (self , name : str , value : str ) -> int :
2101
2103
"""
2102
2104
Push ``value`` onto the tail of the list ``name`` if ``name`` exists
2103
2105
2104
2106
For more information check https://redis.io/commands/rpushx
2105
2107
"""
2106
2108
return self .execute_command ("RPUSHX" , name , value )
2107
2109
2108
- def lpos (self , name , value , rank = None , count = None , maxlen = None ):
2110
+ def lpos (
2111
+ self ,
2112
+ name : str ,
2113
+ value : str ,
2114
+ rank : Optional [int ] = None ,
2115
+ count : Optional [int ] = None ,
2116
+ maxlen : Optional [int ] = None ,
2117
+ ) -> Union [str , List , None ]:
2109
2118
"""
2110
2119
Get position of ``value`` within the list ``name``
2111
2120
@@ -2145,16 +2154,16 @@ def lpos(self, name, value, rank=None, count=None, maxlen=None):
2145
2154
2146
2155
def sort (
2147
2156
self ,
2148
- name ,
2149
- start = None ,
2150
- num = None ,
2151
- by = None ,
2152
- get = None ,
2153
- desc = False ,
2154
- alpha = False ,
2155
- store = None ,
2156
- groups = False ,
2157
- ):
2157
+ name : str ,
2158
+ start : Optional [ int ] = None ,
2159
+ num : Optional [ int ] = None ,
2160
+ by : Optional [ str ] = None ,
2161
+ get : Optional [ List [ str ]] = None ,
2162
+ desc : bool = False ,
2163
+ alpha : bool = False ,
2164
+ store : Optional [ str ] = None ,
2165
+ groups : Optional [ bool ] = False ,
2166
+ ) -> Union [ List , int ] :
2158
2167
"""
2159
2168
Sort and return the list, set or sorted set at ``name``.
2160
2169
0 commit comments