Skip to content

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.

Terminal window
# Default: persistent storage, port 6767
./redlite --db=mydata.db
# In-memory mode
./redlite --db=:memory:
Terminal window
# 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:6767
OptionDefaultDescription
--db, -dredlite.dbDatabase file path (:memory: for in-memory)
--addr, -a127.0.0.1:6767Listen address and port
Terminal window
$ redis-cli -p 6767
127.0.0.1:6767> PING
PONG
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 5000
OK
127.0.0.1:6767> GET temp
"expires"
# Wait 5 seconds...
127.0.0.1:6767> GET temp
(nil)
import redis
r = redis.Redis(host='localhost', port=6767)
# String operations
r.set('foo', 'bar')
print(r.get('foo')) # b'bar'
# With expiration
r.setex('session', 60, 'user_data') # expires in 60 seconds
import { createClient } from 'redis';
const client = createClient({ url: 'redis://localhost:6767' });
await client.connect();
// String operations
await client.set('foo', 'bar');
console.log(await client.get('foo')); // 'bar'
// With expiration
await 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(())
}

Create /etc/systemd/system/redlite.service:

[Unit]
Description=Redlite KV Store
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/redlite --db=/var/lib/redlite/data.db
Restart=always
User=redlite
Group=redlite
[Install]
WantedBy=multi-user.target
Terminal window
sudo systemctl enable redlite
sudo systemctl start redlite
FROM rust:1.75 as builder
WORKDIR /app
COPY . .
RUN cargo build --release
FROM debian:bookworm-slim
COPY --from=builder /app/target/release/redlite /usr/local/bin/
EXPOSE 6767
CMD ["redlite", "--db=/data/redlite.db", "--addr=0.0.0.0:6767"]
Terminal window
docker build -t redlite .
docker run -p 6767:6767 -v redlite-data:/data redlite

When using server mode, be aware of these differences:

  1. Persistence - Data is always persisted (unless using :memory:)
  2. Memory - Not bounded by RAM; uses disk storage
  3. Commands - Only subset of Redis commands supported (see Commands)
  4. Clustering - No cluster mode; single-node only
  5. Pub/Sub - Not yet implemented