22
Azure Redis Cache Udaiappa Ramachandran ( Udai ) //linkedin.com/in/ udair

Azure Redis Cache

Embed Size (px)

Citation preview

Page 1: Azure Redis Cache

Azure Redis Cache

Udaiappa Ramachandran ( Udai )//linkedin.com/in/udair

Page 2: Azure Redis Cache

Who am I?• Udaiappa Ramachandran ( Udai )• CTO, Akumina, Inc.,• Consultant• Azure Insider• New Hampshire Cloud User Group (http://www.meetup.com/nashuaug )• Focus on Cloud Computing

• Microsoft Azure and Amazon Web Services

• http://cloudycode.wordpress.com• @nhcloud

Page 3: Azure Redis Cache

Agenda• Redis Cache• Redis Data Types• Redis Eviction policies• Cache Patterns• Azure Redis Cache• Best practices• Demo• References• Q & A

Page 4: Azure Redis Cache

Redis Cache• In-memory, high throughput key-value store• Rich data types- Ability to store more than just strings• Configurable Eviction policies• Highly customizable replication support

• Supports hierarchy of ‘Slaves’ per ‘Master’

• Persistence support• Point in time, Log every write, or both

• Clustering• Built in LUA scripting support• Atomic operations• Transactions• Publisher – Subscriber pattern• Pipelining

Page 5: Azure Redis Cache

Redis Cache…• Rich Ecosystem

• Proven at scale: Twitter, GitHub, Weibo, Pinterest, Snapchat, Craigstlist, StackOverflow, Flickr, etc.,

• Wide range of open source community• Rich set of Redis client libraries in multiple languages available on NuGet

• For Example StockExchange.Redis, ServiceStack.Redis• Many more open source libraries and script

• Tools• Redis-benchmark.exe• Redis-cli.exe• Rdm.exe from http://redisdesktop.com/download• Redis Commander from http://joeferner.github.io/redis-commander/

Page 6: Azure Redis Cache

Redis Data Types• Strings• Lists• Sets• Sorted sets• Hashes• Non-trivial, atomic operations on data

• Appends, increments, sorts, merges and many more

Page 7: Azure Redis Cache

String CommandsRedis StackExchange.Redis

SETGETAPPENDINCRDECRGETRANGEMGETMSETSTRLEN

StringAppendStringBitCountStringBitOperationStringBitPositionStringDecrementStringIncrementStringGetStringGetBitStringGetRangeStringGetSetStringGetWithExpiryStringLengthStringSetStringSetBitStringSetRange

Page 8: Azure Redis Cache

List CommandsRedis StackExchange.Redis

LPUSHRPUSHLREMLSETLINDEXLRANGELLENLPOPRPOPLTRIM

ListGetByIndexListInsertAfterListInsertBeforeListLeftPopListLeftPushListLengthListRangeListRemoveListRightPopListRightPopLeftPushListRightPushListSetByIndexListTrim

Page 9: Azure Redis Cache

Set CommandsRedis StackExchange.Redis

SADDSCARDSDIFFSINTERSUNIONSISMEMBERSMEMBERSSMOVESREM

SetAddSetCombineSetCombineAndStoreSetContainsSetLengthSetMembersSetMoveSetPopSetRandomMemberSetRandomMembersSetRemoveSetScan

Page 10: Azure Redis Cache

Sorted Set CommandsRedis StackExchange.Redis

ZADDZCARDZCOUNTZINCRBYZRANGEZRANKZREMZSCORE

SortAndStoreSortedSetAddSortedSetCombineAndStoreSortedSetDecrementSortedSetIncrementSortedSetLengthSortedSetLengthByValueSortedSetRangeByRankSortedSetRangeByRankWithScoreSortedSetRangeByValueSortedSetRankSortedSetRemoveSortedSetRemoveRangeByScoreSortedSetRemoveRangeByValueSortedSetScanSortedSetScore

Page 11: Azure Redis Cache

Hash CommandsRedis StackExchange.Redis

HSETHMSETHGETHMGETHGETALLHDELHEXISTSHINCRBYHKEYSHVALS

HashDecrementHashIncrementHashDeleteHashExistsHashGetHashGetAllHashKeysHashLengthHashScanHashSetHashValues

Page 12: Azure Redis Cache

Redis Eviction Policies• noeviction• allkeys-lru• volatile-lru• allkeys-random• volatile-random• volatile-ttl

Page 13: Azure Redis Cache

Azure Redis Cache• Redis Cache hosted and managed by Microsoft• Dedicated virtual instance per cache• Multiple sizes up to 53GB• Tiers

• Basic: Single node, multiple sizes up to 53GB• Standard: Two node Master/Replica, 99.9% SLA, multiple sizes up to 53GB• Premium: Two-node Primary/Replica with up to 10 shards. Multiple sizes from 6 GB to 53 GB

(contact Microsoft for more).

• Available in all Azure Regions• SSL/non-SSL

Page 14: Azure Redis Cache

Azure Redis Cache…• RBAC support• Provisioning Redis Cache

• Azure Management Portal• API• PowerShell

• Monitoring/Diagnostics• Alerts• ASP.NET Sessions and Output cache providers• Memcached protocol shim

Page 15: Azure Redis Cache

Monitoring Azure Redis Cache• Monitor in the portal• Set eviction policies• Set alerts• Monitor using redis tools ex., redis-cli.exe

• High fragmentation

• Benchmarking using redis-benchmark.exe

Page 16: Azure Redis Cache

Scaling Azure Redis Cache• Scale Up (Vertical Scaling)

• Increase cache size (memory), Bandwidth, CPU

• Scale Out (Horizontal Scaling)• Increased Cache Size, Bandwidth, CPU• Improved Availability, Replication, Clustering

• Things to know• You can't scale to or from a Premium cache.• You can't scale from a Standard cache to a Basic cache.• You can scale from a Basic cache to a Standard cache but you can't change the size at the same

time. If you need a different size, you can do a subsequent scaling operation to the desired size.• You can't scale from a larger size down to the C0 (250 MB) size.

Page 17: Azure Redis Cache

Cache Patterns• Read-Through (RT) – caches data after reading them• Write-Through (WT) - writes data on cache update• Cache Aside is used when the caching provider offers no RT or WT capabilities

• Read from the cache first• Go to the data storage if cache “misses”• Invalidate cache upon data changes

• Retry Logic• Local cache

• Separate cache on each instance• Inconsistent results between instances• Very, very fast• Static or nearly staic data• Examples: Azure In-Role cache, .NET 4 MemoryCache

• Distributed Caching• Transactional or dynamic data• Common cache shared between instances• More scalable • Slower• Example: Managed Cache, Redis Cache

Page 18: Azure Redis Cache

Best Practices• Select right Cache SKU

• Size, Availability, Netowrk Bandwidth, etc.,

• Always use latest version of StackExchange.Redis• Cache and Client should be in the same region• Set Expiration time: minimizes the stale data impact• Use Single instance of ConnectionMultiplexer• AbortOnConnectFail=false• ConnectRetry• Set ConnectionTimeout• Large values/Long running commands

• Use multiple connection multiplexers for different connection settings.

• Bench mark using redis-benchmark.exe• Pub/Sub is not recommended for reliable notification

Page 19: Azure Redis Cache

Demo• Download Source from

• https://github.com/nhcloud/azureredis

Page 20: Azure Redis Cache

Reference• //msdn.microsoft.com/en-us/library/dn589799.aspx• //msdn.microsoft.com/en-us/library/azure/dn766201.aspx• //azure.microsoft.com/en-us/documentation/articles/cache-configure• //msdn.microsoft.com/en-us/library/ff649918.aspx• //azure.microsoft.com/en

-us/blog/investigating-timeout-exceptions-in-stackexchange-redis-for-azure-redis-cache/• //

azure.microsoft.com/en-us/documentation/articles/web-sites-connect-to-redis-using-memcache-protocol/

• //redis.io/documentation• //github.com/MSOpenTech/redis/releases

Page 21: Azure Redis Cache

Q & A

Page 22: Azure Redis Cache

Thank you for attending New Hampshire - Nashua Cloud .NET User Group