The ocachecli command-line tool provides a convenient interface for interacting with the OCache service. It features a unified client architecture with automatic mode detection, connection pooling, and smart routing capabilities.
Build the CLI from source:
make build-cliThis creates the ocachecli executable in the project root.
The CLI supports three connection modes that determine how it connects to cache servers:
Automatically detects whether to use cluster or simple mode by checking for topology service availability:
# Auto-detects the appropriate mode
ocachecli --addr localhost:9000 <command>
# Multiple servers - will detect if cluster topology is available
ocachecli --addr "node1:9001,node2:9002,node3:9003" <command>Direct connections without topology service. Uses hash-based routing for multiple servers:
# Force simple mode
ocachecli --mode simple --addr "server1:9000,server2:9000" <command>Uses topology service for smart routing with consistent hashing:
# Force cluster mode (requires topology service)
ocachecli --mode cluster --addr "node1:9001,node2:9002" <command>| Flag | Description | Default |
|---|---|---|
--addr |
Cache server address(es), comma-separated for multiple servers | localhost:9000 |
--mode |
Connection mode: auto, simple, or cluster |
auto |
--topology-refresh |
Topology refresh interval (cluster mode only) | 30s |
Store a value in the cache:
# Put with value as argument
ocachecli put mykey "my value"
# Put with TTL
ocachecli put mykey "my value" --ttl 3600
# Put from stdin (useful for large files)
cat file.txt | ocachecli put mykey
# Multiple servers with auto-detection
ocachecli --addr "node1:9001,node2:9002" put mykey "value"
# Force specific mode
ocachecli --mode cluster --addr "node1:9001" put mykey "value"Retrieve a value from the cache:
# Get a value
ocachecli get mykey
# Multiple servers
ocachecli --addr "node1:9001,node2:9002" get mykey
# Save to file
ocachecli get mykey > output.txtRemove a key from the cache:
# Delete a key
ocachecli del mykey
# Delete with multiple servers
ocachecli --addr "node1:9001,node2:9002" del mykeyList keys in the cache:
# List all keys
ocachecli list
# List with prefix filter
ocachecli list --prefix "user:"
# Multiple servers
ocachecli --addr "node1:9001,node2:9002" list --prefix "session:"Inspect cluster topology and key ownership. These commands only work when connected to a cluster-enabled server.
Display full cluster topology including nodes and ring configuration:
# Display cluster topology
ocachecli cluster topology
# Output in JSON format
ocachecli cluster topology --jsonExample output:
Cluster Topology (Epoch: 12345678901234567890)
Ring Configuration:
Replication Factor: 1
Total Tokens: 384
Nodes:
NODE ID STATUS LISTEN ADDRESS CLUSTER ADDRESS JOINED AT
------- ------ -------------- --------------- ---------
node1 ACTIVE localhost:9001 localhost:7001 2025-01-09T10:30:00Z
node2 ACTIVE localhost:9002 localhost:7002 2025-01-09T10:30:05Z
node3 ACTIVE localhost:9003 localhost:7003 2025-01-09T10:30:10Z
Get the node that owns a specific key:
# Find which node owns a key
ocachecli cluster node mykey
# Output in JSON format
ocachecli cluster node mykey --jsonExample output:
Key: mykey
Node: node2
Address: localhost:9002
Display the current topology epoch:
# Display epoch
ocachecli cluster epoch
# Output in JSON format
ocachecli cluster epoch --jsonExample output:
Epoch: 12345678901234567890
| Flag | Description | Default |
|---|---|---|
--json |
Output in JSON format | false |
When using the default auto mode:
- The client attempts to connect to the provided addresses
- It checks if a cluster topology service is available
- If topology service is found → operates in cluster mode
- If no topology service → operates in simple mode
- Direct connections to all provided addresses
- Each address gets its own connection pool
- Hash-based routing distributes keys across servers
- No automatic failover (relies on gRPC retries)
- Best for standalone servers or simple multi-server setups
- Fetches and maintains cluster topology
- Smart routing based on consistent hashing
- Automatic topology refresh at configured intervals
- Handles node additions/removals gracefully
- Partition-aware routing ensures keys go to correct nodes
- Best for production clusters with coordinator service
The CLI uses connection pooling for better performance:
- Benefits:
- Better load distribution
- Reduced connection setup overhead
- Higher throughput for concurrent operations
- Resilience to individual connection failures
# Auto mode will detect simple mode for single server
ocachecli --addr localhost:9000 put mykey "value"
# Store a configuration file
cat config.json | ocachecli put app:config --ttl 86400
# Retrieve configuration
ocachecli get app:config
# List all app configurations
ocachecli list --prefix "app:"
# Delete old configuration
ocachecli del app:config:old# Define servers
SERVERS="cache1:9001,cache2:9002,cache3:9003"
# Auto-detect mode (cluster if topology service available, simple otherwise)
ocachecli --addr "$SERVERS" put "user:123" '{"name":"Alice"}'
# Force simple mode for basic distribution
ocachecli --mode simple --addr "$SERVERS" get "user:123"
# Force cluster mode for smart routing (requires topology service)
ocachecli --mode cluster --addr "$SERVERS" del "user:123"See Benchmark Guide for more details.
The CLI provides clear error messages for common issues:
# Connection errors
Failed to create client: failed to create pool for localhost:9000
# Cluster mode specific
Failed to fetch initial topology: no topology service available
Error: cluster commands require cluster mode. Connected in simple mode.
# General errors
Get failed: rpc error: code = NotFound desc = key not found- Use Auto Mode: Let the client detect the best mode automatically
- Pool Size Tuning: Start with defaults, increase for high concurrency workloads
- Streaming: Automatically used for values > 4MB
- Mode Selection:
- Use
simplemode for development or standalone servers - Use
clustermode for production clusters with coordinator - Use
automode when unsure (recommended)
- Use
- Benchmark First: Test with your actual workload patterns
# Test basic connectivity
ocachecli --addr localhost:9000 put test "value"
# Check if cluster mode is available
ocachecli --addr "node1:9001,node2:9002" cluster topology
# Will show error if cluster mode is not available
# Force specific mode to isolate issues
ocachecli --mode simple --addr "node1:9001" put test "value"
ocachecli --mode cluster --addr "node1:9001" put test "value"If auto mode isn't detecting correctly:
- Check if coordinator service is running (for cluster mode)
- Verify network connectivity to all nodes
- Force the desired mode explicitly
- Check server logs for topology service errors
0: Success1: Error (invalid arguments, connection failure, operation failure, or interrupted)
The CLI provides a simple yet powerful interface for interacting with OCache:
- Auto mode by default for zero configuration
- Connection pooling always enabled for better performance
- Smart routing in cluster mode for optimal key distribution
- Simple mode for straightforward multi-server setups
- Consistent interface regardless of deployment topology