ESUB
Subscribe to events from one or more streams with real-time delivery.
Syntax
# Single stream
ESUB <stream_id> [PARTITION_KEY <partition_key>] [FROM <version>] [WINDOW <size>]
# Multiple streams
ESUB <stream_id_1> [PARTITION_KEY <pk_1>] <stream_id_2> [PARTITION_KEY <pk_2>] ...
[FROM LATEST | FROM <version> | FROM MAP <stream>=<ver>...] [WINDOW <size>]
Parameters
| Parameter | Type | Description |
|---|---|---|
stream_id | String | Stream identifier(s) to subscribe to |
partition_key | UUID | UUID for specific partition (optional) |
FROM | Position | Starting position (LATEST, version number, or MAP) |
WINDOW | Integer | Maximum number of unacknowledged events |
Examples
Basic Subscription
# Subscribe to latest events
ESUB user-123
# Subscribe from specific version
ESUB user-123 FROM 50
# Subscribe with window
ESUB user-123 FROM LATEST WINDOW 100
Multiple Stream Subscription
# Subscribe to multiple streams
ESUB user-1 user-2 user-3 FROM LATEST
# With per-stream starting positions
ESUB user-1 user-2 user-3 FROM MAP user-1=10 user-2=20 user-3=30 WINDOW 50
Client Examples
Python
import redis
client = redis.Redis(host='localhost', port=9090, protocol=3, decode_responses=False)
# Create subscription
subscription_id = client.execute_command('ESUB', 'user-123', 'FROM', 'LATEST', 'WINDOW', '100')
print(f"Subscription ID: {subscription_id}")
# Process events (this blocks)
pubsub = client.pubsub()
for message in pubsub.listen():
if message['type'] == 'message':
# Process event
event_data = message['data']
print(f"Received event: {event_data}")
# Acknowledge processing
client.execute_command('EACK', subscription_id, event_version)
Related Commands
ESCAN- Read historical events