Redis is a high-performance, in-memory, key-value store with persistence. It's a great alternative to memcached for caching, with the additional functionality of a NoSQL data store. Here, we will learn how to add Redis to our application and set it up to be used as a cache.
We'll first set up a Redis server on our development machine using the following steps:
Let's start by installing Redis.
On OS X, we can use Homebrew to install Redis with the following command:
$ brew install redis
For Ubuntu, we can use
apt-get
:$ sudo apt-get update $ sudo apt-get install redis-server
For other operating systems, we can get installation instructions from the Redis website (http://redis.io/download).
Once installed, we can verify that our installation is working by trying out a couple of commands. Redis comes with a command-line program,
redis-cli
.Let's start it up and try setting and getting a key/value pair:
$ redis-cli $ set testing 123 OK $ get testing...