Redis is open source key-value data store.  If you are planning to use the new Consistent Region feature , you might use Redis as the checkpoint repository data store. This article will help you if you are not familiar with Redis and would like a guide how to get started quickly. There is another article how to submit consistent region application in Streams 4.0 with Redis, where you can tie everything together.

 

Streams 4.0 works with Redis version 2.8.17 and 2.8.19 (the latest version available in February 2015).

Main Redis website: http://redis.io/

Downloading and Installing :

To download, http://redis.io/download.

You don’t need root to download and install Redis, regular user is fine.

~/redis > ls redis-2.8.19.tar.gz

 

Uncompress it:

~/redis > tar zxvf redis-2.8.19.tar.gz

 

~/redis > ls redis-2.8.19  redis-2.8.19.tar.gz

 

~/redis > cd redis-2.8.19

 

~/redis/redis-2.8.19 > ls 00-RELEASENOTES  BUGS  CONTRIBUTING  COPYING  deps  INSTALL  Makefile  MANIFESTO  README  redis.conf  runtest  runtest-sentinel  sentinel.conf  src  tests  utils

 

Now let’s install Redis into a specific directory:

~/redis/redis-2.8.19 >  make PREFIX=~ivan/redis install

 

Let’s check the binaries were generated OK under ~/redis/bin directory.

~/redis > ls bin  redis-2.8.19  redis-2.8.19.tar.gz

 

~/redis > cd bin ivan@d0428b06:~/redis/bin > ls redis-benchmark  redis-check-aof  redis-check-dump  redis-cli  redis-sentinel  redis-server

 

Starting up Redis:

The simplest way if to start Redis with no parameters. It will use the default port 6379.

~/redis/bin > ./redis-server & [1] 3725 ivan@d0428b06:~/redis/bin > [3725] 09 Feb 09:15:19.265 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf _._ _.-“__ ”-._ _.-“¬†¬†¬† `.¬† `_.¬† ”-._¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† Redis 2.8.19 (00000000/0) 64 bit .-“ .-“`.¬† “`\/¬†¬†¬† _.,_ ”-._ (¬†¬†¬† ‘¬†¬†¬†¬†¬† ,¬†¬†¬†¬†¬†¬† .-`¬† | `,¬†¬†¬† )¬†¬†¬†¬† Running in stand alone mode |`-._`-…-` __…-.“-._|’` _.-‘|¬†¬†¬†¬† Port: 6379 |¬†¬†¬† `-._¬†¬† `._¬†¬†¬† /¬†¬†¬†¬† _.-‘¬†¬†¬† |¬†¬†¬†¬† PID: 3725 `-._¬†¬†¬† `-._¬† `-./¬† _.-‘¬†¬†¬† _.-‘ |`-._`-._¬†¬†¬† `-.__.-‘¬†¬†¬† _.-‘_.-‘| |¬†¬†¬† `-._`-._¬†¬†¬†¬†¬†¬†¬† _.-‘_.-‘¬†¬†¬† |¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† http://redis.io `-._¬†¬†¬† `-._`-.__.-‘_.-‘¬†¬†¬† _.-‘ |`-._`-._¬†¬†¬† `-.__.-‘¬†¬†¬† _.-‘_.-‘| |¬†¬†¬† `-._`-._¬†¬†¬†¬†¬†¬†¬† _.-‘_.-‘¬†¬†¬† | `-._¬†¬†¬† `-._`-.__.-‘_.-‘¬†¬†¬† _.-‘ `-._¬†¬†¬† `-.__.-‘¬†¬†¬† _.-‘ `-._¬†¬†¬†¬†¬†¬†¬† _.-‘ `-.__.-‘

 

[3725] 09 Feb 09:15:19.267 # Server started, Redis version 2.8.19 [3725] 09 Feb 09:15:19.267 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ‘vm.overcommit_memory = 1’ to /etc/sysctl.conf and then reboot or run the command ‘sysctl vm.overcommit_memory=1’ for this to take effect. [3725] 09 Feb 09:15:19.267 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command ‘echo never > /sys/kernel/mm/transparent_hugepage/enabled’ as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled. [3725] 09 Feb 09:15:19.267 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. [3725] 09 Feb 09:15:19.268 * DB loaded from disk: 0.001 seconds [3725] 09 Feb 09:15:19.268 * The server is now ready to accept connections on port 6379

 

If there is already a Redis (or another process) using the same port, you will see an error message like this.

[3738] 09 Feb 09:15:40.332 # Creating Server TCP listening socket *:6379: bind: Address already in use

 

To check if Redis is running:

1. ps -ef|grep redis

 

2. ~/redis/bin > ./redis-cli ping PONG

 

If not up it will say something like this:

./redis-cli ping Could not connect to Redis at 127.0.0.1:6379: Connection refused

 

To shutdown Redis:

ivan@d0428b06:~/redis/redis-2.8.19 > ps -ef|grep redis ivan    3725     1  0 09:15 ?        00:00:00 ./redis-server *:6379 ivan    3806  1010  0 09:17 pts/9    00:00:00 grep redis

 

~/redis/bin > ./redis-cli

 

127.0.0.1:6379> shutdown save

 

not connected>

 

not connected> quit ivan@d0428b06:~/redis/bin >

 

ivan@d0428b06:~/redis/bin > ps -ef|grep redis ivan    4231  1010  0 09:18 pts/9    00:00:00 grep redis

 

To start Redis on a port different than the default 6379.

:~/redis/bin > ./redis-server –port 6300 & [1] 4351 ivan@d0428b06:~/redis/bin >¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† _._ _.-“__ ”-._ _.-“¬†¬†¬† `.¬† `_.¬† ”-._¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† Redis 2.8.19 (00000000/0) 64 bit .-“ .-“`.¬† “`\/¬†¬†¬† _.,_ ”-._ (¬†¬†¬† ‘¬†¬†¬†¬†¬† ,¬†¬†¬†¬†¬†¬† .-`¬† | `,¬†¬†¬† )¬†¬†¬†¬† Running in stand alone mode |`-._`-…-` __…-.“-._|’` _.-‘|¬†¬†¬†¬† Port: 6300 |¬†¬†¬† `-._¬†¬† `._¬†¬†¬† /¬†¬†¬†¬† _.-‘¬†¬†¬† |¬†¬†¬†¬† PID: 4351 `-._¬†¬†¬† `-._¬† `-./¬† _.-‘¬†¬†¬† _.-‘ |`-._`-._¬†¬†¬† `-.__.-‘¬†¬†¬† _.-‘_.-‘| |¬†¬†¬† `-._`-._¬†¬†¬†¬†¬†¬†¬† _.-‘_.-‘¬†¬†¬† |¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† http://redis.io `-._¬†¬†¬† `-._`-.__.-‘_.-‘¬†¬†¬† _.-‘ |`-._`-._¬†¬†¬† `-.__.-‘¬†¬†¬† _.-‘_.-‘| |¬†¬†¬† `-._`-._¬†¬†¬†¬†¬†¬†¬† _.-‘_.-‘¬†¬†¬† | `-._¬†¬†¬† `-._`-.__.-‘_.-‘¬†¬†¬† _.-‘ `-._¬†¬†¬† `-.__.-‘¬†¬†¬† _.-‘ `-._¬†¬†¬†¬†¬†¬†¬† _.-‘ `-.__.-‘

 

[4351] 09 Feb 09:21:48.659 # Server started, Redis version 2.8.19 [4351] 09 Feb 09:21:48.659 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ‘vm.overcommit_memory = 1’ to /etc/sysctl.conf and then reboot or run the command ‘sysctl vm.overcommit_memory=1’ for this to take effect. [4351] 09 Feb 09:21:48.659 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command ‘echo never > /sys/kernel/mm/transparent_hugepage/enabled’ as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled. [4351] 09 Feb 09:21:48.659 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. [4351] 09 Feb 09:21:48.660 * DB loaded from disk: 0.000 seconds [4351] 09 Feb 09:21:48.660 * The server is now ready to accept connections on port 6300

 

To configure Redis:

All the examples so far were using the default config. In my tests, the default config worked fine for all the tests I did however, there might some need to change the Redis configuration.

To list all config parameters:

~/redis/bin > ./redis-cli -p 6300 127.0.0.1:6300> get conf

 

127.0.0.1:6300> config get *

 

¬† 1) “dbfilename” 2) “dump.rdb” 3) “requirepass” 4) “” 5) “masterauth” 6) “” 7) “unixsocket” 8) “” 9) “logfile” 10) “” 11) “pidfile” 12) “/var/run/redis.pid” 13) “maxmemory” 14) “0” 15) “maxmemory-samples” 16) “3” 17) “timeout” 18) “0” 19) “tcp-keepalive” 20) “0” 21) “auto-aof-rewrite-percentage” 22) “100” 23) “auto-aof-rewrite-min-size” 24) “67108864” 25) “hash-max-ziplist-entries” 26) “512” 27) “hash-max-ziplist-value” 28) “64” 29) “list-max-ziplist-entries” 30) “512” 31) “list-max-ziplist-value” 32) “64” 33) “set-max-intset-entries” 34) “512” 35) “zset-max-ziplist-entries” 36) “128” 37) “zset-max-ziplist-value” 38) “64” 39) “hll-sparse-max-bytes” 40) “3000” 41) “lua-time-limit” 42) “5000” 43) “slowlog-log-slower-than” 44) “10000” 45) “latency-monitor-threshold” 46) “0” 47) “slowlog-max-len” 48) “128” 49) “port” 50) “6300” 51) “tcp-backlog” 52) “511” 53) “databases” 54) “16” 55) “repl-ping-slave-period” 56) “10” 57) “repl-timeout” 58) “60” 59) “repl-backlog-size” 60) “1048576” 61) “repl-backlog-ttl” 62) “3600” 63) “maxclients” 64) “10000” 65) “watchdog-period” 66) “0” 67) “slave-priority” 68) “100” 69) “min-slaves-to-write” 70) “0” 71) “min-slaves-max-lag” 72) “10” 73) “hz” 74) “10” 75) “repl-diskless-sync-delay” 76) “5” 77) “no-appendfsync-on-rewrite” 78) “no” 79) “slave-serve-stale-data” 80) “yes” 81) “slave-read-only” 82) “yes” 83) “stop-writes-on-bgsave-error” 84) “yes” 85) “daemonize” 86) “no” 87) “rdbcompression” 88) “yes” 89) “rdbchecksum” 90) “yes” 91) “activerehashing” 92) “yes” 93) “repl-disable-tcp-nodelay” 94) “no” 95) “repl-diskless-sync” 96) “no” 97) “aof-rewrite-incremental-fsync” 98) “yes” 99) “aof-load-truncated” 100) “yes” 101) “appendonly” 102) “no” 103) “dir” 104) “/home/ivan/redis/bin” 105) “maxmemory-policy” 106) “volatile-lru” 107) “appendfsync” 108) “everysec” 109) “save” 110) “” 111) “loglevel” 112) “notice” 113) “client-output-buffer-limit” 114) “normal 0 0 0 slave 268435456 67108864 60 pubsub 33554432 8388608 60” 115) “unixsocketperm” 116) “0” 117) “slaveof” 118) “” 119) “notify-keyspace-events” 120) “” 121) “bind” 122) “”

 

To change a Redis parameter:

127.0.0.1:6300> config set tcp-keepalive 3600 OK

 

However, this will not change the redis.conf file.I suggest always using redis.conf. Please see below.

I suggest using the redis.conf configuration file when starting up Redis.

This way you have all your parameters documented and you dont depend on starting Redis with a bunch of different option in the initial redis-server command.

Edit redis.conf. I updated:

logfile “/home/ivan/redis/bin/redis.log”

port 6400

Then you start Redis like this:

~/redis/bin > ./redis-server ./redis.conf & [1] 5469

 

You can then check the redis.log file.

 

~/redis/bin > tail redis.log

 

¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† _._ _.-“__ ”-._ _.-“¬†¬†¬† `.¬† `_.¬† ”-._¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† Redis 2.8.19 (00000000/0) 64 bit .-“ .-“`.¬† “`\/¬†¬†¬† _.,_ ”-._ (¬†¬†¬† ‘¬†¬†¬†¬†¬† ,¬†¬†¬†¬†¬†¬† .-`¬† | `,¬†¬†¬† )¬†¬†¬†¬† Running in stand alone mode |`-._`-…-` __…-.“-._|’` _.-‘|¬†¬†¬†¬† Port: 6400 |¬†¬†¬† `-._¬†¬† `._¬†¬†¬† /¬†¬†¬†¬† _.-‘¬†¬†¬† |¬†¬†¬†¬† PID: 5469 `-._¬†¬†¬† `-._¬† `-./¬† _.-‘¬†¬†¬† _.-‘ |`-._`-._¬†¬†¬† `-.__.-‘¬†¬†¬† _.-‘_.-‘| |¬†¬†¬† `-._`-._¬†¬†¬†¬†¬†¬†¬† _.-‘_.-‘¬†¬†¬† |¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† http://redis.io `-._¬†¬†¬† `-._`-.__.-‘_.-‘¬†¬†¬† _.-‘ |`-._`-._¬†¬†¬† `-.__.-‘¬†¬†¬† _.-‘_.-‘| |¬†¬†¬† `-._`-._¬†¬†¬†¬†¬†¬†¬† _.-‘_.-‘¬†¬†¬† | `-._¬†¬†¬† `-._`-.__.-‘_.-‘¬†¬†¬† _.-‘ `-._¬†¬†¬† `-.__.-‘¬†¬†¬† _.-‘ `-._¬†¬†¬†¬†¬†¬†¬† _.-‘ `-.__.-‘

 

[5469] 09 Feb 09:41:32.244 # Server started, Redis version 2.8.19 [5469] 09 Feb 09:41:32.245 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ‘vm.overcommit_memory = 1’ to /etc/sysctl.conf and then reboot or run the command ‘sysctl vm.overcommit_memory=1’ for this to take effect. [5469] 09 Feb 09:41:32.247 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command ‘echo never > /sys/kernel/mm/transparent_hugepage/enabled’ as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled. [5469] 09 Feb 09:41:32.248 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. [5469] 09 Feb 09:41:32.250 * DB loaded from disk: 0.001 seconds [5469] 09 Feb 09:41:32.251 * The server is now ready to accept connections on port 6400

 

Join The Discussion