Performance is an important key in the success of a good user experienceCaching information is often the best way to achieve the performance.
Redis is far for the traditional cache which deals only with key-value pairs. Build from an open-sourceproject, it is accessible from multiple languages and supports atomic operations such as appending to a string, incrementing the value in a hash, pushing to a list, computing set intersection, union and difference, or getting the member with highest ranking in a sorted set.
This session will introduce many features of the Azure Redis Cache service through a demo application.
5. REDIS DEFINITION
Redis is an open source, (BSD licensed), in-memory
data structure store, used as database, cache and
message broker. It supports data structures such as
strings, hashes, lists, sets, sorted sets with range
queries, bitmaps, hyperloglogs, and geospatial
indexes with radius queries.
REDIS - REmote DIctionary Server
Redis.io
9. REDIS - DATA TYPES
• String - key value
• Lists - list of string, sorted by insertion order
• Hashes - map between string fields and string values
• Sets - unordered collection of strings
• Sorted Set - similar to sets but each entry has an associated
“score”
10. SAMPLE APPLICATION -TWEETER
• Tweets
• Timeline
• Accounts
• Account Statistics
• Followers
• Following
• Favorite Hashtags
by Marc Dugas
11. Features
• Can store any kind of data (JPEG images, serialized JSON)
• Maximum size 512MB
Operations
• INCR, DECR, INCRBY, APPEND, EXPIRE
Uses
• Counters (Hits), Rate Limiter (API)
key value
STRING DATA TYPE
12. key
9numberoffollo
wers
tweetcount 843
HASH DATA TYPE
Features
• Map between string fields and string
value
• 4 billion fields per hash
Operations
• HGET, HSET, HINCRBY
Uses
• Statistics for Entity (ex: Number of
Followers)
13. d a bc
LIST DATA TYPE
Features
• List of strings sorted by insertion order
• Can add to head or tail
• 4 billion elements per list
• Very fast access to items from head/tail
Operations
• LPUSH, RPUSH, LRANGE, LTRIM, LPOP,
RPOP
Uses
• Timeline
14. a
e
c
bd
f
SET DATA TYPE
Features
• Unordered collection of strings, no repeating members
• Add/Remove and test for existing extremely quick
• 4 billion elements per set
• Union and Intersection between sets
Operations
• SADD, SREM, SUNION, SINTER
Uses
• Common Followers
15. Features
• Similar to Set → no repeating members
• Each member is associated with a score that is used to order the set
Operations
• ZADD, ZRANGE, ZRANK
Uses
• Leaderboards
c
9
a
3
b
-1
member
score
SORTED SET DATA TYPE
16. background workers
waitinglist
processinglist
producer
QUEUE PATTERN
Approach
• Leverage the Redis List Commands to create a distributed queuing
mechanism
Operations
• Enqueue LPUSH (add to waitinglist)
• Dequeue RPOPLPUSH (RPOP from waitinglist, LPUSH on
processinglist)
• Post Processing LREM (remove from processinglist )
17. Features
• Implementation of the Publish/Subscribe paradigm
• Messages are “published” into channels (no knowledge of subscribers)
• Subscribers express interest in channel and receive messages from that
channel
Operations
• PUBLISH , SUBSCRIBE, UNSUBSCRIBE
Uses
• Real time applications, SignalR Scaleout
publisher
channel
subscribers
PUBLISH/SUBSCRIBE PATTERN
Usages: Counter, Rate Limiter
Rate Limiter (i.e. max requests per second):
If Key Does Not Exists
Create Key with Expiry (ex: 1 second)
Increment
If Count > LIMIT
Raise Error
-Show Demo (Creating Tweet)
Operations
-Enqueue -> LPUSH (List left Push)
-Dequeue -> RPOPLPUSH (Right Pop from one queue, LPUSH on second list) Atomic
-Note: A background process can monitor “processinglist” for items that remain for too long and push on the waiting list again
-Show Demo (Create Tweet)
DEMO
PUBLISH clearlocalcache yes
https://azure.microsoft.com/en-gb/blog/azure-redis-cache-public-preview-of-premium-tier/
http://redis.io/topics/cluster-tutorial
-Standard/Premium are configured as two-node Primary/Secondary Replica (Completely managed)
-Premium tier : Snapshots, Enhanced Security, access control policies, etc..
When cache greater than 53GB need, can move to a Redis Cluster