In this article we will do a walk through of how to use Redis Cache from a .NET Core Serverless HTTP function. Redis is a very powerful caching engine and offers features beyond simple key-value pair caching. In this article, I will restrict my focus to the following topics:
- Installing Redis locally and on Azure
- Using the command line tools of Redis
- Scripting the installation of Azure Redis via PowerShell and ARM templates
- Writing some sample C# code to demonstrate the key-value pair caching aspect of Redis using a sample Azure HTTP trigger function
- Benchmarking the latency and throughput of Redis using simple C# client code
to be done. Talk about the needs for a cache Scalability Database bottle necks Repeated read and round trips
<<a picture would be good, show some web servers, a DB, a memory cache>> Look at Wikipedia for definitions
to be done
Talk about earliest versions of caching (ASP.NET)
to be done , repetitive access of the same data items.
to be done
- ASP.NET Cache
- Session state server
- Microsoft Appfabric
- Third party products like NCache, Memcached and Redis
to be done (talk about serialization, page caching, session state caching)
to be done
to be done
to be done
to be done
- Where to install Windows binaries? Redis server sets up a TCP/IP server. The Redis server can be run as follows
- Open a CMD prompt
- Navigate to the folder where the redis-server.exe was extracted
- You should see a file redis.conf in this folder
- The port number is specified in this (Usually 6379)
- Launch redis server with the following command
c:\redis-server
The log messages on the console will help affirming the actual port number
[36388] 31 May 22:07:17 * The server is now ready to accept connections on port 6379
redis-cli.exe -h localhost -p 6379
redis localhost:6379> keys *
39) "foo:rand:000000000016"
40) "foo:rand:000000000017"
41) "foo:rand:000000000018"
42) "foo:rand:000000000019"
43) "mykey-f9d21bca-48f6-4cf8-b68d-1652b9533633"
44) "mykey-43d5b08a-5b60-4c72-8820-dcb6f6372b4b"
redis localhost:6379> del mykey-0001
redis localhost:6379> flushall
Install-Package StackExchange.Redis
https://github.com/Azure/azure-quickstart-templates/tree/master/101-redis-cache
TODO Talk about redis-benchmark.exe tool
- Pluralsight video (to be done)
- How Facebook uses Memcached(By Mark Zuckerberg) ?
- How Netflix uses caching?
to be done. A short bulleted list
Managing Redis using PowerShell https://docs.microsoft.com/en-us/azure/azure-cache-for-redis/cache-how-to-manage-redis-cache-powershell Caveat about Premium edition
How to reboot Redis? Reset-AzRedisCache https://stackoverflow.com/questions/45978130/clearing-azure-redis-cache-using-powershell-during-deployment
You are releasing a new build and you want to clear any items that are held in the cache. See Redis Cache Utils Task on Azure Devops https://marketplace.visualstudio.com/items?itemName=gbnz.redis-cache-clear&targetId=545b42c4-2c3c-4eef-bbeb-ca8970eab77e
https://github.com/MicrosoftArchive/redis/ Look for the Releases section
- Running redis-cli or redis-benchmark on Windows AppService was not possible
- Make sure to have the latest Redis tools from Microsoft site https://github.com/microsoftarchive/redis
- My tests were done using the Release 3.2.100
- You will need to create a VM in the same region as the Redis instance
- Remember that the client tools do not support TLS security. You will have to disable TLS security from Redis configuration
- Good article from Microsoft. https://docs.microsoft.com/en-us/azure/azure-cache-for-redis/cache-how-to-redis-cli-tool
redis-cli.exe -h saudemo001-dev.redis.cache.windows.net -p 6379 -a "nXz4LEnKPzlYZsIJpmThr29Yzg6J5L6pfih+q4XlDSg=" redis-benchmark.exe -h saudemo001-dev.redis.cache.windows.net -p 6379 -a "nXz4LEnKPzlYZsIJpmThr29Yzg6J5L6pfih+q4XlDSg=" -d 2000 -c 5 -n 5000
Azure/azure-quickstart-templates#7608 Azure/azure-quickstart-templates#7609