Redis Database – Part 01 – Foundation

This is a blog series on using the Redis NoSQL database.

Introduction

I have been around databases for 30 years starting out with IDMS on ICL mainframes. That progressed into Sybase and Microsoft SQL Server. I have cut my teeth on relational databases however; the one size fits all no longer applies anymore. Those previous eras can be referred to as the first and second database revolution targeting Mainframes, client/server and the beginnings of the web.

The third database revolution are NoSQL databases. With the growth of the cloud, social media, big data, mobile and IOT, a new wave of technologies needed to be designed to cope with the different demands placed on it.

NoSQL databases can be categorized as follows:

  • Document Orientated
  • Key Value Store
  • Wide Column
  • Graph

In order to talk about NoSQL it is often easier when comparing it against a relational database. This is by no means the complete list, just some of the common ones.

SQL

NoSQL

Predefined schema

No schema enforcement (All Data has a schema)

Tabular

Various data structures

ACID compliance

BASE compliance.

Scales vertically

Scales horizontally

Full transaction support

Partial transaction support

SQL Query language

SQL like language or custom language

 

There are other NoSQL types but these are the most popular. If you look at the website DB-Engines Ranking it shows a list of all the databases based on data extracted from search engines. It uses the data to determine how often a search on a particular engine is performed and thereby accessing how popular it is. At the time of writing the most popular Key Value database is Redis.

Redis (Remote Dictionary Server)

What exactly is a Key Value Store? It means all access to the database is done by referencing a key. What is then returned is one or more values however; values are not just simple strings, more like data structures. As we shall see in another blog, there are a number of different types we can use for values which makes it very powerful. Redis focuses on performance and simplicity. The following table gives a list of the features of Redis.

Platform

  • It is open source with the source on Github
  • Written for the Linux and MacOS platform
  • There has been windows versions in the past however; they are old versions only.

Version

  • 4.0.8 (At the time of writing)

Data Durability

  • Sometimes. All data exists in memory and there may be no durability (D) depending on the running mode.
  • It can run in these modes:
    • Memory Only (Never written to disk. Makes it very fast)
    • Snapshot (RDB). This is the default mode and periodically the data is flushed to disk
    • Append-only File (AOF). Has a recovery log where commands are played back at start-up.

Indexes

  • None. Need to create and manage your own List or Sets.

Query Language

  • None. All access is direct using commands

Compelling Features

  • Really fast
  • Simple access
  • Data expiration
  • Lists, Sets and Sorted Sets
  • Publish/Subscribe model
  • HADR.
  • Scale-out.

 

When would you use Redis

This is probably the most important question when determining a specific database platform. Redis is typically used in the following scenarios:

Session Storage

Create an HTTP session store which lowers your page load times without compromising stability.

Caches

Cache data retrieved from applications like twitter which can then have expirations set.

Message Queues

Can act as a Service Broker for publishers and consumers.

Notifications

Allows clients to subscribe to Pub/Sub channels in order to receive events affecting the Redis data set in some way.

Leader boards

Keeping live information in sorted sets.

Installing Redis

Redis requires Linux or MacOS. These can be downloaded from here.

If you are a windows shop you have a number of options:

  • Run Redis in a Linux container using docker running in Linux mode. In fact at the time of writing, Docker have an experimental release that allows you to run Linux containers whilst running in Windows mode.
  • Microsoft Azure has a number of Redis installations.
  • If you sign up with Redis Labs you can get a free cloud Redis installation to try out.

In the next blog I will go into some basics.