How to install and setup Redis
We aggregate and tag open source projects. We have collections of more than one million projects. Check out the projects section.
Redis is an open source (BSD licensed), in-memory data structure store, used also as a database cache and message broker.
It is written in ANSI C and works in all the operating systems. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams. This article explains about how to install Redis.
To install in Linux environment, download the tar ball and compile it. The instructions are available here.
To install in Windows, the redis package can be downloaded from the following links
Once you install, you will find following binaries in the installed location.
- 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.
Start the server
Connect to the server and check if it is responding.
redis-cli ping // uses default localhost and redis port 6379
redis-cli -h hostname -p port ping
How to install and setup Redis Cluster
Redis cluster can be setup very easily in the recent version of redis 5. We need to create redis.conf for each node with following minimal configuration and start each node. In the below configuration, change port number for each instance.
Alternatively you can use Redis CLI to create cluster. Following command will create 6 nodes of 3 master and 3 slaves.
redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 \
127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 \
Now the cluster is created, Connect to any node and then type cluster nodes, it will print all the details of this cluster.
$ ./redis-cli -c -p 7000
127.0.0.1:7000> cluster nodes
38fbbd9d1963ff5708d64d74b9e2f7acf2153a3b 127.0.0.1:7004@17004 slave f734244f4ff3c6e13dfd2699e587982eea3517e3 0 1550414464000 5 connected
60225952df928acdae4cb8576018ddbbeb5bb954 127.0.0.1:7005@17005 master - 0 1550414463540 9 connected 0-5460
d517512c6169882a9614510aa2342470e921db20 127.0.0.1:7001@17001 slave a7fa72c6fc086a474fde0765fe96ca081c66b827 0 1550414464000 8 connected
a7fa72c6fc086a474fde0765fe96ca081c66b827 127.0.0.1:7003@17003 master - 0 1550414463840 8 connected 5461-10922
f734244f4ff3c6e13dfd2699e587982eea3517e3 127.0.0.1:7002@17002 master - 0 1550414464843 3 connected 10923-16383
5ffc6d5c8858d6eedded019519c69834f53305ad 127.0.0.1:7000@17000 myself,slave 60225952df928acdae4cb8576018ddbbeb5bb954 0 1550414463000 1 connected
Redis server communicated with protocol called RESP (Redis Serialization Protocol). It connects to server using TCP connections and work with request and response model. There are many clients available for each language to connect and work with redis.