- Primary Focus: Speed. It is used when extremely high speed is required.
- A type of NoSQL database designed in a key:value format. It is utilized when more than just a key-value pair is needed.
- Optional Disk Storage: Redis can write to disk optionally. It is often used where the dataset is not critical. Redis stores data in memory, which imposes significant memory constraints.
- Memory Usage:
- An empty instance uses 1 MB of memory.
- 1 million key-value string pairs use approximately 100 MB of memory.
- Memory Usage:
- String
- Hash
- List
- Set
- Sorted Set
- Geospatial Index
- HyperLogLog
- Database
- Caching Layer
- Message Broker
- Redis is not a relational database. However, it can be used as a layer to define relationships for such database types.
- Its best use case is handling datasets with a predictable size that grows rapidly, requiring speed.
- Caching Mechanisms
- Pub/Sub
- Preventing and Delaying Queues
- Short-lived Data
- Counting Comments
- Analyzing Real Data
- Storing Unique Data
Redis provides two persistence mechanisms:
- RDB (Redis Database Snapshots)
- AOF (Append-Only Files)
- A single Redis instance acts as the master.
- Other instances are slaves, serving as copies of the master.
- Clients can connect to either master or slave instances.
- By default, slaves are read-only.
- Data can be split and distributed across instances.
- Manual
- Automatic: Managed by Redis Sentinel for master-slave topologies.
To start a Redis container using Docker, execute the following command:
docker run --name my-redis -p 6379:6379 -d redis
dotnet new webapi -n "CachingWebApi"