LinuxCommandLibrary

redis-server

Start the Redis server

TLDR

Start Redis server, using the default port (6379), and write logs to stdout

$ redis-server
copy

Start Redis server, using the default port, as a background process
$ redis-server --daemonize yes
copy

Start Redis server, using the specified port, as a background process
$ redis-server --port [port] --daemonize yes
copy

Start Redis server with a custom configuration file
$ redis-server [path/to/redis.conf]
copy

Start Redis server with verbose logging
$ redis-server --loglevel [warning|notice|verbose|debug]
copy

SYNOPSIS

redis-server [/path/to/redis.conf] [--option value] [--option value]

PARAMETERS

<config_file>
    Specifies the path to the Redis configuration file. Options provided on the command line will override settings in this file.

--port <port_number>
    Sets the TCP port on which Redis will listen for connections. Default is 6379.

--daemonize <yes|no>
    If set to 'yes', Redis will run as a background process (daemon). Default is 'no'.

--loglevel <debug|verbose|notice|warning>
    Controls the verbosity of Redis logs. 'notice' is the default and recommended for production.

--bind <address> [<address>...]
    Binds Redis to specific IP addresses. By default, it binds to all available network interfaces if `protected-mode` is disabled, or to 127.0.0.1 if enabled.

--protected-mode <yes|no>
    Enables or disables protected mode. When enabled, Redis only accepts connections from localhost or via the `bind` directive unless a password is set.

--dir <directory>
    Sets the working directory where Redis will save RDB snapshot files and AOF log files.

--dbfilename <filename>
    Specifies the name of the RDB snapshot file. Default is dump.rdb.

--requirepass <password>
    Sets a password for client authentication. Clients must use the AUTH command to connect.

--maxmemory <bytes>
    Configures the maximum amount of memory Redis should use. When the limit is reached, Redis will start evicting keys based on the `maxmemory-policy`.

--slaveof <masterip> <masterport>
    Configures this Redis instance to be a replica (slave) of another Redis server (master).

--sentinel
    Runs Redis in Sentinel mode, used for high availability to monitor master and replica instances.

--cluster-enabled <yes|no>
    Enables or disables Redis Cluster support for sharding data across multiple instances.

DESCRIPTION

The `redis-server` command initiates the Redis server, an open-source, in-memory data structure store used as a database, cache, and message broker. Redis supports various data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, and geospatial indexes with radius queries.

When executed, `redis-server` listens for incoming client connections, typically on port 6379, enabling applications to store, retrieve, and manipulate data. It can run in the foreground, displaying logs to the console, or daemonized in the background. While primarily an in-memory database for high performance, Redis offers persistence options (RDB snapshots and AOF logs) to ensure data durability across server restarts.

The server's behavior is highly configurable via command-line arguments or, more commonly, through a `redis.conf` configuration file.

CAVEATS

Security:
By default, Redis 6+ runs with `protected-mode` enabled, binding only to localhost (127.0.0.1) unless specified otherwise. If `protected-mode` is disabled or Redis is bound to all interfaces (0.0.0.0) without a strong password, it can be vulnerable to unauthorized access.

Persistence:
While Redis is an in-memory store, it offers persistence. If persistence (RDB or AOF) is not properly configured, data stored in Redis may be lost upon server restart or crash.

Memory Usage:
Redis stores data primarily in RAM. Large datasets can consume significant memory, potentially impacting system stability if not managed via `maxmemory` settings.

CONFIGURATION FILE

The most common way to configure `redis-server` is by providing a `redis.conf` file as an argument. This file contains detailed settings for persistence, memory limits, logging, security, and more. Command-line options override settings in the configuration file, allowing for quick adjustments or specific instance configurations.

PERSISTENCE

Redis offers two primary methods for data persistence: RDB (Redis Database) snapshots, which are point-in-time compressed binary files of the dataset, and AOF (Append Only File), which logs every write operation received by the server. Users can configure Redis to use one or both, balancing performance with data durability requirements.

SERVICE MANAGEMENT

In production environments, `redis-server` is typically run as a background daemon and managed via a system service manager like systemd (`systemctl`). This ensures Redis starts automatically on boot, can be easily started/stopped, and its processes are monitored for stability.

HISTORY

Redis was created by Salvatore Sanfilippo (also known as antirez) in 2009. Initially developed to improve the scalability of his startup's real-time web analytics service, Redis quickly gained popularity as a standalone open-source project. Its unique combination of performance, versatility, and rich data structures led to its widespread adoption across various industries. Over the years, it has evolved significantly, adding features like replication, persistence, clustering, and high availability (Sentinel), becoming one of the most widely used NoSQL databases and caching solutions. While Salvatore stepped down as the lead developer in 2020, development continues under the stewardship of Redis Inc. and the broader community.

SEE ALSO

redis-cli(1), redis-sentinel(1), systemctl(1), ss(8), netstat(8)

Copied to clipboard