Skip to content

Server & Connection

Server and connection commands for managing the Redis protocol connection, authentication, and server information.

CommandSyntaxDescription
PINGPING [message]Test connection, returns PONG or echoes message
ECHOECHO messageEcho the given message
INFOINFO [section]Get server information and statistics
SELECTSELECT dbSelect database (0-15)
DBSIZEDBSIZEReturn number of keys in current database
FLUSHDBFLUSHDBDelete all keys in current database
QUITQUITClose the connection
AUTHAUTH passwordAuthenticate with password
COMMANDCOMMANDList all supported commands
CONFIGCONFIG GET/SET optionGet or set configuration
Terminal window
# Simple ping
127.0.0.1:6379> PING
PONG
# Ping with message
127.0.0.1:6379> PING "hello"
"hello"
# Echo message
127.0.0.1:6379> ECHO "testing"
"testing"
Terminal window
# Redlite supports databases 0-15 (like Redis)
127.0.0.1:6379> SELECT 0
OK
127.0.0.1:6379> SET key1 "in db 0"
OK
127.0.0.1:6379> SELECT 1
OK
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 0
OK
127.0.0.1:6379> GET key1
"in db 0"
Terminal window
# Count keys in current database
127.0.0.1:6379> DBSIZE
(integer) 42
# Clear current database
127.0.0.1:6379> FLUSHDB
OK
127.0.0.1:6379> DBSIZE
(integer) 0
Terminal window
127.0.0.1:6379> INFO
# Server
redis_version:7.0.0
redlite_version:0.1.0
os:darwin
arch:aarch64
# Clients
connected_clients:1
# Memory
used_memory:1048576
used_memory_human:1.00M
# Stats
total_connections_received:5
total_commands_processed:100
# Keyspace
db0:keys=42,expires=5
Terminal window
# Start server with password
$ redlite --db mydata.db --password mysecret
# Client must authenticate
127.0.0.1:6379> GET key
(error) NOAUTH Authentication required
127.0.0.1:6379> AUTH mysecret
OK
127.0.0.1:6379> GET key
"value"
Terminal window
# Get configuration values
127.0.0.1:6379> CONFIG GET maxmemory
1) "maxmemory"
2) "0"
127.0.0.1:6379> CONFIG GET maxmemory-policy
1) "maxmemory-policy"
2) "noeviction"
# Set configuration
127.0.0.1:6379> CONFIG SET maxmemory 104857600
OK
127.0.0.1:6379> CONFIG SET maxmemory-policy allkeys-lru
OK
# Get disk limit
127.0.0.1:6379> CONFIG GET maxdisk
1) "maxdisk"
2) "0"
Terminal window
127.0.0.1:6379> COMMAND
1) "GET"
2) "SET"
3) "DEL"
4) "MGET"
5) "MSET"
... (200+ commands)
OptionDescriptionDefault
maxmemoryMaximum memory in bytes (0 = unlimited)0
maxmemory-policyEviction policy when limit reachednoeviction
maxdiskMaximum disk size in bytes (0 = unlimited)0
persist-access-trackingPersist LRU/LFU tracking to diskauto
access-flush-intervalTracking flush interval in ms300000
PolicyDescription
noevictionReturn error when memory limit reached
allkeys-lruEvict least recently used keys
allkeys-lfuEvict least frequently used keys
allkeys-randomEvict random keys
volatile-lruEvict LRU keys with TTL set
volatile-lfuEvict LFU keys with TTL set
volatile-ttlEvict keys with shortest TTL
volatile-randomEvict random keys with TTL set
use redlite::Db;
// Open database (equivalent to connecting)
let db = Db::open("mydata.db")?;
// Select database (0-15)
db.select(1)?;
// Get database size
let count = db.dbsize()?;
// Clear database
db.flushdb()?;
// Configuration
db.set_max_memory(100 * 1024 * 1024); // 100MB
db.set_eviction_policy(EvictionPolicy::AllKeysLru);
Terminal window
# Start server with options
redlite --db mydata.db \
--host 127.0.0.1 \
--port 6379 \
--password mysecret \
--max-memory 100mb \
--max-disk 1gb
OptionDescription
--dbDatabase file path
--hostBind address (default: 127.0.0.1)
--portPort number (default: 6379)
--passwordRequire authentication
--max-memoryMemory limit for eviction
--max-diskDisk limit for eviction
Terminal window
# Simple liveness check
PING
# With custom message for identification
PING "worker-1"
Terminal window
# Each tenant gets a separate database
SELECT 0 # Tenant A
SET user:1 "Alice"
SELECT 1 # Tenant B
SET user:1 "Bob"
# Data is isolated
SELECT 0
GET user:1 # "Alice"
Terminal window
# Clear all test data
SELECT 15 # Use db 15 for tests
FLUSHDB
# Run tests...