Redis Flashcards
Azure Cache for Redis tiers
Tier
Basic
Standard
Premium
Enterprise
Enterprise Flash
Basic
An OSS Redis cache running on a single virtual machine (VM). This tier has no service-level agreement (SLA) and is ideal for development/test and noncritical workloads.
Standard
An OSS Redis cache running on two VMs in a replicated configuration.
Premium
High-performance OSS Redis caches. This tier offers higher throughput, lower latency, better availability, and more features. Premium caches are deployed on more powerful VMs compared to the VMs for Basic or Standard caches.
Enterprise
High-performance caches powered by Redis Labs’ Redis Enterprise software. This tier supports Redis modules including RediSearch, RedisBloom, and RedisTimeSeries. Also, it offers even higher availability than the Premium tier.
Enterprise Flash
Cost-effective large caches powered by Redis Labs’ Redis Enterprise software. This tier extends Redis data storage to nonvolatile memory, which is cheaper than DRAM, on a VM. It reduces the overall per-GB memory cost.
Redis cache Name
The Redis cache needs a globally unique name. The name has to be unique within Azure because it’s used to generate a public-facing URL to connect and communicate with the service.
The name must be between 1 and 63 characters, composed of numbers, letters, and the ‘-‘ character. The cache name can’t start or end with the ‘-‘ character, and consecutive ‘-‘ characters aren’t valid.
Cache type
The tier determines the size, performance, and features that are available for the cache.
Clustering support
With the Premium, Enterprise, and Enterprise Flash tiers you can implement clustering to automatically split your dataset among multiple nodes. To implement clustering, you specify the number of shards to a maximum of 10. The cost incurred is the cost of the original node, multiplied by the number of shards.
Accessing the Redis instance
ping Ping the server. Returns PONG.
set [key] [value] Sets a key/value in the cache. Returns “OK” on success.
get [key] Gets a value from the cache.
exists [key] Returns ‘1’ if the key exists in the cache, ‘0’ if it doesn’t.
type [key] Returns the type associated to the value for the given key.
incr [key] Increment the given value associated with key by ‘1’. The value must be an integer or double value. This returns the new value.
incrby [key] [amount] Increment the given value associated with key by the specified amount. The value must be an integer or double value. Returns the new value.
del [key] Deletes the value associated with the key.
flushdb Delete all keys and values in the database.
Adding an expiration time to values
expire counter 5
Connecting to your Redis cache with StackExchange.Redis
[cache-name].redis.cache.windows.net:6380,password=[password-here],ssl=True,abortConnect=False
Creating a connection
You create a ConnectionMultiplexer instance using the static ConnectionMultiplexer.Connect or ConnectionMultiplexer.ConnectAsync method, passing in either a connection string or a ConfigurationOptions object.
using StackExchange.Redis;
…
var connectionString = “[cache-name].redis.cache.windows.net:6380,password=[password-here],ssl=True,abortConnect=False”;
var redisConnection = ConnectionMultiplexer.Connect(connectionString);
Accessing a Redis database
The IDatabase type represents the Redis database. You can retrieve one using the GetDatabase() method:
IDatabase db = redisConnection.GetDatabase();
example of storing/getting a key/value in the cache:
bool wasSet = db.StringSet(“favorite:flavor”, “i-love-rocky-road”);
string value = db.StringGet(“favorite:flavor”);
Console.WriteLine(value); // displays: ““i-love-rocky-road””