Pivotal Knowledge Base


How to install and use Redis on Linux


Product Version
Redis 3.0.1 and above
Ubuntu  14.04


Users can easily install Redis on Linux and start running Redis commands using redis-cli client.

In short, Redis is a high-performance in-memory NoSQL key-value database cache but persistent data on disk and highly scalable. By default, Redis saves snapshots of the dataset on disk in a binary file called dump.rdb at predefined intervals so any changes between these intervals will be lost when the server crashed. 

See Introduction to Redis: http://redis.io/topics/introduction


For this demo setup, we are using Ubuntu 14.04 and the latest stable Redis version 3.0.1 available on http://download.redis.io

1)  Download, build and install Redis server on ubuntu
> cd /usr/src
> wget -c http://download.redis.io/redis-stable.tar.gz
> tar xvzf redis-stable.tar.gz
> cd redis-stable
> make && make install

2)  Install the Redis script
> utils/install_server.sh

Welcome to the Redis service installer
This script will help you easily set up a running Redis server

Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] /etc/redis/redis_6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port           : 6379
Config file    : /etc/redis/redis_6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
 Adding system startup for /etc/init.d/redis_6379 ...
   /etc/rc0.d/K20redis_6379 -> ../init.d/redis_6379
   /etc/rc1.d/K20redis_6379 -> ../init.d/redis_6379
   /etc/rc6.d/K20redis_6379 -> ../init.d/redis_6379
   /etc/rc2.d/S20redis_6379 -> ../init.d/redis_6379
   /etc/rc3.d/S20redis_6379 -> ../init.d/redis_6379
   /etc/rc4.d/S20redis_6379 -> ../init.d/redis_6379
   /etc/rc5.d/S20redis_6379 -> ../init.d/redis_6379
Starting Redis server...
Installation successful!

3) Check and test to make make sure Redis server is running and working
> /etc/init.d/redis_6379 status
Redis is running (27186)

> redis-cli -p 6379 info server
# Server
os:Linux 3.13.0-52-generic x86_64

Run Redis commands using redis-cli client

> redis-cli

  • Set multiple hash fields to multiple values

hmset user:1  name kymeng email klim@pivotal.io phone 1234567

  • Get all of the fields and values in a hash

 hgetall user:1
1) "name"
2) "kymeng"
3) "email"
4) "klim@pivotal.io"
5) "phone"
6) "1234567"

  • Get the values of all the given hash fields

hmget user:1 name email phone
1) "kymeng"
2) "klim@pivotal.io"
3) "1234567"

  • Get the value of hash field

hget user:1 email

  • Find all keys matching the given pattern

keys *
1) "user:1"

  • Get all of the fields and values in a hash

hgetall user:1
1) "username"
2) "kymeng"
3) "email"
4) "klim@pivotal.io"

  • Get the value of a configuration parameter

config get *
 1) "dbfilename"
  2) "dump.rdb"
  3) "requirepass"
  4) ""
  5) "masterauth"
  6) ""
  7) "unixsocket"

  • Remove all keys from the current database


  • Set the string value of a key

set server:redis version:3.0.1

  • Find all keys matching the given pattern

keys *
1) "server:redis"

  • Get the value of a key

get server:redis

  • Synchronously save the dataset to disk and then shut down the server

shutdown save
not connected>

Additional information

  • For complete list of Redis commands, see http://redis.io/commands
  • For more Redis tutorials, see http://www.tutorialspoint.com/redis/index.htm

Also, check out these other How-to articles

  • How to setup Redis Session Manager on tcServer/Tomcat
  • How to setup and run multiple Redis server instances on a Linux host
  • How to setup Redis Master and Slave replication
  • How to setup Redis Sentinel and HAProxy to provide automatic failover between Redis Master and Slave servers.


  • Avatar
    Krishna Gangaraju

    very helpfull, can we define dependencies in redis installer ? like gcc need to installed first etc

Powered by Zendesk