Last active
January 16, 2022 09:46
-
-
Save ajeetraina/6891f1562b09182eabf16d8650ca5e4f to your computer and use it in GitHub Desktop.
Getting Started with Redis using Docker Container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
# 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 | |
reids-cli | |
# Access the keys | |
- Create a generic key like set a1 100 and get a1 100 | |
# Importing user keys | |
Let us import a user database( 6k keys). This dataset contains users stored as Redis Hash. | |
Users | |
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HMGET user:3333 first_name last_name city