Chapter 8. Redis: A Key/Value Store

In this chapter, we’ll look at the support Spring Data offers for the key/value store Redis. We’ll briefly look at how Redis manages data, show how to install and configure the server, and touch on how to interact with it from the command line. Then we’ll look at how to connect to the server from Java and how the RedisTemplate organizes the multitude of operations we can perform on data stored in Redis. We’ll look at ways to store POJOs using JSON, and we’ll also briefly discuss how to use the fast and efficient pub/sub (publish/subscribe) capability to do basic event-based programming.

Redis in a Nutshell

Redis is an extremely high-performance, lightweight data store. It provides key/value data access to persistent byte arrays, lists, sets, and hash data structures. It supports atomic counters and also has an efficient topic-based pub/sub messaging functionality. Redis is simple to install and run and is, above all, very, very fast at data access. What it lacks in complex querying functionality (like that found in Riak or MongoDB), it makes up for in speed and efficiency. Redis servers can also be clustered together to provide for very flexible deployment. It’s easy to interact with Redis from the command line using the redis-cli binary that comes with the installation.

Setting Up Redis

To start working with Redis, you’ll want to have a local installation. Depending on your platform, the installation process ranges from easy to literally one command. ...

Get Spring Data now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.