Redis stands for REmote DIctionary Server. It is a fast, open-source NoSQL database written in ANSI C and optimized for speed. Redis is an in-memory database, which means that all Redis data is stored in RAM, offering the fastest possible data access times for 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 on which it is running. The data structures used internally by Redis are implemented for maximum performance and most data operations require constant time and space.
Redis is based on the key-value model. In Redis, data is stored and obtained from Redis by key. Key-based access allows for extremely efficient access times and this model naturally maps to caching, with Redis providing the usual GET and SET semantics for interacting with data. In addition, it supports multi-key operations. Several of Redis’ commands operate on multiple keys. Multi-key operations provide better overall performance compared to performing operations one after the other, as they require substantially less communication and management.
Redis is designed to be a remote server connected to the network. It uses a lightweight TCP protocol that has client implementations in every programming language imaginable. 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, graphs, real-time streaming, analysis, and many other use cases beyond a simple data warehouse. With over 52,000+ GitHub stars, 20,000+ forks, and over 500+ contributors, Redis is quite popular with developers. Redis gives developers building applications the tools and information they need in a very efficient way. Redis today can be deployed on-premises, in clouds, hybrid environments, and on edge devices seamlessly.
Here’s a quick start guide for
Redis to run in a Docker container: Make sure 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 Redis-cli
Redis-cli Access
to keys
- Create a generic key as
set a1 100 and get a1 100
set a1 100 get a1
Importing user keys
Let’s import a user database (6k keys). This dataset contains users stored as Redis Hash.
User hashes contain the following fields
: user:id : The key of the hash. first_name : Name. last_name : Surname. Email: Email address. Gender : Gender (male/female). ip_address : IP address. country : Name of the country. country_code : Country code. city : City of the user. Length : Length of the user. Latitude : Latitude of the user. last_login : EPOC time of the last login.
Cloning
the git repository clone https://github.com/redis-developer/redis-datasets cd redis-datasets/user-database User database import: redis-cli -h localhost -p 6379 < ./import_users.redis
Open a new terminal and run the monitor CLI monitor
Flushing the
flushdb database
Cleaning the
Docker container Stop Myredis
Other references
Redis
- Developer Hub
- Redis on Kubernetes Redis on AWS