Ajeet Raina I am a Docker Captain, ARM Innovator & Docker Bangalore Community Leader. I am a maintainer of Collabnix blogging site. I work for Docker as a full-time employee. I run Collabnix Community Slack with over 6500+ audience . We have built a popular projects like Docker Labs, KubeLabs, KubeTools and DockerTools. You can follow me on Twitter(@ajeetsraina) & GitHub(@ajeetraina)

How to setup and run Redis in a Docker Container

1 min read

Redis stands for REmote DIctionary Server. It is an open source, fast NoSQL database written in ANSI C and optimized for speed. Redis is an in-memory database that means that all data in Redis is stored in RAM, delivering the fastest possible access times to the data for both read and write requests.

Redis  is designed and implemented for performance. Redis compiles into extremely efficient machine code and requires little overhead. It uses a (mostly) single threaded event loop model that optimally utilizes the CPU core that it is running on. The data structures used internally by Redis are implemented for maximum performance and the majority of data operations require constant time and space.

Redis is based on the key-value model. In Redis, the data is stored and fetched from Redis by key. Keybased access allows for extremely efficient access times and this model maps naturally to caching, with Redis providing the customary GET and SET semantics for interacting with the data. Also, it supports multi-key operations. Several of Redis’ commands operate on multiple keys. Multi-key operations provide better overall performance compared to performing the operations one after the other, because they require substantially less communication and administration.

Redis is designed to be a remote, network-attached server. It uses a lightweight TCP protocol that has client implementations in every conceivable programming language. Redis is basically an open source, in-memory, data structure store that can be used as a cache, primary database and message broker. It is a multi-model database that supports search, graph, real-time streaming, analytics and many other use cases beyond that of a simple data store. With over 52,000+ GitHub stars, 20,000+ forks and over 500+ contributors, Redis is quite popular among the developers. Redis gives developers building applications the tools and information they need in a very efficient manner. Redis today can be deployed on-premises, across clouds, hybrid environments as well as over the Edge devices flawlessly.

Here’s a quickstart guide to get Redis running in a Docker container:

Ensure that Docker is installed

docker -v

Create a dedicated Docker network

docker network create -d bridge redisnet

Run Redis container

docker run -d -p 6379:6379 --name myredis --network redisnet redis

Install redis-cli

brew install redis-cli

Enter into Redis-cli

redis-cli

Accessing the keys

  • Create a generic key like set a1 100 and get a1 100
set a1 100
get a1

Importing user keys

Let us import a user database( 6k keys). This dataset contains users stored as Redis Hash.

The user hashes contain the following fields:

user:id : The key of the hash.
first_name : First Name.
last_name : Last name.
email : email address.
gender : Gender (male/female).
ip_address : IP address.
country : Country Name.
country_code : Country Code.
city : City of the user.
longitude : Longitude of the user.
latitude : Latitude of the user.
last_login : EPOC time of the last login.

Cloning the repository

git clone https://github.com/redis-developer/redis-datasets
cd redis-datasets/user-database

Importing the user database:

redis-cli -h localhost -p 6379 < ./import_users.redis

Open a new terminal and run the monitor CLI

monitor

Flushing up the database

flushdb

Cleaning up container

docker stop myredis

Further References

Have Queries? Join https://launchpass.com/collabnix

Ajeet Raina I am a Docker Captain, ARM Innovator & Docker Bangalore Community Leader. I am a maintainer of Collabnix blogging site. I work for Docker as a full-time employee. I run Collabnix Community Slack with over 6500+ audience . We have built a popular projects like Docker Labs, KubeLabs, KubeTools and DockerTools. You can follow me on Twitter(@ajeetsraina) & GitHub(@ajeetraina)

What is a Dockerfile – A Step-By-Step Guide

A Dockerfile is a text file which contains a series of commands or instructions. These instructions are executed in the order in which they...
Ajeet Raina
21 min read

Docker Desktop for Linux,  Docker Extensions and more with…

Docker Desktop 4.8.2 is now available for download for Mac, Windows and Linux. Here are the major highlights: Docker Desktop for various Linux distributions made available for the first...
Ajeet Raina
1 min read

One Reply to “How to setup and run Redis in a Docker…”

  1. How Docker Container Works?

    Docker has become the de facto standard in container-based implementation. Docker is an open-source platform, written in GO language, developed by DotCloud and used by developers to build, deploy and run applications. With Docker, one can easily separate their applications from the infrastructure for the fast delivery of the project. It enables developers to package and run the application in a loosely remote environment called a container. The isolation that Docker provides allows developers to run several containers at the same time on a given host.

Leave a Reply