ESVER
Get the current version number for a stream.
Syntax
ESVER <stream_id> [PARTITION_KEY <partition_key>]
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
stream_id | String | Yes | Stream identifier to get version for |
partition_key | UUID | No | UUID to check specific partition |
Return Value
Integer or Null: Current version number of the stream, or null if the stream doesn't exist.
- If stream exists: Returns the current version number (starting from 0)
- If stream doesn't exist: Returns
null
Examples
Basic Usage
ESVER user-123
Returns:
4
With Partition Key
ESVER user-123 PARTITION_KEY 550e8400-e29b-41d4-a716-446655440000
Returns:
2
Non-existent Stream
ESVER user-999
Returns:
null
Client Examples
Python
import redis
client = redis.Redis(host='localhost', port=9090, protocol=3)
# Get current version
version = client.execute_command('ESVER', 'user-123')
print(f"Current version: {version}")
# Use for optimistic concurrency
def append_with_version_check(stream_id, event_name, payload):
current_version = client.execute_command('ESVER', stream_id)
try:
new_version = client.execute_command(
'EAPPEND', stream_id, event_name,
'EXPECTED_VERSION', current_version,
'PAYLOAD', payload
)
return new_version
except redis.ResponseError as e:
if 'WRONG_EXPECTED_VERSION' in str(e):
print("Concurrent modification detected")
raise
JavaScript
const version = await client.sendCommand(['ESVER', 'user-123']);
console.log(`Current stream version: ${version}`);