BasePool¶
Bases: object
Base connection pool for synchronous Redis clients.
Manages a pool of free and used connections, handling acquisition, release, and automatic scaling up to the configured pool limit.
Source code in pyredis/pool/base.py
5 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 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 139 140 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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
close_on_err
property
¶
Whether to close all idle connections when a connection closes on error.
conn_timeout
property
¶
Socket 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
¶
Socket read timeout in seconds.
username
property
¶
ACL authentication username.
__init__(database=0, password=None, encoding=None, conn_timeout=2, read_timeout=2, pool_size=16, lock=None, username=None)
¶
Initialize connection pool parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
Database index to select. |
0
|
|
password
|
Password for authentication. |
None
|
|
encoding
|
Optional string encoding for automatic decoding. |
None
|
|
conn_timeout
|
Socket connection timeout in seconds. |
2
|
|
read_timeout
|
Socket read timeout in seconds. |
2
|
|
pool_size
|
Maximum number of connections allowed in the pool. |
16
|
|
lock
|
Threading lock for synchronization. |
None
|
|
username
|
Username for ACL authentication. |
None
|
Source code in pyredis/pool/base.py
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 | |
acquire()
¶
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 |
|---|---|
|
A Connection instance. |
Raises:
| Type | Description |
|---|---|
PyRedisError
|
If the maximum pool size is exceeded. |
Source code in pyredis/pool/base.py
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 139 140 | |
execute(*args, **kwargs)
¶
Acquire a connection, execute a command, and release it back to the pool.
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/base.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
release(conn)
¶
Release a connection back to the pool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
The Connection instance to return. |
required |
Source code in pyredis/pool/base.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |