2021/02/20

Walkthrough the basic of redis

Goal of writing this blog

  • Figure out the database type of Redis
    • Say, mysql is kind of a RDBMS (Relational database management system)
  • Figure out the data persistence on Redis
    • Say, in RDBMS, data will be persistent unless we delete them explicitly
  • Figure out terminologies in Redis on saving data
    • Say, in RDBMS (mysql etc), we have table / record / schema

Database type of Redis

According to the official introduction,

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache, and message broker.

Here are comparisons between RDBMS and Redis:

The role of Redis in our big picture is acting as a cache or message broker. So, in the following, I will focus on these 2 areas.

Data persistence

In my scenario, redis is acting as a cache or message broker. Therefore, I need to concern following configurations:

  • Keep them in memory, and do not saving data into files (Secondary memory).
  • Size of cache
  • Timeout of cache

Keep them in memory not files

  • Disable RDB & AOF
  • Keep data as long as redis live
save ""
appendonly no
persistence-available no

Size of cache

Timeout of Cache

  • Related Redis Command: TTL / EXPIRE
  • Related configuration: maxmemory-policy

Final configuration should be

database 4
save ""
appendonly no
persistence-available no
maxmemory 3GB
maxpolicy volatile-ttl

Terminologies

Redis stands for?

It means REmote DIctionary Server

Source: https://redis.io/topics/faq

RDB vs AOF

Keys and Values

If we were to apply this data structure concept to the relational world, we could say that databases expose a single data structure - tables. Tables are both complex and flexible. There isn’t much you can’t model, store or manipulate with tables.
...
Keys are how you identify pieces of data. We’ll be dealing with keys a lot, but for now, it’s good enough to know that a key might look like users:leto. One could reasonably expect such a key to contain information about a user named leto. The colon doesn’t have any special meaning, as far as Redis is concerned, but using a separator is a common approach people use to organize their keys.

...
Values represent the actual data associated with the key. They can be anything.

Source: https://www.openmymind.net/redis.pdf

LRU

less recently used (LRU)

Source: https://redis.io/topics/lru-cache

Useful references

沒有留言:

張貼留言