Redis: Cache, sessions and queues

Introduction

Redis are data structures in memory with network access: strings, Hashes, lists, lots. Reading in fractions of a millisecond makes it standard cache SQL base.

Three Redis jobs

Cash: Add the results of heavy queries to TTL and don’t think. Sessions: shared session storage for multiple backends instead Sticky sessions. queues and meters: atomic INCR and Blocking readings from lists close limits and background tasks broker.

Persistence without illusion

By default Redis in memory: the process fell – the data evaporated. RDB Takes periodic pictures (you can lose minutes), AOF writes each operation (slower, but whole seconds). There's enough RDB for the cache. Include AOF sessions and queues, otherwise the first restart will be incident.

Teams every day

Base of the day: SET/GET with TTL via SETEX, INCR for meters, LPUSH/BRPOP For queues, SADD/SMEMBERS for sets, HSET/HGETALL for hashes. Name the keys with the namespace through the colon ?app:session:123- otherwise, in six months, no one He won't remember what's next to him.

Cluster and Sentinel

One instance rests on the memory and becomes a single point of failure. Sentinel gives an automatic filer between the master and the replicas. The cluster shuffles data by nodes. Start with one instance and Sentinel, the cluster connect according to the measured need, not "on" growth.