Introduction to Redis

Downloading

For Linux

$ wget https://github.com/antirez/redis/archive/3.2.0-rc3.tar.gz 
   

For MacOS

Save https://github.com/antirez/redis/archive/3.2.0-rc3.tar.gz to your Downloads directory. Open a terminal and copy the file to a working directory

Installing

$ tar xzf redis-3.2.0-rc3.tar.gz
$ cd redis-3.2.0-rc3
$ make
   

For Microsoft Windows

Redis does not have an official version for Microsoft Windows. Microsoft Open Tech group does provide a supported and actively developed port for Windows 64-bit systems. Download https://github.com/MSOpenTech/redis/releases/download/win-3.0.501/Redis-x64-3.0.501.zip and then extract the contents of the zip file to a local directory.

Exercise: Starting and Stopping Redis

Starting Redis

$ cd redis-3.2.0-rc3/src
$ ./redis-server
6602:C 17 Apr 20:08:27.565 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
6602:M 17 Apr 20:08:27.567 * Increased maximum number of open files to 10032 (it was originally set to 256).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.1.103 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 6602
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

6602:M 17 Apr 20:08:27.572 # Server started, Redis version 3.1.103
6602:M 17 Apr 20:08:27.572 * The server is now ready to accept connections on port 6379
       
Windows:
C:\ cd C:\RedisTraining\
C:\RedisTraining\redis-server.exe
      

Stopping Redis

To stop a running instance of Redis server, use the ctrl-t key combination to halt the process.


Redis Command Line Client redis-cli

Redis comes with a command-line client that should be in the same directory as the redis-server. We will use redis-cli to send commands to the server, load data, and explore the functionality of Redis.

Exercise: Running redis-cli

Restart redis-server in a terminal. Open a new command-line terminal and enter the following commands:

$ cd redis-3.2.0-rc3/src
$ ./redis-cli
127.0.0.1:6379>
    

The redis-cli prompt first shows the IP address the client is connected to (in this case localhost) and the port number of 6379. You can change the server hostname and port number by appending -h {host-name} to change the host name and -p {port-number} to change the port number.

Exercise: First Redis Commands with redis-cli

With a running redis-cli instance, we will issue some basic informational commands to Redis server.

The PING command simple checks to see if the Redis server is live.

127.0.0.1:6379> PING
PONG
   

To see the total number of keys in the Redis datastore, use the DBSIZE command

127.0.0.1:6379> DBSIZE
(integer) 0

Getting Help and Participating in the Redis Community

A robust and thriving community has grown around Redis, including a yearly conference, RedisConf, social media, and traditional email mailing list and IRC channel. An important social-media source for Redis news is the Redis News Twitter feed at https://twitter.com/redisfeed and the Redis sub-Reddit at https://www.reddit.com/r/redis. These various communication channels provide multiple avenues to engage with other individuals who are actively developing and using Redis in diverse industries and environments.

The first place to look for help is on Redis's website, http://redis.io/, that has a rich trove of documentation and tutorials as well as the latest downloads for the current stable version of Redis, along with the cutting-edge development version and links to older versions of Redis. The website also lists all the various Redis clients for the most popular (and not so popular) programming languages and frameworks. These clients make it easy to use Redis as connection layer between systems that may have very different implementations and technology stacks.