OpenBSD Handbook

    • Part I. Install & Configure
      • Introduction
      • Installing OpenBSD
      • The X Window System
      • Networking
      • System Configuration
      • OpenBSD Basics
      • Managing Software: Packages and Ports
    • Part II. Daily Operations
      • Graphical Environments
      • Multimedia
      • Printing
      • Linux Compatibility
      • Windows Compatibility
      • Games
    • Part III. System Administration
      • Security
      • Virtualization
      • Storage and File Systems
      • Updating and Upgrading
      • Localization
      • The OpenBSD Boot Process
    • Part IV. Networking & Daemons
      • Services
        • Database
          • MariaDB
          • PostgreSQL
          • Redis
          • memcached
        • Directory
          • YP (NIS)
          • LDAP
        • File
          • NFS
          • Samba
        • FTP Services
          • ftpd
          • ProFTPD
          • vsftpd
          • TFTP
        • Mail
          • Dovecot
          • smtpd
          • Postfix
          • Exim
          • Rspamd
        • Name
          • Named
          • Unbound
          • NSD
        • Networking
          • OpenBGPD
          • rtadvd
          • DHCP
          • slaacd
        • Web
          • Apache
          • nginx
          • httpd
          • relayd
        • Logging
          • syslogd
        • Monitoring
          • SNMP
        • Remote Access
          • Audit OpenSSH
          • sshd
        • File Synchronization
          • rsync
        • Messaging
          • RabbitMQ
        • Time
          • NTP
      • PF
        • pfctl cheat sheet
        • PF Anchors
        • PF Filter Rules
        • PF Forwarding
        • PF Lists and Macros
        • PF Load Balancing
        • PF Logging
        • PF NAT
        • PF Options
        • PF Policies
        • PF Shortcuts
        • PF Tables
      • Advanced Networking
        • High Availability and State Replication
        • Multi-WAN and Policy-Based Routing
        • VPN and Cryptographic Tunneling
        • Classic and Lightweight Tunnels
        • IPv6 at Scale
        • QoS and Traffic Shaping
        • MPLS and Label Distribution
        • Network Services at Scale
        • Virtualization and Host Networking
        • Large-Scale L2 and L3 Design
        • Telemetry, Logging, and Flow Export
        • Hardening and Operational Safety
        • Reference Architectures
        • Troubleshooting Playbooks
      • Serial Communication
    • Part V. Miscellaneous
      • Virtualization Cheat Sheet
      • OpenBSD Cheatsheet
      • Howto
        • Install Z shell (zsh)
        • Set Up WordPress
        • Build a Simple Router and Firewall
      • OpenBSD for Linux Users
      • OpenBSD for FreeBSD Users
      • OpenBSD for macOS Users
    • Package Search
      Redis
      • Synopsis
      • Installation
      • Configuration
      • Enabling the Service
      • Basic Usage
      • Persistence
      • Remote Access and Security
      • Service Management

      Redis

      Synopsis #

      Redis is an in-memory key-value store designed for high performance, low latency, and a wide range of data structures such as strings, hashes, sets, sorted sets, and streams. It supports optional disk persistence, 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:

      # pkg_add redis
      

      This installs:

      • redis-server: the main daemon
      • redis-cli: command-line interface client
      • Default configuration at /etc/redis.conf

      Configuration #

      The main configuration file is:

      /etc/redis.conf
      

      A minimal configuration example:

      bind 127.0.0.1
      port 6379
      
      daemonize no
      supervised auto
      pidfile /var/run/redis.pid
      logfile /var/log/redis.log
      
      dir /var/redis
      dbfilename dump.rdb
      

      Key options:

      • bind: restricts listening to loopback
      • port: default is 6379
      • daemonize: no for rcctl compatibility
      • dir: working directory for data persistence
      • logfile: optional file logging (otherwise logs to syslog)

      Create the data directory if not present:

      # mkdir -p /var/redis
      # chown _redis:_redis /var/redis
      

      Enabling the Service #

      Enable and start Redis:

      # rcctl enable redis
      # rcctl start redis
      

      Check status:

      # rcctl check redis
      

      View logs:

      # tail -f /var/log/redis.log
      

      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:

      1. RDB (snapshotting) — default method using dump.rdb
      2. AOF (append-only file) — logs each write operation

      To enable AOF persistence in /etc/redis.conf:

      appendonly yes
      appendfilename "appendonly.aof"
      

      Restart Redis to apply:

      # rcctl restart redis
      

      Backups can be made by copying the .rdb or .aof files from /var/redis.

      Remote Access and Security #

      By default, Redis binds to 127.0.0.1 only.

      To allow access from remote hosts (not recommended unless protected):

      1. Change bind address in /etc/redis.conf:
      bind 127.0.0.1 192.0.2.1
      
      1. (Optional) Set a password:
      requirepass "strongsecret"
      
      1. Use pf(4) to restrict port 6379:
      pass in on $int_if proto tcp from 192.0.2.0/24 to port 6379
      
      1. Restart Redis:
      # rcctl restart redis
      

      Accessing with authentication:

      $ redis-cli -a strongsecret
      

      Important: Redis does not support TLS natively in OpenBSD’s package (as of 7.6). To proxy TLS, use relayd(8) or stunnel.

      Service Management #

      Standard service commands:

      # rcctl enable redis
      # rcctl start redis
      # rcctl restart redis
      # rcctl check redis
      
      Report a bug
      • Synopsis
      • Installation
      • Configuration
      • Enabling the Service
      • Basic Usage
      • Persistence
      • Remote Access and Security
      • Service Management