- In-memory data structure store, used as a database, cache and message broker.
- Key / value database.
- Different levels of on-disk persistence.
- Not just a cache.
- Multiple datatypes.
- Pub-sub model.
- Cluster mode for high availability.
- Perfectly works in cloud: AWS Elasticache, Azure Redis Cache and Memorystore (Google Cloud).
Remember you need in our local:
# redis
# redis-cli
# npm / nodejs
# install dependencies
npm install
- Redis instance has 16 databases, DONT NEED PREFIX IN KEYS
redis-cli -n {database_number}
- Debugging from cli
redis-cli monitor
- Main commands: KEYS / DEBUG / SCAN / TYPE / EXPIRATE
- Basic data type
- Main commands: set / get
node examples/datatypes/string.js
- Arrays of strings
- Main commands : lpush / lrange / lpop
node examples/datatypes/list.js
- Unique and unordered collection of strings
- Main commands: sadd / smember / srem / sscan
node examples/datatypes/set.js
- Maps between string fields and string values
- Perfect data type to represent objects
- Main commands: hset / hmset / hget / hgetall / hscan
node examples/datatypes/hash.js
- Similarly to Redis Sets, non repeating collections of Strings.
- Every member of a Sorted Set is associated with score
- Main commands: zadd / zrangebyscore
node examples/datatypes/sorted-set.js
- New data type from Redis 5
- Goal handle large amount of data (example: chat history, logs, etc)
- Main commands: xadd / xread
node examples/datatypes/stream.js
- They allow the execution of a group of commands in a single step
- All the commands in a transaction are serialized and executed sequentially.
- Atomicity (either all occur or nothing occurs)
node examples/transactions/multi-exec.js
- You can encapsulate some complex operations in a script and your data layer will perform the atomic
node examples/transactions/rewards.js
node examples/transactions/lua-script.js
- PUBLISH / SUBSCRIBE
pros
- Memory efficiency
- Group messagingsS
- Examples: notifications, chats, etc.
cons
- High chance loss message
node pubsub.js
- BRPOPLPUSH / RedisSMQ
- Message only will be consumed by one consumer
- Less memory efficiency
node examples/queues/create.js
node examples/queues/producer.js
node examples/queues/consumer.js
https://redis.io/topics/introduction
https://dzone.com/articles/how-redis-is-used-in-practice
https://www.bogotobogo.com/DevOps/Redis/Redis_vs_Memcached.php
https://matt.sh/introduction-to-redis-data-types
https://www.compose.com/articles/a-quick-guide-to-redis-lua-scripting/
https://medium.com/@anvannguyen/redis-message-queue-rpoplpush-vs-pub-sub-e8a19a3c071b