glide_sync
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 | |
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.
GlideClient
Bases: BaseClient, StandaloneCommands
Client used for connection to standalone servers. For full documentation, see https://glide.valkey.io/how-to/client-initialization/#standalone
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/glide_client.py
2430 2431 2432 2433 2434 2435 2436 2437 | |
GlideClusterClient
Bases: BaseClient, ClusterCommands
Client used for connection to cluster servers. For full documentation, see https://glide.valkey.io/how-to/client-initialization/#cluster
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/glide_client.py
2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 | |
RdmaReadReceipt
dataclass
What the server reported about a completed read.
Attributes:
| Name | Type | Description |
|---|---|---|
bytes_written |
int
|
Bytes the server moved into the window. |
checksum |
Optional[int]
|
CRC-32c the server computed over those bytes. The landed bytes have already been verified against it. |
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/glide_client.py
129 130 131 132 133 134 135 136 137 138 139 140 141 | |
RdmaRegion
Memory registered with the server for RDMA transfers.
The memory is the caller's: this holds a reference to it and registers it with the client's fabric, but never copies or owns it. Register one large region at start-up and address windows of it per transfer rather than registering per operation.
The pages stay pinned until :meth:close is called, and the buffer must not
be resized or freed before then. The server writes into it at times the
caller does not control, so a transfer must not overlap any other use of the
same window.
Only one transfer may use a region at a time, even when each transfer uses
a different window. Threads that transfer concurrently each need their own
region, for example one per non-overlapping slice of the same buffer. A
transfer that finds the region already in use by another raises
RdmaError, and so does :meth:close while a transfer is using it.
Create one with :meth:BaseClient.register_rdma_region. Close it with
:meth:close, or use it as a context manager. A region garbage-collected
without being closed is freed then, with a ResourceWarning; until
then its pages stay pinned::
with client.register_rdma_region(bytearray(1 << 20)) as region:
client.rdma_set(b"key", region.window(0, 4096))
Handling a failed transfer: some failures leave the region usable, such as a value too large for its window, a checksum mismatch, or a refusal from the server. Others close it, because the server might still be using the memory:
- the connection was lost while the transfer was in flight;
- the client was closed to cancel the transfer;
- the server's reply was neither a result nor an error, such as the
+QUEUEDa server sends when another thread has aMULTIopen on this client, which means the server may still run the transfer onEXEC.
The error's class does not say which happened. For example, a handshake
that leaves the connection unusable raises ConnectionError but keeps
the region open, since the transfer was never sent, and the client
reconnects for the next one. So check :attr:closed after any error, and
register the memory again if the client is still open::
try:
receipt = client.rdma_get(key, region.window(offset, length))
except GlideError:
if region.closed and not client.closed:
region = client.register_rdma_region(slab)
raise
Whether to retry is left to the caller, since only the caller knows whether
sending a value again is safe. On efa-direct the same memory can be
registered again at once. GLIDE refuses it, raising RdmaError, only
while it still holds the memory: on the tcp provider, which is for
development only, or after a failed deregistration. See
:attr:memory_released.
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/glide_client.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 | |
capacity
property
How many bytes were registered.
closed
property
Whether the region has been deregistered, by :meth:close or by a
transfer that ended before the server was known to be done with the
memory; see :class:RdmaRegion.
memory_released
property
Whether the caller may reuse or free the registered memory.
False while the region is open. After it closes, False while GLIDE still holds the memory because a write could still land in it: after a transfer closed the region on the tcp provider, until the client and all its regions are closed, or after a failed deregistration, for good. True otherwise, which on efa-direct is as soon as the region closes.
Registering memory GLIDE still holds is refused, so a caller who only wants to register the same memory again can try that and handle the error rather than check this first.
Example
region.close() if not region.memory_released: ... slab = bytearray(len(slab)) # the old one may still be written
window(offset=0, length=None)
The span of this region a transfer should use.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
offset
|
int
|
Where the window starts. Defaults to 0. |
0
|
length
|
Optional[int]
|
How many bytes it covers. If not set, the
rest of the region from |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
RdmaWindow |
RdmaWindow
|
The window, to pass to |
Raises:
| Type | Description |
|---|---|
RdmaError
|
If the region is closed or the window runs outside it. |
Example
region.window() # the whole region region.window(4096, 1024) # 1 KiB starting 4 KiB in
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/glide_client.py
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |
memoryview()
A view of the registered memory as a span of bytes.
Raises:
| Type | Description |
|---|---|
RdmaError
|
If the region has been closed. |
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/glide_client.py
502 503 504 505 506 507 508 509 510 | |
close()
Deregister the memory and release the pinned pages.
The caller's buffer is not freed. Usually it can be reused or freed once
this returns. The exception is a region a transfer closed on the tcp
provider, or whose deregistration failed: a write may still land in it,
so GLIDE keeps the buffer referenced until the fabric is done with it,
and the caller should not reuse it either. On tcp that is once the
client and all its regions are closed; after a failed deregistration,
which is logged as an error, it is never. :attr:memory_released says
which. Closing twice is a no-op, so this is safe in a finally.
This is not a way to cancel a transfer. To cancel one in flight, close the client from another thread: the transfer then closes its region on the way out, so closing it again is a no-op.
Raises:
| Type | Description |
|---|---|
RdmaError
|
If a transfer is using the region. Closing it then would free the region under the transfer. |
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/glide_client.py
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 | |
RdmaWindow
dataclass
The span of a registered region one transfer uses.
Attributes:
| Name | Type | Description |
|---|---|---|
region |
RdmaRegion
|
The region the window belongs to. |
offset |
int
|
Where the window starts within the region. |
length |
int
|
How many bytes it covers. |
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/glide_client.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
memoryview()
A view of just this window for reading what a transfer landed or staging what one will send.
Raises:
| Type | Description |
|---|---|
RdmaError
|
If the region has been closed. |
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/glide_client.py
159 160 161 162 163 164 165 166 167 | |
IsolatedScope
A borrowed dedicated connection for operations requiring per-connection state.
Commands bypass the multiplexer and execute on a single TCP connection. Enables WATCH/MULTI/EXEC, CLIENT TRACKING, blocking commands, and pub/sub without interference from other callers.
Thread Safety: A single IsolatedScope is NOT thread-safe (serial execution). Multiple threads should each acquire their own scope via client.scoped_connection().
Use as a context manager for automatic release
with client.scoped_connection() as scope: scope.watch("key") ...
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/isolated_scope.py
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 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 | |
scope_id
property
The scope identifier handle.
is_released
property
Whether the scope has been returned to the pool.
watch(*keys)
WATCH one or more keys for optimistic locking.
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/isolated_scope.py
85 86 87 | |
unwatch()
Discard all watched keys.
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/isolated_scope.py
89 90 91 | |
multi()
Begin a transaction block.
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/isolated_scope.py
93 94 95 | |
exec()
Execute the transaction (returns None if WATCH detected a conflict).
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/isolated_scope.py
97 98 99 | |
discard()
Discard the transaction.
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/isolated_scope.py
101 102 103 | |
get(key)
GET a key value.
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/isolated_scope.py
105 106 107 | |
set(key, value)
SET a key to a value.
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/isolated_scope.py
109 110 111 | |
incr(key)
Increment a key's integer value by 1.
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/isolated_scope.py
113 114 115 | |
ping(message=None)
PING the server.
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/isolated_scope.py
117 118 119 120 121 | |
select(db)
SELECT a database by index.
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/isolated_scope.py
123 124 125 | |
execute_command(command, *args)
Execute an arbitrary command on this scope.
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/isolated_scope.py
127 128 129 | |
close()
Release the scope back to the pool.
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/isolated_scope.py
199 200 201 202 203 | |
MonitorClient
A client that streams all commands processed by the server via the MONITOR command.
Must be used with a standalone (non-cluster) configuration.
The configuration's lib_name and client_info_tag identify the dedicated
monitor connection, using GlidePySync as the default library name.
Warning: MONITOR is a debugging tool with performance implications. Do not use in production environments.
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/monitor_client.py
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 | |
create(config, callback=None)
classmethod
Create a new MonitorClient connected to the server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
GlideClientConfiguration
|
Standalone client configuration (must be GlideClientConfiguration). Its library-name override and client information tag are applied to the dedicated monitor connection. |
required |
callback
|
Optional[Callable[[MonitorMsg], None]]
|
Optional callback invoked for each MonitorMsg. If None, messages are queued and retrievable via get_monitor_message(). |
None
|
Returns:
| Type | Description |
|---|---|
MonitorClient
|
A MonitorClient instance. |
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/monitor_client.py
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 | |
get_monitor_message(timeout=None)
Block until a MonitorMsg is available, then return it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
Optional[float]
|
Optional timeout in seconds. Returns None on timeout or if closed. |
None
|
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/monitor_client.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
try_get_monitor_message()
Non-blocking retrieval. Returns None if no message is available.
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/monitor_client.py
156 157 158 159 | |
close()
Stop monitoring and release resources.
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/monitor_client.py
161 162 163 164 165 166 167 168 169 170 171 172 | |
stop()
Alias for close(). Stop monitoring and release resources.
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/monitor_client.py
174 175 176 | |
OpenTelemetry
Bases: OpenTelemetry
Sync client OpenTelemetry singleton (separate from async).
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/opentelemetry.py
11 12 13 14 15 | |
ClusterScanCursor
Bases: ClusterScanCursor
ClusterScanCursor using the sync package's FFI instance.
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/sync_commands/cluster_scan_cursor.py
7 8 9 10 11 | |
Script
Bases: Script
Script using the sync package's FFI instance.
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/sync_commands/script.py
7 8 9 10 11 | |
get_min_compressed_size()
Get the minimum compression size in bytes.
Returns the minimum size threshold for compression. Values smaller than this will not be compressed.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The minimum compression size in bytes (currently 6 bytes: 5-byte header + 1 byte data) |
Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/sync_commands/utils.py
6 7 8 9 10 11 12 13 14 15 16 17 | |