- Azure Redis Cache is based on the popular open-source Redis cache.
- It is typically used as a cache to improve the performance and scalability of systems that rely heavily on backend data-stores.
- Performance is improved by temporarily copying frequently accessed data to fast storage located close to the application.
- Azure Redis Cache can also be used as an in-memory data structure store, distributed non-relational database, and message broker.
- Depending on the service tier, Redis Cache is available with limits from 53GB to 530GB, and 99.9% availability.
- Redis is more than just a key/value store. It supports atomic operations such as appending to a string, incrementing a hash value, etc.
- It also supports transactions, pub/sub, and other features.
Data Types
- Strings: Redis strings are binary safe and allow them to store any type of data with serialization.
- The maximum allowed string length is 512MB.
- It provides some useful commands like
Incr
, Desr
, Append
, GetRange
, SetRange
.
- Lists: Lists are lists of Strings, sorted by insertion order.
- It allows adding elements at the beginning or end of the list.
- It supports constant time insertion and deletion of elements near the beginning or end of the list, even with many millions of inserted items.
- Sets: These are also lists of Strings.
- The unique feature of sets is that they don’t allow duplicate values.
- There are two types of sets: Ordered and Unordered Sets.
- Hashes: Hashes are objects, contains multiple fields.
- The object allows storing as many fields as required.
Cache Invalidation
- Cache Invalidation is the process of replacing or removing the cached items.
- If the data in the cache is deleted or invalid, then the application gets the latest data from the database and keeps it in the cache, and subsequent requests get the latest data from the cache.
- There are different ways to invalidate the cache:
- An application can remove the data in the cache.
- Configure the invalidation rule while setting up the cache.
- Set absolute expiration: you can set a specific time period to expire the cache.
- Set sliding expiration: If the data in the cache not touched for a certain amount of time, then delete the cache.
private static Lazy<ConnectionMultiplexer> _LazyConnection = new Lazy<ConnectionMultiplexer>(() =>
{
return ConnectionMultiplexer.Connect(ConfigurationManager.AppSettings["CacheConnection"]);
});
public static ConnectionMultiplexer Connection => _LazyConnection.Value;
static void Main(string[] args)
{
IDatabase cache = Connection.GetDatabase();
cache.Ping(); // PING command.
// Simple get and put of integral data types into the cache.
var cacheValue = cache.StringGet("Message");
cacheValue = cache.StringSet("Message", "Hello! The cache is working!");
// Get the client list, useful to see if connection list is growing...
var clientList = cache.Execute("CLIENT", "LIST").ToString();
_LazyConnection.Value.Dispose();
}
Caching guidance
qishibo/AnotherRedisDesktopManager