Redis - An Alternative (to) Cache - Part I

 


Redis is not a new concept but only introduced to SDL Web 8.5 recently. It is a good choice, and hope it will gain lots of popularity in SDL's ecosystem.
 
This series will show a few basic concepts on Redis and how it is used in SDL Web, and how you can use it inside and outside SDL products.
 
As this is my first blog post, I want to record the experience of writing one as a new blogger. I thought a bit of encouragement (aka beer) would help - let's see how it goes!
 
 
 

What is Redis

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker (from https://redis.io). In fact, the key features of Redis can be summarised in the tag cloud on the top of the post
  • It is a key-value pair data store
  • It can be used as in-memory cache
  • It is a NoSql database with persistence
  • It supports different data types
  • It supports clustering, replication, and high availability
  • Developers love it

Redis Supported Data Types

It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with radius queries (from https://redis.io). As a matter of fact, it is exactly the support to these data types that differentiated Redis from other NoSql databases such as Memcached. Very briefly here is an re-cap of these types - let's go back to school and get the basics right!

Redis Keys

Redis keys are binary-safe strings which means it can be any binary sequence. It also supports the concept of name spaces and all you need to do is to use colon : as part of the key string. For instance, if the key is publication-6:all-products, it is likely that you would like to store all products of the site that is mapped to the specific Tridion publication (id being 6). In this case publication-6 part is the name space.
 
My thoughts started flowing, and it is easier than I thought. I am sure I have not written anything awfully wrong.
 

Redis Values

Strings
It is a string, the very basic Redis type
 
Lists
Redis Lists in generic terms, is just a sequence of ordered elements. What is worth noting is that it is backed by Linked List (https://en.wikipedia.org/wiki/Linked_list) instead of arrays. This has gained benefits of very fast insertion to the head or tail of the list (constant time O(1)). If however performance of getting something from the middle of a large list is important, Sorted Set (as below) may be more suitable.
 
Hashes
Redis value itself can be a key-value pair. It is a very useful way of storing "objects", where the key can be the object property's name, and value being the object property's value (or the key of the 'embedded' object)
 
Sets
Sets are unordered collections of strings. Remember what made you scratch your head at school, intersection? union?
 
Sorted Sets
Similar as sets but the values of the set are sorted. Can only have unique elements. 
 
Bitmaps
Not strictly a datatype but a transformation of strings. Strings are binary safe which has made Redis capable enough to store binary files. This however has a limitation of 512MB. 
 
Powerful thing isn't it! That is why I would like to quote myself
SDL Web 8.5 brings another scalable solution to the need of high performance in modern websites serving big volume of data.
- Hao Peng
And on that note, worth another pint then look forward to the next post in the series! Thoroughly enjoyed it!