Jump to content

# Redis

1 language

- 日本語

From ArchWiki

From Wikipedia:Redis:

  Redis is a software project that implements data structure servers. It is open-source, networked, in-memory, and stores keys with optional durability.

## Installation

Install the redis package.

Start/enable `redis.service`.

### Client-side software

- Python: python-redis
- PHP: php-redis
- C: hiredis

## Configuration

The Redis configuration file is well-documented and located at `/etc/redis/redis.conf`.

- Accept connections on the specified port (default is 6379), specify `port 0` to disable listening on TCP:

    port 6379

### Listen on socket

Using Redis over a Unix socket may give a performance increase, compared to TCP/IP [1].

The following changes should be made in `/etc/redis/redis.conf` to enable use of the unix socket:

- Enable and update the Redis socket path:

    unixsocket /run/redis/redis.sock

- Set permission to the socket to all members of the `redis` user group:

    unixsocketperm 770

- Add users (e.g. "git", "http") to the `redis` user group so they can access and use the socket.

Finally restart the `redis.service`.

### Redis JSON

JSON objects now have support in Redis. To use this feature you need to install the JSON module redis-rejsonAUR then edit `/etc/redis/redis.conf` and add in the modules section of the config:

    loadmodule /usr/lib/redis/rejson.so

Then restart `redis.service` to enable Redis JSON.

## Troubleshooting

### Warning about Transparent Huge Pages (THP)

To solve warning messages as "you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis", you may want to permanently disable this feature:

    /etc/tmpfiles.d/redis.conf

    w /sys/kernel/mm/transparent_hugepage/enabled - - - - never
    w /sys/kernel/mm/transparent_hugepage/defrag - - - - never

### Warning about TCP backlog

To solve warning messages as "The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128", increase the current value:

    /etc/sysctl.d/99-sysctl.conf

    net.core.somaxconn=512

### Warning about overcommit_memory is set to 0

To solve warning messages as "overcommit_memory is set to 0! Background save may fail under low memory condition":

    /etc/sysctl.d/99-sysctl.conf

    vm.overcommit_memory=1

Category:

- Database management systems