Configuration

Configuration #

Redict is able to start without a configuration file using a built-in default configuration, however this setup is only recommended for testing and development purposes.

The proper way to configure Redict is by providing a Redict configuration file, usually called redict.conf.

The redict.conf file contains a number of directives that have a very simple format:

keyword argument1 argument2 ... argumentN

This is an example of a configuration directive:

replicaof 127.0.0.1 6380

It is possible to provide strings containing spaces as arguments using (double or single) quotes, as in the following example:

requirepass "hello world"

Single-quoted string can contain characters escaped by backslashes, and double-quoted strings can additionally include any ASCII symbols encoded using backslashed hexadecimal notation “\xff”.

The list of configuration directives, and their meaning and intended usage is available in the self documented example redict.conf shipped into the Redict distribution.

Passing arguments via the command line #

You can also pass Redict configuration parameters using the command line directly. This is very useful for testing purposes. The following is an example that starts a new Redict instance using port 6380 as a replica of the instance running at 127.0.0.1 port 6379.

./redict-server --port 6380 --replicaof 127.0.0.1 6379

The format of the arguments passed via the command line is exactly the same as the one used in the redict.conf file, with the exception that the keyword is prefixed with --.

Note that internally this generates an in-memory temporary config file (possibly concatenating the config file passed by the user, if any) where arguments are translated into the format of redict.conf.

Changing Redict configuration while the server is running #

It is possible to reconfigure Redict on the fly without stopping and restarting the service, or querying the current configuration programmatically using the special commands CONFIG SET and CONFIG GET.

Not all of the configuration directives are supported in this way, but most are supported as expected. Please refer to the CONFIG SET and CONFIG GET pages for more information.

Note that modifying the configuration on the fly has no effects on the redict.conf file so at the next restart of Redict the old configuration will be used instead.

Make sure to also modify the redict.conf file accordingly to the configuration you set using CONFIG SET. You can do it manually, or you can use CONFIG REWRITE, which will automatically scan your redis.conf file and update the fields which don’t match the current configuration value. Fields non existing but set to the default value are not added. Comments inside your configuration file are retained.

Configuring Redict as a cache #

If you plan to use Redict as a cache where every key will have an expire set, you may consider using the following configuration instead (assuming a max memory limit of 2 megabytes as an example):

maxmemory 2mb
maxmemory-policy allkeys-lru

In this configuration there is no need for the application to set a time to live for keys using the EXPIRE command (or equivalent) since all the keys will be evicted using an approximated LRU algorithm as long as we hit the 2 megabyte memory limit.

Basically, in this configuration Redict acts in a similar way to memcached. We have more extensive documentation about using Redict as an LRU cache here.

Redict logo courtesy of @janWilejan, CC-BY-SA-4.0. Download SVG ⤑

Portions of this website courtesy of Salvatore Sanfilippo, CC-BY-SA-4.0.