Redis using Spring Data – Part 1/3

Before we start
In this blog, you will learn how to install a NoSQL database Redis. You will also learn about starting redis-server, using redis-cli.

In the upcoming series of this article, we will create a demo java application using spring-data-redis exploring various data structures supported by the redis and also go through publish subscribe messaging with Redis PubSub. I will also show you about the replication setup for Redis server.

Installing Redis
The official stable version of redis can be installed for unix like system only. Download, extract and compile Redis with following commands on the terminal:$ wget http://redis.googlecode.com/files/redis-2.6.14.tar.gz
$ tar xzf redis-2.6.14.tar.gz
$ cd redis-2.6.14
$ make

Redis is now installed. Now run the redis using the command :
$ ./src/redis-server

By default, redis run on port 6379. Port can be configured in /redis.conf. Your terminal screen should have message like:

A two-minute introduction to Redis data types using redis-cli
Any binary sequence can be used as the redis key, from string to jpeg content. Redis support following data types for value:
Redis command line interface can be started on the terminal by the command:src/redis-cli

String type

This is the simplest data type. The simple string key/value data can be saved and retrieved as on redis-cli as :$ set author.name "Omanand Jha Vatsa"
OK
$ get author.name
"Omanand Jha Vatsa"

List type

Redis lists are ordered collection implemented using linked list. Adding an element to the head or tail of the list is performed in the constant time.The LPUSH command adds a new element into a list, on the left (at the head), while the RPUSH command adds a new element into a list, on the right (at the tail). Finally the LRANGE command extracts ranges of elements from lists:
$ rpush scores 30
(integer) 1
$ rpush scores 40
(integer) 2
$ rpush scores 50
(integer) 3
$ lrange scores 0 2
1) "30"
2) "40"
3) "50"
$ lrange scores -3 -1
1) "30"
2) "40"
3) "50"