Server & Connection
Server and connection commands for managing the Redis protocol connection, authentication, and server information.
Commands
Section titled âCommandsâ| Command | Syntax | Description |
|---|---|---|
| PING | PING [message] | Test connection, returns PONG or echoes message |
| ECHO | ECHO message | Echo the given message |
| INFO | INFO [section] | Get server information and statistics |
| SELECT | SELECT db | Select database (0-15) |
| DBSIZE | DBSIZE | Return number of keys in current database |
| FLUSHDB | FLUSHDB | Delete all keys in current database |
| QUIT | QUIT | Close the connection |
| AUTH | AUTH password | Authenticate with password |
| COMMAND | COMMAND | List all supported commands |
| CONFIG | CONFIG GET/SET option | Get or set configuration |
Examples
Section titled âExamplesâConnection Testing
Section titled âConnection Testingâ# Simple ping127.0.0.1:6379> PINGPONG
# Ping with message127.0.0.1:6379> PING "hello""hello"
# Echo message127.0.0.1:6379> ECHO "testing""testing"Database Selection
Section titled âDatabase Selectionâ# Redlite supports databases 0-15 (like Redis)127.0.0.1:6379> SELECT 0OK
127.0.0.1:6379> SET key1 "in db 0"OK
127.0.0.1:6379> SELECT 1OK
127.0.0.1:6379> SET key1 "in db 1"OK
127.0.0.1:6379> GET key1"in db 1"
127.0.0.1:6379> SELECT 0OK
127.0.0.1:6379> GET key1"in db 0"Database Statistics
Section titled âDatabase Statisticsâ# Count keys in current database127.0.0.1:6379> DBSIZE(integer) 42
# Clear current database127.0.0.1:6379> FLUSHDBOK
127.0.0.1:6379> DBSIZE(integer) 0Server Information
Section titled âServer Informationâ127.0.0.1:6379> INFO# Serverredis_version:7.0.0redlite_version:0.1.0os:darwinarch:aarch64
# Clientsconnected_clients:1
# Memoryused_memory:1048576used_memory_human:1.00M
# Statstotal_connections_received:5total_commands_processed:100
# Keyspacedb0:keys=42,expires=5Authentication
Section titled âAuthenticationâ# Start server with password$ redlite --db mydata.db --password mysecret
# Client must authenticate127.0.0.1:6379> GET key(error) NOAUTH Authentication required
127.0.0.1:6379> AUTH mysecretOK
127.0.0.1:6379> GET key"value"Configuration
Section titled âConfigurationâ# Get configuration values127.0.0.1:6379> CONFIG GET maxmemory1) "maxmemory"2) "0"
127.0.0.1:6379> CONFIG GET maxmemory-policy1) "maxmemory-policy"2) "noeviction"
# Set configuration127.0.0.1:6379> CONFIG SET maxmemory 104857600OK
127.0.0.1:6379> CONFIG SET maxmemory-policy allkeys-lruOK
# Get disk limit127.0.0.1:6379> CONFIG GET maxdisk1) "maxdisk"2) "0"List Supported Commands
Section titled âList Supported Commandsâ127.0.0.1:6379> COMMAND1) "GET"2) "SET"3) "DEL"4) "MGET"5) "MSET"... (200+ commands)Configuration Options
Section titled âConfiguration Optionsâ| Option | Description | Default |
|---|---|---|
maxmemory | Maximum memory in bytes (0 = unlimited) | 0 |
maxmemory-policy | Eviction policy when limit reached | noeviction |
maxdisk | Maximum disk size in bytes (0 = unlimited) | 0 |
persist-access-tracking | Persist LRU/LFU tracking to disk | auto |
access-flush-interval | Tracking flush interval in ms | 300000 |
Eviction Policies
Section titled âEviction Policiesâ| Policy | Description |
|---|---|
noeviction | Return error when memory limit reached |
allkeys-lru | Evict least recently used keys |
allkeys-lfu | Evict least frequently used keys |
allkeys-random | Evict random keys |
volatile-lru | Evict LRU keys with TTL set |
volatile-lfu | Evict LFU keys with TTL set |
volatile-ttl | Evict keys with shortest TTL |
volatile-random | Evict random keys with TTL set |
Library Mode (Rust)
Section titled âLibrary Mode (Rust)âuse redlite::Db;
// Open database (equivalent to connecting)let db = Db::open("mydata.db")?;
// Select database (0-15)db.select(1)?;
// Get database sizelet count = db.dbsize()?;
// Clear databasedb.flushdb()?;
// Configurationdb.set_max_memory(100 * 1024 * 1024); // 100MBdb.set_eviction_policy(EvictionPolicy::AllKeysLru);CLI Options
Section titled âCLI Optionsâ# Start server with optionsredlite --db mydata.db \ --host 127.0.0.1 \ --port 6379 \ --password mysecret \ --max-memory 100mb \ --max-disk 1gb| Option | Description |
|---|---|
--db | Database file path |
--host | Bind address (default: 127.0.0.1) |
--port | Port number (default: 6379) |
--password | Require authentication |
--max-memory | Memory limit for eviction |
--max-disk | Disk limit for eviction |
Use Cases
Section titled âUse CasesâHealth Check
Section titled âHealth Checkâ# Simple liveness checkPING
# With custom message for identificationPING "worker-1"Multi-Tenant Isolation
Section titled âMulti-Tenant Isolationâ# Each tenant gets a separate databaseSELECT 0 # Tenant ASET user:1 "Alice"
SELECT 1 # Tenant BSET user:1 "Bob"
# Data is isolatedSELECT 0GET user:1 # "Alice"Development Reset
Section titled âDevelopment Resetâ# Clear all test dataSELECT 15 # Use db 15 for testsFLUSHDB# Run tests...