- Clone the repository
- Run
docker compose up -d - Run
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' redis-node-1to get the IP address of the first node - Repeat the previous step for the other nodes
Run docker exec -it redis-node-1 redis-cli --cluster create <ip1>:6379 <ip2>:6379 <ip3>:6379 <ip4>:6379 <ip5>:6379 <ip6>:6379 --cluster-replicas 1
- Run
docker exec -it redis-node-1 redis-cli -cto connect to the first node - Run
cluster infoto get information about the cluster - Run
cluster nodesto get information about the nodes
- Run
set key valueto set a key - Run
get keyto get the value of the key - Run
keys *to get all the keys - Run
del keyto delete a key - Run
flushallto delete all keys - Run
exitto exit the redis-cli
Create a key in one node and try to get it from another node. You will see that the key is available in all nodes.
- Run
hset user:1 name "John Doe"to set a hash - Run
hget user:1 nameto get the value of the hash - Run
hgetall user:1to get all the values of the hash - Run
hmset user:1 name "John Doe" age 30to set multiple values in a hash - Run
hmget user:1 name ageto get multiple values of the hash - Run
hdel user:1 ageto delete a value of the hash
- Run
lpush list 1 2 3 4 5to create a list - Run
lrange list 0 -1to get all the values of the list - Run
lpop listto remove the first element of the list - Run
rpop listto remove the last element of the list - Run
ltrim list 0 2to remove all elements of the list except the first three
- Run
sadd set 1 2 3 4 5to create a set - Run
smembers setto get all the values of the set - Run
srem set 1to remove a value of the set
- Run
zadd sorted-set 1 one 2 two 3 three 4 four 5 fiveto create a sorted set - Run
zrange sorted-set 0 -1to get all the values of the sorted set - Run
zrange sorted-set 0 -1 withscoresto get all the values of the sorted set with the scores - Run
zrem sorted-set oneto remove a value of the sorted set
- Run
set key valueto set a key - Run
expire key 10to set the key to expire in 10 seconds - Run
ttl keyto get the time to live of the key Wait 10 seconds and runget keyto see that the key is no longer available - Run
setex key 10 valueto set a key with an expiration time
In this repository, you have a index.py file that shows how to connect to the Redis cluster using the redis library.
Run docker compose --profile testing up -d to start the testing environment, it will add a new container that will run the index.py
file.
See the logs of the container to see the output of the script using docker logs -f python-project.
I have this project https://github.com/Ayfri/UF_Project_B3 which is my end of year project for my third year at Ynov.
We have to make BigQuery requests to get data of GDELT project and then use this data to make predictions.
But each request takes a lot of time, around 30 seconds, so I thought about using Redis to cache the results of the requests.
So in this commit : 3c8aa9 I added a Redis instance in a Docker container and I used it to cache the results of the requests.
I used the redis library to connect to the Redis instance and I used the set and get methods to cache the results, also using JSON
serialization to store complex data.
Redis is great for caching and simple key-value storage thanks to its speed, scalability, and ease of use.
- Blazingly fast thanks to in-memory data storage and efficient data structures.
- Highly scalable with sharding and replication strategies.
- Simple data model and minimalistic commands make it easy to learn and integrate.
- Excellent for caching to improve application performance.
- Rich set of data structures like strings, hashes, lists, sets, etc.
- Data persistence requires configuration and can be challenging for high-write scenarios.
- Limited query capabilities compared to traditional databases or data warehouses.
- Memory usage can grow quickly with large datasets or memory-intensive data structures.
- Not well-suited for complex relational data or join operations.
- Limited transaction support may not meet strong consistency requirements.
I actually use Redis Stack Server in a private project for storing a large amount of complex data, and it works
perfectly.
It also gives us RedisSearch and RedisTimeSeries modules that we use for more advanced data management and querying.
Before that, we were using local files, and that was a mess to manage and query. Redis was much faster.
One good tool present in the Redis environment is Redis Insight, a graphical user interface that gives Redis users a powerful way to visualize and interact with their data. Redis Insight allows viewing databases, querying keys and values, and executing common Redis commands through an intuitive interface. It also integrates tightly with Redis, enabling real-time monitoring and command inspection capabilities.
While Redis has limitations, it shines for use cases like caching, session management, real-time messaging, and scenarios needing high-performance data access with simple data structures. For more complex requirements, it's often combined with other solutions or Redis Stack Server for enhanced data management and querying capabilities.