Fundamentals of Redis for Caching — All You Need to Know as a Developer

Learn the most common use cases of Redis

Lynn Kwong
14 min readAug 22, 2021

--

Redis, which stands for Remote Dictionary Server, is an open-source in-memory data structure store that can be used as an in-memory key-value database, caching system, and pub/sub message broker. Redis is special in that all its data is stored in memory rather than on disk which makes it extremely fast and is a popular option for caching.

Photo by Tyler Clemmensen on Unsplash.

Redis is similar to Memcached, which as the name indicates is also an in-memory key-value data storage. However, Redis has more advanced features which makes it applicable to more scenarios. Unlike Memcached which only supports strings, Redis supports a variety of data structures including lists, sets, sorted sets, hashes, etc. Besides, Redis also supports snapshots, transactions, pub/sub, etc.

To start using Redis, you need a Redis server. For learning purposes, you can install Redis on your local machine or use a Docker container. For production purposes, you need to install Redis on a dedicated server or use third-party hosted Redis servers, such as GCP Memorystore for Redis or Amazon ElastiCache.

In this tutorial, we will install Redis on our local machine. If you are using Ubuntu, you can install Redis in this way:

$ sudo apt-get update 
$ sudo apt-get install redis-server

The version of Redis installed in this way may not be the latest version. If you want to install the latest stable version of Redis, you can follow the instructions on the Redis official site:

$ wget http://download.redis.io/redis-stable.tar.gz
$ tar xvzf redis-stable.tar.gz
$ cd redis-stable
$ make
$ sudo make install

After Redis is installed, you can start the server with the redis-server command directly. If port 6379 is used by another process, you can specify a different one, for example:

$ redis-server --port 16379

To interact with the Redis server, we can use redis-cli which is also installed in the package:

$ redis-cli# If the port is set to something other than 6379:
$ redis-cli -p 16379

--

--

Lynn Kwong

I’m a Software Developer (https://superdataminer.com) keen on sharing thoughts, tutorials, and solutions for the best practice of software development.