Redis

From XennisWiki
Jump to: navigation, search

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

Setup

Arch Linux

Install the redis package.

Debian

Install redis-cli
apt-get install redis-tools
Install redis server
apt-get install redis-server

Use Docker container

Further information: Docker Hub Redis Container, redis-cli, the Redis command line interface

Pull the Redis container

docker pull redis

Run the container as some-redis and bind the exposed port 6379 to 6000 at localhost

docker run --name some-redis -d -p 127.0.0.1:6000:6379 redis

Use redis-cli to ping the redis

redis-cli -p 6000 ping

Basic usage

Open a Redis command line (for instance with the argument port 6000)

redis-cli -p 6000
127.0.0.1:6379> ping 
PONG
127.0.0.1:6379> SET name "test" 
OK 
127.0.0.1:6379> GET name 
"test"
127.0.0.1:6000> KEYS "*"
1) "name"
127.0.0.1:6000> DEL name
(integer) 1

(1) Show information (statistic), (2) Output number of keys in server, (3) crash the server for debugging by executing an invalid memory access and (4) delete all keys

INFO
DBSIZE
DEBUG SEGFAULT
FLUSHALL

Monitor

Start to monitor Redis

redis-cli -p 6000 monitor

Exemplary output of the monitor

1490176137.196157 [0 172.17.0.1:33980] "ping"
1490176138.796191 [0 172.17.0.1:33980] "SET" "name" "test"
1490176141.372171 [0 172.17.0.1:33980] "GET" "name"
1490176143.564055 [0 172.17.0.1:33980] "KEYS" "*"

Benchmark

Run a benchmark with 1000 number of parallel connections (clients), 600000 total number of requests and 5000 bytes payload. The benchmark tests in this case set and get operations.

redis-benchmark -c 1000 -n 600000 -r 600000 -d 5000 -t set,get

Number of clients

Further information: Redis Clients Handling

Redis sets the maximum of clients to 100000 b default. To increase the maximum start the server with the argument --maxclients 100000. Linux limits the number of open files. To output the limit execute ulimit -n. Increase the limit of open files by:

ulimit -n 50000

(To increase the number of file you maybe have to set sudo sysctl -w fs.file-max=65536 as well. Get the current value by cat /proc/sys/fs/file-max.)

Tips

Monitor without default messages

redis-cli monitor | grep --line-buffered -Ev "PING|PONG|INFO|sentinel"

Sentinal: Figure out master name

In the sentinel.conf is entry like

sentinel monitor my-master 10.137.0.4 6379 2

The format is

sentinel monitor <master-name> <master-ip> <master-port> <failover-quorum>

Problems and errors

Misconf RDB snapshots

Error message
(error) MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error.
Solution
$ redis-cli
> config set stop-writes-on-bgsave-error no
OK

NOAUTH Authentication required

Error message
(error) NOAUTH Authentication required.
Solution
redis-cli
> auth <password>

External links