Skip to content

AsyncHashPool

Bases: AsyncBasePool, Connection, Geo, Hash, HyperLogLog, Key, List, Publish, Scripting, Set, SSet, String

Asynchronous Redis Hashed Client Connection Pool.

Acts as a proxy for client commands, leasing an asynchronous AsyncHashClient to route operations across multiple client-side hashing nodes asynchronously.

Source code in pyredis/pool/async_hash.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class AsyncHashPool(
    AsyncBasePool,
    commands.Connection,
    commands.Geo,
    commands.Hash,
    commands.HyperLogLog,
    commands.Key,
    commands.List,
    commands.Publish,
    commands.Scripting,
    commands.Set,
    commands.SSet,
    commands.String,
):
    """
    Asynchronous Redis Hashed Client Connection Pool.

    Acts as a proxy for client commands, leasing an asynchronous AsyncHashClient
    to route operations across multiple client-side hashing nodes asynchronously.
    """

    def __init__(self, buckets, **kwargs):
        """
        Initialize the AsyncHashPool connection manager.

        Args:
            buckets: Dict mapping server keyspace slots/buckets to connection options.
            **kwargs: Additional options forwarded to AsyncBasePool.
        """
        super().__init__(**kwargs)
        self._buckets = buckets
        self._cluster = True

    @property
    def buckets(self):
        """Dict of connection options for node buckets."""
        return self._buckets

    def _connect(self):
        return pyredis.pool.AsyncHashClient(
            buckets=self.buckets,
            database=self.database,
            password=self.password,
            encoding=self.encoding,
            conn_timeout=self.conn_timeout,
            read_timeout=self.read_timeout,
            username=self.username,
        )

buckets property

Dict of connection options for node buckets.

close_on_err property

Whether to close all idle connections when a connection closes on error.

conn_timeout property

Async connection timeout in seconds.

database property

Database index selected on connections.

encoding property

Optional string decoding encoding.

password property

Authentication password.

pool_size property writable

Maximum number of connections allowed in the pool.

read_timeout property

Async read timeout in seconds.

username property

ACL authentication username.

__init__(buckets, **kwargs)

Initialize the AsyncHashPool connection manager.

Parameters:

Name Type Description Default
buckets

Dict mapping server keyspace slots/buckets to connection options.

required
**kwargs

Additional options forwarded to AsyncBasePool.

{}
Source code in pyredis/pool/async_hash.py
27
28
29
30
31
32
33
34
35
36
37
def __init__(self, buckets, **kwargs):
    """
    Initialize the AsyncHashPool connection manager.

    Args:
        buckets: Dict mapping server keyspace slots/buckets to connection options.
        **kwargs: Additional options forwarded to AsyncBasePool.
    """
    super().__init__(**kwargs)
    self._buckets = buckets
    self._cluster = True

acquire() async

Asynchronously acquire a connection from the pool.

Reuses an idle connection or establishes a new one if the pool size limit has not been reached.

Returns:

Type Description

An AsyncConnection instance.

Raises:

Type Description
PyRedisError

If the maximum pool size is exceeded.

Source code in pyredis/pool/async_base.py
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
async def acquire(self):
    """
    Asynchronously acquire a connection from the pool.

    Reuses an idle connection or establishes a new one if the pool size limit
    has not been reached.

    Returns:
        An AsyncConnection instance.

    Raises:
        PyRedisError: If the maximum pool size is exceeded.
    """
    async with self._lock:
        try:
            client = self._pool_free.pop()
            self._pool_used.add(client)
        except KeyError:
            if len(self._pool_used) < self.pool_size:
                client = self._connect()
                if asyncio.iscoroutine(client):
                    client = await client
                self._pool_used.add(client)
            else:
                raise PyRedisError(
                    f"Max connections {self.pool_size} exhausted"
                )
        return client

append(*args)

Source code in pyredis/commands/string.py
10
11
12
13
14
15
16
17
18
def append(self, *args):
    if self._cluster:
        return self.execute(
            *[b"APPEND", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"APPEND", *args]
    )

bitcount(*args)

Source code in pyredis/commands/string.py
20
21
22
23
24
25
26
27
28
def bitcount(self, *args):
    if self._cluster:
        return self.execute(
            *[b"BITCOUNT", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"BITCOUNT", *args]
    )

bitfield(*args)

Source code in pyredis/commands/string.py
30
31
32
33
34
35
36
37
38
def bitfield(self, *args):
    if self._cluster:
        return self.execute(
            *[b"BITFIELD", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"BITFIELD", *args]
    )

bitop(*args)

Source code in pyredis/commands/string.py
40
41
42
43
44
45
46
47
48
def bitop(self, *args):
    if self._cluster:
        return self.execute(
            *[b"BITOP", *args],
            shard_key=args[1]
        )
    return self.execute(
        *[b"BITOP", *args]
    )

bitpos(*args)

Source code in pyredis/commands/string.py
50
51
52
53
54
55
56
57
58
def bitpos(self, *args):
    if self._cluster:
        return self.execute(
            *[b"BITPOS", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"BITPOS", *args]
    )

blpop(*args)

Source code in pyredis/commands/list.py
10
11
12
13
14
15
16
17
18
def blpop(self, *args):
    if self._cluster:
        return self.execute(
            *[b"BLPOP", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"BLPOP", *args]
    )

brpop(*args)

Source code in pyredis/commands/list.py
20
21
22
23
24
25
26
27
28
def brpop(self, *args):
    if self._cluster:
        return self.execute(
            *[b"BRPOP", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"BRPOP", *args]
    )

brpoplpush(*args)

Source code in pyredis/commands/list.py
30
31
32
33
34
35
36
37
38
def brpoplpush(self, *args):
    if self._cluster:
        return self.execute(
            *[b"BRPOPPUSH", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"BRPOPPUSH", *args]
    )

decr(*args)

Source code in pyredis/commands/string.py
60
61
62
63
64
65
66
67
68
def decr(self, *args):
    if self._cluster:
        return self.execute(
            *[b"DECR", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"DECR", *args]
    )

decrby(*args)

Source code in pyredis/commands/string.py
70
71
72
73
74
75
76
77
78
def decrby(self, *args):
    if self._cluster:
        return self.execute(
            *[b"DECRBY", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"DECRBY", *args]
    )

delete(*args)

Source code in pyredis/commands/key.py
10
11
12
13
14
15
16
17
18
def delete(self, *args):
    if self._cluster:
        return self.execute(
            *[b"DEL", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"DEL", *args]
    )

dump(*args)

Source code in pyredis/commands/key.py
20
21
22
23
24
25
26
27
28
def dump(self, *args):
    if self._cluster:
        return self.execute(
            *[b"DUMP", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"DUMP", *args]
    )

echo(*args, shard_key=None, sock=None)

Source code in pyredis/commands/connection.py
10
11
12
13
14
15
16
17
18
19
def echo(self, *args, shard_key=None, sock=None):
    if self._cluster:
        return self.execute(
            *[b"ECHO", *args],
            shard_key=shard_key,
            sock=sock
        )
    return self.execute(
        *[b"ECHO", *args]
    )

eval(*args, shard_key=None, sock=None)

Source code in pyredis/commands/scripting.py
10
11
12
13
14
15
16
17
18
19
def eval(self, *args, shard_key=None, sock=None):
    if self._cluster:
        return self.execute(
            *[b"EVAL", *args],
            shard_key=shard_key,
            sock=sock
        )
    return self.execute(
        *[b"EVAL", *args]
    )

evalsha(*args, shard_key=None, sock=None)

Source code in pyredis/commands/scripting.py
21
22
23
24
25
26
27
28
29
30
def evalsha(self, *args, shard_key=None, sock=None):
    if self._cluster:
        return self.execute(
            *[b"EVALSHA", *args],
            shard_key=shard_key,
            sock=sock
        )
    return self.execute(
        *[b"EVALSHA", *args]
    )

execute(*args, **kwargs) async

Asynchronously acquire a connection, execute a command, and release it.

Parameters:

Name Type Description Default
*args

Command name and positional arguments.

()
**kwargs

Execution options (e.g. shard_key, sock).

{}

Returns:

Type Description

Parsed Redis reply.

Source code in pyredis/pool/async_base.py
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
async def execute(
    self,
    *args,
    **kwargs
):
    """
    Asynchronously acquire a connection, execute a command, and release it.

    Args:
        *args: Command name and positional arguments.
        **kwargs: Execution options (e.g. shard_key, sock).

    Returns:
        Parsed Redis reply.
    """
    conn = await self.acquire()
    try:
        return await conn.execute(
            *args,
            **kwargs
        )
    finally:
        await self.release(
            conn=conn
        )

exists(*args)

Source code in pyredis/commands/key.py
30
31
32
33
34
35
36
37
38
def exists(self, *args):
    if self._cluster:
        return self.execute(
            *[b"EXISTS", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"EXISTS", *args]
    )

expire(*args)

Source code in pyredis/commands/key.py
40
41
42
43
44
45
46
47
48
def expire(self, *args):
    if self._cluster:
        return self.execute(
            *[b"EXPIRE", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"EXPIRE", *args]
    )

expireat(*args)

Source code in pyredis/commands/key.py
50
51
52
53
54
55
def expireat(self, *args):
    if self._cluster:
        return self.execute(b"EXPIREAT")
    return self.execute(
        *[b"EXPIREAT", *args]
    )

geoadd(*args)

Source code in pyredis/commands/geo.py
10
11
12
13
14
15
16
17
18
def geoadd(self, *args):
    if self._cluster:
        return self.execute(
            *[b"GEOADD", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"GEOADD", *args]
    )

geodist(*args)

Source code in pyredis/commands/geo.py
20
21
22
23
24
25
26
27
28
def geodist(self, *args):
    if self._cluster:
        return self.execute(
            *[b"GEODIST", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"GEODIST", *args]
    )

geohash(*args)

Source code in pyredis/commands/geo.py
30
31
32
33
34
35
36
37
38
def geohash(self, *args):
    if self._cluster:
        return self.execute(
            *[b"GEOHASH", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"GEOHASH", *args]
    )

geopos(*args)

Source code in pyredis/commands/geo.py
50
51
52
53
54
55
56
57
58
def geopos(self, *args):
    if self._cluster:
        return self.execute(
            *[b"GEOPOS", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"GEOPOS", *args]
    )

georadius(*args)

Source code in pyredis/commands/geo.py
40
41
42
43
44
45
46
47
48
def georadius(self, *args):
    if self._cluster:
        return self.execute(
            *[b"GEORADIUS", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"GEORADIUS", *args]
    )

georadiusbymember(*args)

Source code in pyredis/commands/geo.py
60
61
62
63
64
65
66
67
68
def georadiusbymember(self, *args):
    if self._cluster:
        return self.execute(
            *[b"GEORADIUSBYMEMBER", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"GEORADIUSBYMEMBER", *args]
    )

get(*args)

Source code in pyredis/commands/string.py
80
81
82
83
84
85
86
87
88
def get(self, *args):
    if self._cluster:
        return self.execute(
            *[b"GET", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"GET", *args]
    )

getbit(*args)

Source code in pyredis/commands/string.py
90
91
92
93
94
95
96
97
98
def getbit(self, *args):
    if self._cluster:
        return self.execute(
            *[b"GETBIT", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"GETBIT", *args]
    )

getrange(*args)

Source code in pyredis/commands/string.py
100
101
102
103
104
105
106
107
108
def getrange(self, *args):
    if self._cluster:
        return self.execute(
            *[b"GETRANGE", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"GETRANGE", *args]
    )

getset(*args)

Source code in pyredis/commands/string.py
110
111
112
113
114
115
116
117
118
def getset(self, *args):
    if self._cluster:
        return self.execute(
            *[b"GETSET", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"GETSET", *args]
    )

hdel(*args)

Source code in pyredis/commands/hash.py
10
11
12
13
14
15
16
17
18
def hdel(self, *args):
    if self._cluster:
        return self.execute(
            *[b"HDEL", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"HDEL", *args]
    )

hexists(*args)

Source code in pyredis/commands/hash.py
20
21
22
23
24
25
26
27
28
def hexists(self, *args):
    if self._cluster:
        return self.execute(
            *[b"HEXISTS", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"HEXISTS", *args]
    )

hget(*args)

Source code in pyredis/commands/hash.py
30
31
32
33
34
35
36
37
38
def hget(self, *args):
    if self._cluster:
        return self.execute(
            *[b"HGET", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"HGET", *args]
    )

hgetall(*args)

Source code in pyredis/commands/hash.py
40
41
42
43
44
45
46
47
48
def hgetall(self, *args):
    if self._cluster:
        return self.execute(
            *[b"HGETALL", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"HGETALL", *args]
    )

hincrby(*args)

Source code in pyredis/commands/hash.py
50
51
52
53
54
55
56
57
58
def hincrby(self, *args):
    if self._cluster:
        return self.execute(
            *[b"HINCRBY", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"HINCRBY", *args]
    )

hincrbyfloat(*args)

Source code in pyredis/commands/hash.py
60
61
62
63
64
65
66
67
68
def hincrbyfloat(self, *args):
    if self._cluster:
        return self.execute(
            *[b"HINCRBYFLOAT", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"HINCRBYFLOAT", *args]
    )

hkeys(*args)

Source code in pyredis/commands/hash.py
70
71
72
73
74
75
76
77
78
def hkeys(self, *args):
    if self._cluster:
        return self.execute(
            *[b"HKEYS", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"HKEYS", *args]
    )

hlen(*args)

Source code in pyredis/commands/hash.py
80
81
82
83
84
85
86
87
88
def hlen(self, *args):
    if self._cluster:
        return self.execute(
            *[b"HLEN", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"HLEN", *args]
    )

hmget(*args)

Source code in pyredis/commands/hash.py
90
91
92
93
94
95
96
97
98
def hmget(self, *args):
    if self._cluster:
        return self.execute(
            *[b"HMGET", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"HMGET", *args]
    )

hmset(*args)

Source code in pyredis/commands/hash.py
100
101
102
103
104
105
106
107
108
def hmset(self, *args):
    if self._cluster:
        return self.execute(
            *[b"HMSET", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"HMSET", *args]
    )

hscan(*args)

Source code in pyredis/commands/hash.py
150
151
152
153
154
155
156
157
158
def hscan(self, *args):
    if self._cluster:
        return self.execute(
            *[b"HSCAN", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"HSCAN", *args]
    )

hset(*args)

Source code in pyredis/commands/hash.py
110
111
112
113
114
115
116
117
118
def hset(self, *args):
    if self._cluster:
        return self.execute(
            *[b"HSET", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"HSET", *args]
    )

hsetnx(*args)

Source code in pyredis/commands/hash.py
120
121
122
123
124
125
126
127
128
def hsetnx(self, *args):
    if self._cluster:
        return self.execute(
            *[b"HSETNX", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"HSETNX", *args]
    )

hstrlen(*args)

Source code in pyredis/commands/hash.py
130
131
132
133
134
135
136
137
138
def hstrlen(self, *args):
    if self._cluster:
        return self.execute(
            *[b"HSTRLEN", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"HSTRLEN", *args]
    )

hvals(*args)

Source code in pyredis/commands/hash.py
140
141
142
143
144
145
146
147
148
def hvals(self, *args):
    if self._cluster:
        return self.execute(
            *[b"HVALS", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"HVALS", *args]
    )

incr(*args)

Source code in pyredis/commands/string.py
120
121
122
123
124
125
126
127
128
def incr(self, *args):
    if self._cluster:
        return self.execute(
            *[b"INCR", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"INCR", *args]
    )

incrby(*args)

Source code in pyredis/commands/string.py
130
131
132
133
134
135
136
137
138
def incrby(self, *args):
    if self._cluster:
        return self.execute(
            *[b"INCRBY", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"INCRBY", *args]
    )

incrbyfloat(*args)

Source code in pyredis/commands/string.py
140
141
142
143
144
145
146
147
148
def incrbyfloat(self, *args):
    if self._cluster:
        return self.execute(
            *[b"INCRBYFLOAT", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"INCRBYFLOAT", *args]
    )

keys(*args, shard_key=None, sock=None)

Source code in pyredis/commands/key.py
57
58
59
60
61
62
63
64
65
66
def keys(self, *args, shard_key=None, sock=None):
    if self._cluster:
        return self.execute(
            *[b"KEYS", *args],
            shard_key=shard_key,
            sock=sock
        )
    return self.execute(
        *[b"KEYS", *args]
    )

lindex(*args)

Source code in pyredis/commands/list.py
40
41
42
43
44
45
46
47
48
def lindex(self, *args):
    if self._cluster:
        return self.execute(
            *[b"LINDEX", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"LINDEX", *args]
    )

linsert(*args)

Source code in pyredis/commands/list.py
50
51
52
53
54
55
56
57
58
def linsert(self, *args):
    if self._cluster:
        return self.execute(
            *[b"LINSERT", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"LINSERT", *args]
    )

llen(*args)

Source code in pyredis/commands/list.py
60
61
62
63
64
65
66
67
68
def llen(self, *args):
    if self._cluster:
        return self.execute(
            *[b"LLEN", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"LLEN", *args]
    )

lpop(*args)

Source code in pyredis/commands/list.py
70
71
72
73
74
75
76
77
78
def lpop(self, *args):
    if self._cluster:
        return self.execute(
            *[b"LPOP", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"LPOP", *args]
    )

lpush(*args)

Source code in pyredis/commands/list.py
80
81
82
83
84
85
86
87
88
def lpush(self, *args):
    if self._cluster:
        return self.execute(
            *[b"LPUSH", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"LPUSH", *args]
    )

lpushx(*args)

Source code in pyredis/commands/list.py
90
91
92
93
94
95
96
97
98
def lpushx(self, *args):
    if self._cluster:
        return self.execute(
            *[b"LPUSHX", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"LPUSHX", *args]
    )

lrange(*args)

Source code in pyredis/commands/list.py
100
101
102
103
104
105
106
107
108
def lrange(self, *args):
    if self._cluster:
        return self.execute(
            *[b"LRANGE", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"LRANGE", *args]
    )

lrem(*args)

Source code in pyredis/commands/list.py
110
111
112
113
114
115
116
117
118
def lrem(self, *args):
    if self._cluster:
        return self.execute(
            *[b"LREM", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"LREM", *args]
    )

lset(*args)

Source code in pyredis/commands/list.py
120
121
122
123
124
125
126
127
128
def lset(self, *args):
    if self._cluster:
        return self.execute(
            *[b"LSET", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"LSET", *args]
    )

ltrim(*args)

Source code in pyredis/commands/list.py
130
131
132
133
134
135
136
137
138
def ltrim(self, *args):
    if self._cluster:
        return self.execute(
            *[b"LTRIM", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"LTRIM", *args]
    )

mget(*args)

Source code in pyredis/commands/string.py
150
151
152
153
154
155
156
157
158
def mget(self, *args):
    if self._cluster:
        return self.execute(
            *[b"MGET", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"MGET", *args]
    )

migrate(*args)

Source code in pyredis/commands/key.py
68
69
70
71
72
73
def migrate(self, *args):
    if self._cluster:
        raise NotImplementedError
    return self.execute(
        *[b"MIGRATE", *args]
    )

move(*args)

Source code in pyredis/commands/key.py
75
76
77
78
79
80
81
82
83
def move(self, *args):
    if self._cluster:
        return self.execute(
            *[b"MOVE", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"MOVE", *args]
    )

mset(*args)

Source code in pyredis/commands/string.py
160
161
162
163
164
165
166
167
168
def mset(self, *args):
    if self._cluster:
        return self.execute(
            *[b"MSET", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"MSET", *args]
    )

msetnx(*args)

Source code in pyredis/commands/string.py
170
171
172
173
174
175
176
177
178
def msetnx(self, *args):
    if self._cluster:
        return self.execute(
            *[b"MSETNX", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"MSETNX", *args]
    )

object(*args, shard_key=None, sock=None)

Source code in pyredis/commands/key.py
85
86
87
88
89
90
91
92
93
94
def object(self, *args, shard_key=None, sock=None):
    if self._cluster:
        return self.execute(
            *[b"DEL", *args],
            shard_key=shard_key,
            sock=sock
        )
    return self.execute(
        *[b"OBJECT", *args]
    )

persist(*args)

Source code in pyredis/commands/key.py
 96
 97
 98
 99
100
101
102
103
104
def persist(self, *args):
    if self._cluster:
        return self.execute(
            *[b"PERSIST", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"PERSIST", *args]
    )

pexpire(*args)

Source code in pyredis/commands/key.py
106
107
108
109
110
111
112
113
114
def pexpire(self, *args):
    if self._cluster:
        return self.execute(
            *[b"PEXPIRE", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"PEXPIRE", *args]
    )

pexpireat(*args)

Source code in pyredis/commands/key.py
116
117
118
119
120
121
122
123
124
def pexpireat(self, *args):
    if self._cluster:
        return self.execute(
            *[b"PEXPIREAT", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"PEXPIREAT", *args]
    )

pfadd(*args)

Source code in pyredis/commands/hyperloglog.py
10
11
12
13
14
15
16
17
18
def pfadd(self, *args):
    if self._cluster:
        return self.execute(
            *[b"PFADD", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"PFADD", *args]
    )

pfcount(*args)

Source code in pyredis/commands/hyperloglog.py
20
21
22
23
24
25
26
27
28
def pfcount(self, *args):
    if self._cluster:
        return self.execute(
            *[b"PFCOUNT", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"PFCOUNT", *args]
    )

pfmerge(*args)

Source code in pyredis/commands/hyperloglog.py
30
31
32
33
34
35
36
37
38
def pfmerge(self, *args):
    if self._cluster:
        return self.execute(
            *[b"PFMERGE", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"PFMERGE", *args]
    )

ping(shard_key=None, sock=None)

Source code in pyredis/commands/connection.py
21
22
23
24
25
26
27
28
def ping(self, shard_key=None, sock=None):
    if self._cluster:
        return self.execute(
            b"PING",
            shard_key=shard_key,
            sock=sock
        )
    return self.execute(b"PING")

psetex(*args)

Source code in pyredis/commands/string.py
180
181
182
183
184
185
186
187
188
def psetex(self, *args):
    if self._cluster:
        return self.execute(
            *[b"PSETEX", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"PSETEX", *args]
    )

pttl(*args)

Source code in pyredis/commands/key.py
126
127
128
129
130
131
132
133
134
def pttl(self, *args):
    if self._cluster:
        return self.execute(
            *[b"PTTL", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"PTTL", *args]
    )

publish(*args)

Source code in pyredis/commands/publish.py
10
11
12
13
14
15
def publish(self, *args):
    if self._cluster:
        raise NotImplementedError
    return self.execute(
        *[b"PUBLISH", *args]
    )

randomkey(*args, shard_key=None, sock=None)

Source code in pyredis/commands/key.py
136
137
138
139
140
141
142
143
144
145
def randomkey(self, *args, shard_key=None, sock=None):
    if self._cluster:
        return self.execute(
            *[b"RANDOMKEY", *args],
            shard_key=shard_key,
            sock=sock
        )
    return self.execute(
        *[b"RANDOMKEY", *args]
    )

release(conn) async

Asynchronously release a connection back to the pool.

Parameters:

Name Type Description Default
conn

The AsyncConnection instance to return.

required
Source code in pyredis/pool/async_base.py
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
async def release(
    self,
    conn
):
    """
    Asynchronously release a connection back to the pool.

    Args:
        conn: The AsyncConnection instance to return.
    """
    async with self._lock:
        try:
            current_size = len(self._pool_free) + len(self._pool_used)
            self._pool_used.remove(conn)
            if conn.closed and self.close_on_err:
                for c in self._pool_free:
                    await c.close()
                self._pool_free = set()
                self._pool_used = set()
            elif not conn.closed:
                if current_size > self.pool_size:
                    await conn.close()
                else:
                    self._pool_free.add(conn)
        except KeyError:
            await conn.close()

rename(*args)

Source code in pyredis/commands/key.py
147
148
149
150
151
152
153
154
155
def rename(self, *args):
    if self._cluster:
        return self.execute(
            *[b"RENAME", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"RENAME", *args]
    )

renamenx(*args)

Source code in pyredis/commands/key.py
157
158
159
160
161
162
163
164
165
def renamenx(self, *args):
    if self._cluster:
        return self.execute(
            *[b"RENAMENX", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"RENAMENX", *args]
    )

restore(*args)

Source code in pyredis/commands/key.py
167
168
169
170
171
172
173
174
175
def restore(self, *args):
    if self._cluster:
        return self.execute(
            *[b"RESTORE", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"RESTORE", *args]
    )

rpop(*args)

Source code in pyredis/commands/list.py
140
141
142
143
144
145
146
147
148
def rpop(self, *args):
    if self._cluster:
        return self.execute(
            *[b"RPOP", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"RPOP", *args]
    )

rpoplpush(*args)

Source code in pyredis/commands/list.py
150
151
152
153
154
155
156
157
158
def rpoplpush(self, *args):
    if self._cluster:
        return self.execute(
            *[b"RPOPLPUSH", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"RPOPLPUSH", *args]
    )

rpush(*args)

Source code in pyredis/commands/list.py
160
161
162
163
164
165
166
167
168
def rpush(self, *args):
    if self._cluster:
        return self.execute(
            *[b"RPUSH", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"RPUSH", *args]
    )

rpushx(*args)

Source code in pyredis/commands/list.py
170
171
172
173
174
175
176
177
178
def rpushx(self, *args):
    if self._cluster:
        return self.execute(
            *[b"RPUSHX", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"RPUSHX", *args]
    )

sadd(*args)

Source code in pyredis/commands/set.py
10
11
12
13
14
15
16
17
18
def sadd(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SADD", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SADD", *args]
    )

scan(*args, shard_key=None, sock=None)

Source code in pyredis/commands/key.py
177
178
179
180
181
182
183
184
185
186
def scan(self, *args, shard_key=None, sock=None):
    if self._cluster:
        return self.execute(
            *[b"SCAN", *args],
            shard_key=shard_key,
            sock=sock
        )
    return self.execute(
        *[b"SCAN", *args]
    )

scard(*args)

Source code in pyredis/commands/set.py
20
21
22
23
24
25
26
27
28
def scard(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SCARD", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SCARD", *args]
    )

script_debug(*args, shard_key=None, sock=None)

Source code in pyredis/commands/scripting.py
32
33
34
35
36
37
38
39
40
41
def script_debug(self, *args, shard_key=None, sock=None):
    if self._cluster:
        return self.execute(
            *[b"SCRIPT", b"DEBUG", *args],
            shard_key=shard_key,
            sock=sock
        )
    return self.execute(
        *[b"SCRIPT", b"DEBUG", *args]
    )

script_exists(*args, shard_key=None, sock=None)

Source code in pyredis/commands/scripting.py
43
44
45
46
47
48
49
50
51
52
def script_exists(self, *args, shard_key=None, sock=None):
    if self._cluster:
        return self.execute(
            *[b"SCRIPT", b"EXISTS", *args],
            shard_key=shard_key,
            sock=sock
        )
    return self.execute(
        *[b"SCRIPT", b"EXISTS", *args]
    )

script_flush(*args, shard_key=None, sock=None)

Source code in pyredis/commands/scripting.py
54
55
56
57
58
59
60
61
62
63
def script_flush(self, *args, shard_key=None, sock=None):
    if self._cluster:
        return self.execute(
            *[b"SCRIPT", b"FLUSH", *args],
            shard_key=shard_key,
            sock=sock
        )
    return self.execute(
        *[b"SCRIPT", b"FLUSH", *args]
    )

script_kill(*args, shard_key=None, sock=None)

Source code in pyredis/commands/scripting.py
65
66
67
68
69
70
71
72
73
74
def script_kill(self, *args, shard_key=None, sock=None):
    if self._cluster:
        return self.execute(
            *[b"SCRIPT", b"KILL", *args],
            shard_key=shard_key,
            sock=sock
        )
    return self.execute(
        *[b"SCRIPT", b"KILL", *args]
    )

script_load(*args, shard_key=None, sock=None)

Source code in pyredis/commands/scripting.py
76
77
78
79
80
81
82
83
84
85
def script_load(self, *args, shard_key=None, sock=None):
    if self._cluster:
        return self.execute(
            *[b"SCRIPT", b"LOAD", *args],
            shard_key=shard_key,
            sock=sock
        )
    return self.execute(
        *[b"SCRIPT", b"LOAD", *args]
    )

sdiff(*args)

Source code in pyredis/commands/set.py
30
31
32
33
34
35
36
37
38
def sdiff(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SDIFF", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SDIFF", *args]
    )

sdiffstore(*args)

Source code in pyredis/commands/set.py
40
41
42
43
44
45
46
47
48
def sdiffstore(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SDIFFSTORE", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SDIFFSTORE", *args]
    )

set(*args)

Source code in pyredis/commands/string.py
190
191
192
193
194
195
196
197
198
def set(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SET", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SET", *args]
    )

setbit(*args)

Source code in pyredis/commands/string.py
200
201
202
203
204
205
206
207
208
def setbit(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SETBIT", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SETBIT", *args]
    )

setex(*args)

Source code in pyredis/commands/string.py
210
211
212
213
214
215
216
217
218
def setex(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SETEX", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SETEX", *args]
    )

setnx(*args)

Source code in pyredis/commands/string.py
220
221
222
223
224
225
226
227
228
def setnx(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SETNX", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SETNX", *args]
    )

setrange(*args)

Source code in pyredis/commands/string.py
230
231
232
233
234
235
236
237
238
def setrange(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SETRANGE", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SETRANGE", *args]
    )

sinter(*args)

Source code in pyredis/commands/set.py
50
51
52
53
54
55
56
57
58
def sinter(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SINTER", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SINTER", *args]
    )

sinterstore(*args)

Source code in pyredis/commands/set.py
60
61
62
63
64
65
66
67
68
def sinterstore(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SINTERSTORE", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SINTERSTORE", *args]
    )

sismember(*args)

Source code in pyredis/commands/set.py
70
71
72
73
74
75
76
77
78
def sismember(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SISMEMBER", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SISMEMBER", *args]
    )

smembers(*args)

Source code in pyredis/commands/set.py
80
81
82
83
84
85
86
87
88
def smembers(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SMEMBERS", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SMEMBERS", *args]
    )

smove(*args)

Source code in pyredis/commands/set.py
90
91
92
93
94
95
96
97
98
def smove(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SMOVE", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SMOVE", *args]
    )

sort(*args)

Source code in pyredis/commands/key.py
188
189
190
191
192
193
194
195
196
def sort(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SORT", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SORT", *args]
    )

spop(*args)

Source code in pyredis/commands/set.py
100
101
102
103
104
105
106
107
108
def spop(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SPOP", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SPOP", *args]
    )

srandmember(*args)

Source code in pyredis/commands/set.py
110
111
112
113
114
115
116
117
118
def srandmember(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SRANDMEMBER", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SRANDMEMBER", *args]
    )

srem(*args)

Source code in pyredis/commands/set.py
120
121
122
123
124
125
126
127
128
def srem(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SREM", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SREM", *args]
    )

sscan(*args)

Source code in pyredis/commands/set.py
150
151
152
153
154
155
156
157
158
def sscan(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SSCAN", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SSCAN", *args]
    )

strlen(*args)

Source code in pyredis/commands/string.py
240
241
242
243
244
245
246
247
248
def strlen(self, *args):
    if self._cluster:
        return self.execute(
            *[b"STRLEN", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"STRLEN", *args]
    )

sunion(*args)

Source code in pyredis/commands/set.py
130
131
132
133
134
135
136
137
138
def sunion(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SUNION", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SUNION", *args]
    )

sunoinstore(*args)

Source code in pyredis/commands/set.py
140
141
142
143
144
145
146
147
148
def sunoinstore(self, *args):
    if self._cluster:
        return self.execute(
            *[b"SUNIONSTORE", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"SUNIONSTORE", *args]
    )

ttl(*args)

Source code in pyredis/commands/key.py
198
199
200
201
202
203
204
205
206
def ttl(self, *args):
    if self._cluster:
        return self.execute(
            *[b"TTL", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"TTL", *args]
    )

type(*args)

Source code in pyredis/commands/key.py
208
209
210
211
212
213
214
215
216
def type(self, *args):
    if self._cluster:
        return self.execute(
            *[b"TYPE", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"TYPE", *args]
    )

wait(*args)

Source code in pyredis/commands/key.py
218
219
220
221
222
223
224
225
226
def wait(self, *args):
    if self._cluster:
        return self.execute(
            *[b"WAIT", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"WAIT", *args]
    )

zadd(*args)

Source code in pyredis/commands/sset.py
10
11
12
13
14
15
16
17
18
def zadd(self, *args):
    if self._cluster:
        return self.execute(
            *[b"ZADD", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"ZADD", *args]
    )

zcard(*args)

Source code in pyredis/commands/sset.py
20
21
22
23
24
25
26
27
28
def zcard(self, *args):
    if self._cluster:
        return self.execute(
            *[b"ZCARD", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"ZCARD", *args]
    )

zcount(*args)

Source code in pyredis/commands/sset.py
30
31
32
33
34
35
36
37
38
def zcount(self, *args):
    if self._cluster:
        return self.execute(
            *[b"ZCOUNT", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"ZCOUNT", *args]
    )

zincrby(*args)

Source code in pyredis/commands/sset.py
40
41
42
43
44
45
46
47
48
def zincrby(self, *args):
    if self._cluster:
        return self.execute(
            *[b"ZINCRBY", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"ZINCRBY", *args]
    )

zinterstore(*args)

Source code in pyredis/commands/sset.py
50
51
52
53
54
55
56
57
58
def zinterstore(self, *args):
    if self._cluster:
        return self.execute(
            *[b"ZINTERSTORE", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"ZINTERSTORE", *args]
    )

zlexcount(*args)

Source code in pyredis/commands/sset.py
60
61
62
63
64
65
66
67
68
def zlexcount(self, *args):
    if self._cluster:
        return self.execute(
            *[b"ZLEXCOUNT", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"ZLEXCOUNT", *args]
    )

zrange(*args)

Source code in pyredis/commands/sset.py
70
71
72
73
74
75
76
77
78
def zrange(self, *args):
    if self._cluster:
        return self.execute(
            *[b"ZRANGE", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"ZRANGE", *args]
    )

zrangebylex(*args)

Source code in pyredis/commands/sset.py
80
81
82
83
84
85
86
87
88
def zrangebylex(self, *args):
    if self._cluster:
        return self.execute(
            *[b"ZRANGEBYLEX", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"ZRANGEBYLEX", *args]
    )

zrangebyscore(*args)

Source code in pyredis/commands/sset.py
90
91
92
93
94
95
96
97
98
def zrangebyscore(self, *args):
    if self._cluster:
        return self.execute(
            *[b"ZRANGEBYSCORE", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"ZRANGEBYSCORE", *args]
    )

zrank(*args)

Source code in pyredis/commands/sset.py
100
101
102
103
104
105
106
107
108
def zrank(self, *args):
    if self._cluster:
        return self.execute(
            *[b"ZRANK", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"ZRANK", *args]
    )

zrem(*args)

Source code in pyredis/commands/sset.py
110
111
112
113
114
115
116
117
118
def zrem(self, *args):
    if self._cluster:
        return self.execute(
            *[b"ZREM", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"ZREM", *args]
    )

zremrangebylex(*args)

Source code in pyredis/commands/sset.py
120
121
122
123
124
125
126
127
128
def zremrangebylex(self, *args):
    if self._cluster:
        return self.execute(
            *[b"ZREMRANGEBYLEX", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"ZREMRANGEBYLEX", *args]
    )

zremrangebyrank(*args)

Source code in pyredis/commands/sset.py
130
131
132
133
134
135
136
137
138
def zremrangebyrank(self, *args):
    if self._cluster:
        return self.execute(
            *[b"ZREMRANGEBYRANK", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"ZREMRANGEBYRANK", *args]
    )

zremrangebyscrore(*args)

Source code in pyredis/commands/sset.py
140
141
142
143
144
145
146
147
148
def zremrangebyscrore(self, *args):
    if self._cluster:
        return self.execute(
            *[b"ZREMRANGEBYSCORE", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"ZREMRANGEBYSCORE", *args]
    )

zrevrange(*args)

Source code in pyredis/commands/sset.py
150
151
152
153
154
155
156
157
158
def zrevrange(self, *args):
    if self._cluster:
        return self.execute(
            *[b"ZREVRANGE", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"ZREVRANGE", *args]
    )

zrevrangebylex(*args)

Source code in pyredis/commands/sset.py
160
161
162
163
164
165
166
167
168
def zrevrangebylex(self, *args):
    if self._cluster:
        return self.execute(
            *[b"ZREVRANGEBYLEX", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"ZREVRANGEBYLEX", *args]
    )

zrevrangebyscore(*args)

Source code in pyredis/commands/sset.py
170
171
172
173
174
175
176
177
178
def zrevrangebyscore(self, *args):
    if self._cluster:
        return self.execute(
            *[b"ZREVRANGEBYSCORE", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"ZREVRANGEBYSCORE", *args]
    )

zrevrank(*args)

Source code in pyredis/commands/sset.py
180
181
182
183
184
185
186
187
188
def zrevrank(self, *args):
    if self._cluster:
        return self.execute(
            *[b"ZREVRANK", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"ZREVRANK", *args]
    )

zscan(*args)

Source code in pyredis/commands/sset.py
210
211
212
213
214
215
216
217
218
def zscan(self, *args):
    if self._cluster:
        return self.execute(
            *[b"ZSCAN", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"ZSCAN", *args]
    )

zscore(*args)

Source code in pyredis/commands/sset.py
190
191
192
193
194
195
196
197
198
def zscore(self, *args):
    if self._cluster:
        return self.execute(
            *[b"ZSCORE", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"ZSCORE", *args]
    )

zunionstore(*args)

Source code in pyredis/commands/sset.py
200
201
202
203
204
205
206
207
208
def zunionstore(self, *args):
    if self._cluster:
        return self.execute(
            *[b"ZUNIONSTORE", *args],
            shard_key=args[0]
        )
    return self.execute(
        *[b"ZUNIONSTORE", *args]
    )