Server Mode
While Redlite is designed as an embedded library, it also includes a standalone server that speaks the Redis protocol. This lets you use any Redis client to connect.
Starting the Server
Section titled “Starting the Server”Basic Usage
Section titled “Basic Usage”# Default: persistent storage, port 6767./redlite --db=mydata.db
# In-memory mode./redlite --db=:memory:Custom Port
Section titled “Custom Port”# Use Redis default port./redlite --db=mydata.db --addr=127.0.0.1:6379
# Bind to all interfaces./redlite --db=mydata.db --addr=0.0.0.0:6767Command Line Options
Section titled “Command Line Options”| Option | Default | Description |
|---|---|---|
--db, -d | redlite.db | Database file path (:memory: for in-memory) |
--addr, -a | 127.0.0.1:6767 | Listen address and port |
Connecting with redis-cli
Section titled “Connecting with redis-cli”$ redis-cli -p 6767
127.0.0.1:6767> PINGPONG
127.0.0.1:6767> SET name "Redlite"OK
127.0.0.1:6767> GET name"Redlite"
127.0.0.1:6767> SET temp "expires" PX 5000OK
127.0.0.1:6767> GET temp"expires"
# Wait 5 seconds...
127.0.0.1:6767> GET temp(nil)Using Redis Client Libraries
Section titled “Using Redis Client Libraries”Python
Section titled “Python”import redis
r = redis.Redis(host='localhost', port=6767)
# String operationsr.set('foo', 'bar')print(r.get('foo')) # b'bar'
# With expirationr.setex('session', 60, 'user_data') # expires in 60 secondsNode.js
Section titled “Node.js”import { createClient } from 'redis';
const client = createClient({ url: 'redis://localhost:6767' });await client.connect();
// String operationsawait client.set('foo', 'bar');console.log(await client.get('foo')); // 'bar'
// With expirationawait client.setEx('session', 60, 'user_data');package main
import ( "context" "github.com/redis/go-redis/v9")
func main() { rdb := redis.NewClient(&redis.Options{ Addr: "localhost:6767", })
ctx := context.Background()
rdb.Set(ctx, "foo", "bar", 0) val, _ := rdb.Get(ctx, "foo").Result() // val == "bar"}use redis::Commands;
fn main() -> redis::RedisResult<()> { let client = redis::Client::open("redis://127.0.0.1:6767/")?; let mut con = client.get_connection()?;
con.set("foo", "bar")?; let value: String = con.get("foo")?; // value == "bar"
Ok(())}Running as a Service
Section titled “Running as a Service”systemd (Linux)
Section titled “systemd (Linux)”Create /etc/systemd/system/redlite.service:
[Unit]Description=Redlite KV StoreAfter=network.target
[Service]Type=simpleExecStart=/usr/local/bin/redlite --db=/var/lib/redlite/data.dbRestart=alwaysUser=redliteGroup=redlite
[Install]WantedBy=multi-user.targetsudo systemctl enable redlitesudo systemctl start redliteDocker
Section titled “Docker”FROM rust:1.75 as builderWORKDIR /appCOPY . .RUN cargo build --release
FROM debian:bookworm-slimCOPY --from=builder /app/target/release/redlite /usr/local/bin/EXPOSE 6767CMD ["redlite", "--db=/data/redlite.db", "--addr=0.0.0.0:6767"]docker build -t redlite .docker run -p 6767:6767 -v redlite-data:/data redliteDifferences from Redis
Section titled “Differences from Redis”When using server mode, be aware of these differences:
- Persistence - Data is always persisted (unless using
:memory:) - Memory - Not bounded by RAM; uses disk storage
- Commands - Only subset of Redis commands supported (see Commands)
- Clustering - No cluster mode; single-node only
- Pub/Sub - Not yet implemented