glide_sync.client_pool
Client-instance pool for the synchronous GLIDE client.
Backed by the shared Rust pool in glide-core via FFI. The Rust pool owns client lifecycle (creation, LIFO reuse, bounded size). This Python class provides the acquire-with-timeout retry loop and maps client_id handles to usable GlideClient wrappers for command dispatch.
Usage
from glide_sync import GlideClient, GlideClientConfiguration, NodeAddress from glide_sync.client_pool import ClientPool, PoolConfig
config = GlideClientConfiguration([NodeAddress("localhost", 6379)]) pool = ClientPool(config, PoolConfig(max_size=10, min_idle=2))
Borrow a client, use it, return it automatically
with pool.borrow() as client: client.set("key", "value") result = client.get("key")
pool.close()
PoolConfig
dataclass
Configuration for the client-instance pool.
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/client_pool.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
max_size = 10
class-attribute
instance-attribute
Maximum number of clients in the pool.
min_idle = 1
class-attribute
instance-attribute
Minimum idle clients to pre-warm at creation.
idle_timeout_ms = 300000
class-attribute
instance-attribute
Evict idle clients after this duration (ms). Default: 5 minutes.
request_timeout_ms = 5000
class-attribute
instance-attribute
Request timeout for commands (ms).
acquire_timeout_s = 5.0
class-attribute
instance-attribute
Maximum time to wait when pool is exhausted (seconds).
abandon_timeout_ms = 300000
class-attribute
instance-attribute
Maximum inactivity time for a borrowed client before the pool reclaims it (ms). The timer resets on every command sent. The abandon monitor skips clients executing blocking commands (BLPOP, XREAD BLOCK, etc.). Set to 0 to disable abandon detection. Default: 5 minutes.
ClientPool
Client-instance pool backed by the Rust core.
The Rust pool owns client lifecycle (creation, bounded size). This Python class provides: - acquire-with-timeout retry loop (exponential backoff) - Cached GlideClient wrappers (one per client_id, reused across borrows) - Zero-overhead borrow() context manager
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/client_pool.py
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 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
create(client_config, pool_config=None)
classmethod
Create a pool and validate connectivity with a probe client.
Creates the pool infrastructure, then attempts to connect a single probe client using the same config. If the probe fails, the pool is destroyed and the actual connection error is propagated (not a timeout).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client_config
|
BaseClientConfiguration
|
Client configuration (standalone or cluster). |
required |
pool_config
|
Optional[PoolConfig]
|
Optional pool sizing/timeout configuration. |
None
|
Returns:
| Type | Description |
|---|---|
ClientPool
|
A ready-to-use ClientPool instance. |
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/client_pool.py
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 | |
acquire(timeout=None)
Acquire a client_id from the Rust pool.
Blocks in Rust using a condvar until a client is available or timeout. Single FFI call — no polling loop.
Returns:
| Type | Description |
|---|---|
int
|
client_id (positive integer) for use with borrow() or get_client(). |
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If no client available within timeout. |
RuntimeError
|
If pool is closed or invalid. |
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/client_pool.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
release(client_id)
Release a borrowed client back to the pool.
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/client_pool.py
227 228 229 | |
borrow(timeout=None)
Returns a context manager that acquires a client from the Rust pool.
The returned client dispatches commands through the native ClientAdapter managed by the Rust pool. On exit, the client is released back to the pool.
Usage
with pool.borrow() as client: client.set("key", "value") result = client.get("key")
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/client_pool.py
231 232 233 234 235 236 237 238 239 240 241 242 243 | |
metrics()
Get pool metrics: idle, active, total counts.
Zeros when the pool was destroyed.
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/client_pool.py
289 290 291 292 293 294 295 | |
close()
Destroy the pool. All idle clients are closed.
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/client_pool.py
309 310 311 312 313 314 | |