Synopsis #
Redis stores key-value data in memory, including strings, hashes, sets, sorted sets, and streams. It also supports saving data to disk, replication, and Lua scripting.
Redis is commonly used for caching, messaging, job queues, and ephemeral data storage.
Redis is not included in the OpenBSD base system, but is available via packages. The Redis server runs as a daemon (redis-server) and is managed with rcctl(8).
Installation #
Install the Redis package:
doas pkg_add redis
This installs:
redis-server: the main daemonredis-cli: command-line interface client- Default configuration at
/etc/redis/redis.conf
Configuration #
The main configuration file is:
/etc/redis/redis.conf
A minimal configuration example:
bind 127.0.0.1
port 6379
daemonize yes
pidfile /var/run/redis/redis.pid
logfile ""
syslog-enabled yes
syslog-facility daemon
dir /var/redis
dbfilename dump.rdb
Key options:
bind: restricts listening to loopbackport: default is 6379daemonize:yesfor the packaged rc servicedir: working directory for data persistencelogfile: optional file logging; syslog requiressyslog-enabled yes
Create the data directory if not present:
doas mkdir -p /var/redis
doas chown _redis:_redis /var/redis
Enabling the Service #
Enable and start Redis:
doas rcctl enable redis
doas rcctl start redis
Check status:
doas rcctl check redis
View logs:
doas tail -f /var/log/daemon
Basic Usage #
Connect using the Redis client:
$ redis-cli
127.0.0.1:6379> SET keyname "hello"
OK
127.0.0.1:6379> GET keyname
"hello"
Exit the client with CTRL+D or QUIT.
Persistence #
Redis can save the dataset to disk in two ways:
- RDB (snapshotting) — default method using
dump.rdb - AOF (append-only file) — logs each write operation
To enable AOF persistence in /etc/redis/redis.conf:
appendonly yes
appendfilename "appendonly.aof"
Restart Redis to apply:
doas rcctl restart redis
For a backup, stop Redis cleanly, copy its configured persistence files, then restart it. Test restoration in a separate instance. For backups without downtime, use a completed RDB snapshot or follow the documented AOF backup procedure; copying files during an AOF rewrite may produce an incomplete backup.
Remote Access and Security #
By default, Redis binds to 127.0.0.1 only.
To allow access from remote hosts (not recommended unless protected):
- Change bind address in
/etc/redis/redis.conf:
bind 127.0.0.1 192.0.2.1
- (Optional) Set a password:
requirepass "strongsecret"
- Use
pf(4)to restrict port 6379:
pass in on $int_if proto tcp from 192.0.2.0/24 to port 6379
- Restart Redis:
doas rcctl restart redis
Accessing with authentication:
redis-cli -a strongsecret
The OpenBSD 8.0 Redis ports build TLS support. Configure Redis TLS certificates and listeners following the installed configuration documentation; the plain TCP example above does not encrypt traffic.
Service Management #
Standard service commands:
doas rcctl enable redis
doas rcctl start redis
doas rcctl restart redis
doas rcctl check redis