Redis Install
Redis In-Memory Datastore
Ref : http://redis.io/topics/quickstart
The suggested way of installing Redis is compiling it from sources as Redis has no dependencies other than a working GCC compiler and libc. Installing it using the package manager of Linux distribution is somewhat discouraged as usually the available version is not the latest.
In later section, we'll installed it from the package.
We can either download the latest Redis tar ball from the redis.io web site, or we can alternatively use the latest stable Redis version (http://download.redis.io/redis-stable.tar.gz).
Let's compile Redis:
$ wget http://download.redis.io/redis-stable.tar.gz $ tar xvzf redis-stable.tar.gz $ cd redis-stable $ cd deps $ make make hiredis lua jemalloc linenoise geohash-int $ cd .. $ make
- redis-server is the Redis Server itself.
- redis-sentinel is the Redis Sentinel executable (monitoring and failover).
- redis-cli is the command line interface utility to talk with Redis.
- redis-benchmark is used to check Redis performances.
- redis-check-aof and redis-check-dump are useful in the rare event of corrupted data files.
Now let's copy both the Redis server and the command line interface in proper places. Assuming we are under redis-stable folder:
$ sudo cp src/redis-server /usr/local/bin/ $ sudo cp src/redis-cli /usr/local/bin/
Or:
$ sudo make install
Let's start Redis:
$ redis-server ... _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 3.2.0 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 29527 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' ... * The server is now ready to accept connections on port 6379
Note that the Redis was started without any explicit configuration file, so all the parameters will use the internal default.
In order to start Redis with a configuration file use the full path of the configuration file as first argument, like in the following example:
$ redis-server /etc/redis/redis.conf
We should use the redis.conf file included in the root directory of the Redis source code distribution as a template to write our configuration file.
To check the version of redis-server:
$ redis-server -v Redis server v=3.2.0 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=64a83e644b56d194
Restart the redis-server:
$ sudo /etc/init.d/redis-server restart
Redis provides a command line utility that can be used to send commands to Redis. This program is called redis-cli.
We can use the redis-cli to check if Redis is working properly by sending a PING command:
$ redis-cli ping PONG
Another usage of the redis-cli (without args) is to start in interactive mode, we can type different commands and see their replies.
$ redis-cli 127.0.0.1:6379> ping PONG 127.0.0.1:6379> set mykey 1234 OK 127.0.0.1:6379> get mykey "1234" 127.0.0.1:6379>
Picture credit : RedisLabs
Check http://redis.io/topics/data-types-intro
By default, if we start Redis with the default configuration, Redis will spontaneously save the dataset only from time to time (for instance after at least five minutes if we have at least 100 changes in our data).
So, if we want our database to persist and be reloaded after a restart, we should make sure to call the SAVE command manually every time we want to force a data set snapshot.
Otherwise make sure to shutdown the database using the SHUTDOWN command to save the data on disk before quitting:
$ redis-cli shutdown
Redis is an in-memory but persistent on disk database, so it represents a different trade off where very high write and read speed is achieved with the limitation of data sets that can't be larger than memory.
Another advantage of in memory databases is that the memory representation of complex data structures is much simpler to manipulate compared to the same data structure on disk, so Redis can do a lot, with little internal complexity.
We may need to enable auto-restart Redis so that after a restart everything will start again properly.
We've already copied redis-server and redis-cli executables under /usr/local/bin.
Here are the steps:
- Create a directory where to store our Redis config files and our data:
$ sudo mkdir -p /etc/redis $ sudo mkdir -p /var/redis
- Copy the init script in the Redis distribution under the utils directory into /etc/init.d with a port name we're going to use:
$ sudo cp utils/redis_init_script /etc/init.d/redis_6379
- Make sure to modify REDISPORT accordingly to the port we are using. Both the pid file path and the configuration file name depend on the port number:
REDISPORT=6379
- Copy the template configuration file in the root directory of the Redis distribution into /etc/redis/ using the port number as name:
$ sudo cp redis.conf /etc/redis/6379.conf
- Create a directory inside /var/redis that will work as data and working directory for this Redis instance:
$ sudo mkdir -p /var/redis/6379
- Since we made changes in previous steps, we need to edit the configuration file (/etc/redis/6379.conf) and make the following changes accordingly:
- Set daemonize to yes (by default it is set to no).
- Set the pidfile to /var/run/redis_6379.pid (modify the port if needed).
- Change the port accordingly. (default port : 6379).
- Set preferred loglevel.
- Set the logfile to /var/log/redis_6379.log
- Set the dir to /var/redis/6379 (very important step!)
- Finally add the new Redis init script to all the default runlevels using the following command:
$ sudo update-rc.d redis_6379 defaults
Now, we're ready. Let's run our instance with:
$ sudo /etc/init.d/redis_6379 start Starting Redis server...
We're done!
The following section is optional and we may want to skip it.
It's for installing Redis from package distribution.
In the previous sections, we downloaded the latest and configured Redis following the official guide, but in this section, we'll install it from the package, and the version could well be not the latest:
$ sudo apt-get update $ sudo apt-get install redis-server
Then, we can start it:
$ redis-server [3796] 09 May 10:03:08.436 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf [3796] 09 May 10:03:08.437 # Unable to set the max number of files limit to 10032 (Operation not permitted), setting the max clients configuration to 3984. _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 2.8.4 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in stand alone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 3796 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' [3796] 09 May 10:03:08.438 # Server started, Redis version 2.8.4 [3796] 09 May 10:03:08.438 # 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. [3796] 09 May 10:03:08.438 * DB loaded from disk: 0.000 seconds [3796] 09 May 10:03:08.438 * The server is now ready to accept connections on port 6379
We can check if redis is working:
$ redis-cli 127.0.0.1:6379>
In the above prompt 6379 is the port on which redis server is running. Now type the PING command as shown below:
127.0.0.1:6379> ping PONG 127.0.0.1:6379>
$ sudo dpkg -i redis-desktop-manager_0.7.6.8_amd64_ubuntu.deb
Run the Redis Desktop Manager:
Redis In-Memory Datastore
Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization