SlideShare a Scribd company logo
+

Redis {beyond the basics}
Presented by
Steph ☺
+

Outline
■ 

Revisiting Redis

■ 

Keeping data safe
■ 
■ 

Replication

■ 

Replacing Failed Master

■ 

■ 

Persistence

Transaction

Reducing memory use
■ 
■ 

Intlist

■ 

■ 

Ziplist
Sharding

Scaling
+

Redis
■ 

In-memory remote database

■ 

Advanced key-value store

■ 

Data-structure server

■ 

Offers
■  High Performance
■  Replication
■  Unique data model
+

Snapshotting
{Persistence}
■  Data

is taken as it exists and is written to the disk

■  Point-in-time

copy of in-memory data

■  Backup

& transfer to other server

■  Written

to file in “dbfilename” stored in “dir”

■  Until

next snapshot is taken, last snapshot can be
lost if redis crashes
+

Snapshotting
{Persistence}
Initiating Snapshots
■ 
■ 
■ 
■ 
■ 

bgsave
SAVE
Save lines save 60 10000
SHUTDOWN / TERM
SYNC
+

Snapshotting

■  How

often to perform an automatic snapshot

■  Accept

writes on failure

■  Snapshot
■  What

compression

to name the snapshot on the disk
+

Append Only File (AOF)
{Persistence}
■ 

Copies incoming write commands as it happens

■ 

Records data changes at the end of the backup file

■ 

Data set could be recovered with replaying AOF

■ 

“append only yes”

■ 

“appendfsyc always”

■ 

Limited by disk performance
+

Append Only File (AOF)

■  Option

to use AOF

■  Occurrence
■  Option

of sync writes to disk

to sync during AOF compaction

■  Occurrence

of AOF compaction
+

Replication
■  Method

where other servers receive an updated
copy of the data as its being written

■  Replicas

can service read queries

■  Single

master database sends writes out to multiple
slave databases

■  Set

operations can take seconds to finish
+

Replication
■  Configuring
■  On

for replication

master, ensure that the path and filename are
writable by redis process
■  Enable slaving : slaveof host port
■  In a running system, redis can be stopped slaving
or connect to a different master
■  New / Transfer connection: slaveof host port
■  Stop data update: SLAVEOF no one
+

Replication
{SLAVE to MASTER Connection}
+

Replication
{Redis Master-Slave Replica Tree}
+

Replacing Failed Master
{Scenario and Solution}
■  What

will we do in case of system failure?

■  Scenario
■ 
■ 
■ 

Machine A – Redis Master, Machine B – Redis Slave
Machine A loses network connectivity
Machine C has Redis, but no copy of data

■  Solution

A

■ 

Make a fresh snapshot using Machine B using SAVE
Copy snapshot to Machine C
Start Redis on Machine C

■ 

Tell Machine B to be a slave of Machine C

■ 
■ 
+

Replacing Failed Master
{Sequence of Commands}
+

Replacing Failed Master
{Scenario and Solution}
■  What

will we do in case of system failure?

■  Solution
■ 
■ 
■ 
■ 

B

Use Machine B (Slave) as Master
Create a new Slave (maybe Machine C)
Update client configuration to read/write to proper servers
(optional) update server configuration if restart is needed
+

Transactions
■  Begin

transaction with MULTI

■  Execute

commands with EXEC

■  Delayed

execution with multi/exec can improve
performance
■ 
■ 

Holds off sending commands until all of them are known
When all of the commands are known, MULTI is sent by
client
+

Transactions
■  Pipelining
■ 
■ 
■ 

Send multiple commands at once
Wait for all replies
Reduces number of network roundtrips that the client waits
for
+

Reducing Memory Use
{Short Structures}
■ 

Method of reducing memory use

■ 

Ziplist – compact storage and unstructured representation of
LISTs HASHes and ZSETs

■ 

Intset – compact representation of SET

■ 

As structures grow beyond limits, they are converted back to
their original data structure type

■ 

Manipulating compact versions can become slow as they grow
+

Ziplist

■ 

Basic configuration for the 3 data types are similar

■ 

*-max-ziplist-value – max number of items to be encoded as ziplist

■ 

If limits are exceeded, redis will convert the list/hash/zset into nonziplist structure
+

ZIPLIST - LIST
+

Intset
+

Sharded Structures
■  Sharding

– takes data, partitions it to smaller pieces
and sends data to different locations depending on
which partition the data is assigned to

■  Sharding
■  Sharding

LISTs – uses LUA scripting

ZSETs – zset operations on shards violate
how quickly zsets perform, sharding is not useful on
zsets
+

Sharded Structures
■  Sharding
■ 
■ 
■ 

HASHes

Method of partitioning data must be chosen
Hash’s keys can be used as source of info for sharding
To partition keys:
■  Calculate hash function on the key
■  Calculate number of shards needed depending on number
of keys we want to fit in one shard and the total number of
keys
■  Resulting number of shards along with hash value will be
used to find out which shard we’ll use
+

Scaling
{read capacity}
■  In

using small structures, make sure max ziplist is
not too large

■  Use

structures that offer good performance for the
types of queries we want to perform

■  Compress

large data sent to redis for caching to
reduce network reads and writes

■  Use

pipelining and connection pooling
+

Scaling
{read capacity}
■  Increase

total read throughput using read only slave

servers
■ 
■ 

Always remember to WRITE TO THE MASTER
Writing on SLAVE will cause an error

■  Redis
■ 
■ 
■ 

Sentinel

Mode where redis server binary doesn’t act like the typical
one
Watches behavior and health of master(s) and slave(s)
Intended to offer automated failover
+

Scaling
{memory capacity}
■ 

Make sure to check all methods to reduce read data
volume

■ 

Make sure larger pieces of unrelated functionality are
moved to different servers

■ 

Aggregate writes in local memory before writing to redis

■ 

Consider using locks or LUA when limitations such as
watch/multi/exec are encountered

■ 

When using AOF, keep in mind that the disk needs to
keep up with the volume we’re writing
+

Scaling
{write capability}
■  Presharding
■ 
■ 

for growth

Run multiple redis servers on your machine (listen on diff.
ports)
Use multiple redis database on your database server
+

Scaling
{complex queries}
■ 

Scenario : machines have enough memory to hold index, but
we need to execute more queries that server can handle

■ 

Use : SUNIONSTORE, SINTERSTORE, SDIFFSTORE,
ZINTERSTORE, and/or ZUNIONSTORE

■ 

Since we “read” from slave, set : slave-read-only no
+

Reference
■ 

Carlson, Josiah. (2013) Redis in Action. Shelter Island, NY:
Manning Publications
+

Thank You ☺

More Related Content

PDF
Redis Beyond
PPTX
Dynamo db and Cross Region Migration
PDF
How to Meet Your P99 Goal While Overcommitting Another Workload
PDF
State of Gluster Performance
PDF
HSM migration with EasyHSM and Nirvana
PDF
Avoiding Data Hotspots at Scale
PDF
P99CONF — What We Need to Unlearn About Persistent Storage
PPTX
Date-tiered Compaction Policy for Time-series Data
Redis Beyond
Dynamo db and Cross Region Migration
How to Meet Your P99 Goal While Overcommitting Another Workload
State of Gluster Performance
HSM migration with EasyHSM and Nirvana
Avoiding Data Hotspots at Scale
P99CONF — What We Need to Unlearn About Persistent Storage
Date-tiered Compaction Policy for Time-series Data

What's hot (20)

PDF
Erasure codes and storage tiers on gluster
PDF
Challenges with Gluster and Persistent Memory with Dan Lambright
PDF
Performance bottlenecks for metadata workload in Gluster with Poornima Gurusi...
PPTX
HBase at Flurry
PDF
Realtime Indexing for Fast Queries on Massive Semi-Structured Data
PPTX
Backup, Restore, and Disaster Recovery
PPTX
MongoDB 101 & Beyond: Get Started in MongoDB 3.0, Preview 3.2 & Demo of Ops M...
PPTX
Let the Tiger Roar!
PDF
Sharding: Past, Present and Future with Krutika Dhananjay
PDF
Life And Times Of An Address Space
PDF
Building an Efficient AI Training Platform at bilibili with Alluxio
PDF
Speed Up Uber's Presto with Alluxio
PDF
Performance Analysis and Troubleshooting Methodologies for Databases
PPT
BigTable PreReading
TXT
No sql
PDF
InfluxDB Internals
PDF
Life as a GlusterFS Consultant with Ivan Rossi
PPTX
Introducing MongoDB in a multi-site HA environment
PDF
Accordion HBaseCon 2017
PPTX
MongoDB on EC2 and EBS
Erasure codes and storage tiers on gluster
Challenges with Gluster and Persistent Memory with Dan Lambright
Performance bottlenecks for metadata workload in Gluster with Poornima Gurusi...
HBase at Flurry
Realtime Indexing for Fast Queries on Massive Semi-Structured Data
Backup, Restore, and Disaster Recovery
MongoDB 101 & Beyond: Get Started in MongoDB 3.0, Preview 3.2 & Demo of Ops M...
Let the Tiger Roar!
Sharding: Past, Present and Future with Krutika Dhananjay
Life And Times Of An Address Space
Building an Efficient AI Training Platform at bilibili with Alluxio
Speed Up Uber's Presto with Alluxio
Performance Analysis and Troubleshooting Methodologies for Databases
BigTable PreReading
No sql
InfluxDB Internals
Life as a GlusterFS Consultant with Ivan Rossi
Introducing MongoDB in a multi-site HA environment
Accordion HBaseCon 2017
MongoDB on EC2 and EBS
Ad

Similar to Redis Beyond (20)

ODP
Introduction to Redis
PDF
Redis acc 2015_eng
PPTX
Introduction to Redis
PDF
mar07-redis.pdf
PDF
Introduction to Redis
PPTX
Redis Clustering Advanced___31Mar2025.pptx
PDF
#SydPHP - The Magic of Redis
PDF
dba_lounge_Iasi: Everybody likes redis
PPTX
Redis - Partitioning
PPTX
Introduction to Redis
PDF
An Introduction to Redis for Developers.pdf
PDF
Redis as a Main Database, Scaling and HA
PPTX
Redis meetup
PPTX
PDF
RedisConf18 - Redis at LINE - 25 Billion Messages Per Day
PDF
Redis 101
PDF
An Introduction to Redis for .NET Developers.pdf
PDF
History Of Redis Replication And Future Prospects: Zhao Zhao
PPTX
Redis_Presentation.pptx ppt on redis and
PDF
Redis overview
Introduction to Redis
Redis acc 2015_eng
Introduction to Redis
mar07-redis.pdf
Introduction to Redis
Redis Clustering Advanced___31Mar2025.pptx
#SydPHP - The Magic of Redis
dba_lounge_Iasi: Everybody likes redis
Redis - Partitioning
Introduction to Redis
An Introduction to Redis for Developers.pdf
Redis as a Main Database, Scaling and HA
Redis meetup
RedisConf18 - Redis at LINE - 25 Billion Messages Per Day
Redis 101
An Introduction to Redis for .NET Developers.pdf
History Of Redis Replication And Future Prospects: Zhao Zhao
Redis_Presentation.pptx ppt on redis and
Redis overview
Ad

More from KLabCyscorpions-TechBlog (13)

PDF
Object Calisthenics in Objective-C
PDF
Auto Layout on Xcode 5
PDF
Code Review for iOS
PDF
Object Calisthenics
PDF
Why You're A Bad PHP Programmer
PDF
PDF
X-Debug in Php Storm
PDF
Software Testing
PDF
Php + MySql Optimization
PDF
Mysql Optimization
PDF
MVC Web Application
PDF
AfNetworking vs. Native + Caching
Object Calisthenics in Objective-C
Auto Layout on Xcode 5
Code Review for iOS
Object Calisthenics
Why You're A Bad PHP Programmer
X-Debug in Php Storm
Software Testing
Php + MySql Optimization
Mysql Optimization
MVC Web Application
AfNetworking vs. Native + Caching

Recently uploaded (20)

PPTX
Institutional Correction lecture only . . .
PDF
01-Introduction-to-Information-Management.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Cell Structure & Organelles in detailed.
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
master seminar digital applications in india
PDF
Classroom Observation Tools for Teachers
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
Cell Types and Its function , kingdom of life
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
Complications of Minimal Access Surgery at WLH
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
Institutional Correction lecture only . . .
01-Introduction-to-Information-Management.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Basic Mud Logging Guide for educational purpose
Cell Structure & Organelles in detailed.
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Supply Chain Operations Speaking Notes -ICLT Program
TR - Agricultural Crops Production NC III.pdf
master seminar digital applications in india
Classroom Observation Tools for Teachers
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Cell Types and Its function , kingdom of life
O5-L3 Freight Transport Ops (International) V1.pdf
Pharma ospi slides which help in ospi learning
Complications of Minimal Access Surgery at WLH
STATICS OF THE RIGID BODIES Hibbelers.pdf

Redis Beyond

  • 1. + Redis {beyond the basics} Presented by Steph ☺
  • 2. + Outline ■  Revisiting Redis ■  Keeping data safe ■  ■  Replication ■  Replacing Failed Master ■  ■  Persistence Transaction Reducing memory use ■  ■  Intlist ■  ■  Ziplist Sharding Scaling
  • 3. + Redis ■  In-memory remote database ■  Advanced key-value store ■  Data-structure server ■  Offers ■  High Performance ■  Replication ■  Unique data model
  • 4. + Snapshotting {Persistence} ■  Data is taken as it exists and is written to the disk ■  Point-in-time copy of in-memory data ■  Backup & transfer to other server ■  Written to file in “dbfilename” stored in “dir” ■  Until next snapshot is taken, last snapshot can be lost if redis crashes
  • 6. + Snapshotting ■  How often to perform an automatic snapshot ■  Accept writes on failure ■  Snapshot ■  What compression to name the snapshot on the disk
  • 7. + Append Only File (AOF) {Persistence} ■  Copies incoming write commands as it happens ■  Records data changes at the end of the backup file ■  Data set could be recovered with replaying AOF ■  “append only yes” ■  “appendfsyc always” ■  Limited by disk performance
  • 8. + Append Only File (AOF) ■  Option to use AOF ■  Occurrence ■  Option of sync writes to disk to sync during AOF compaction ■  Occurrence of AOF compaction
  • 9. + Replication ■  Method where other servers receive an updated copy of the data as its being written ■  Replicas can service read queries ■  Single master database sends writes out to multiple slave databases ■  Set operations can take seconds to finish
  • 10. + Replication ■  Configuring ■  On for replication master, ensure that the path and filename are writable by redis process ■  Enable slaving : slaveof host port ■  In a running system, redis can be stopped slaving or connect to a different master ■  New / Transfer connection: slaveof host port ■  Stop data update: SLAVEOF no one
  • 13. + Replacing Failed Master {Scenario and Solution} ■  What will we do in case of system failure? ■  Scenario ■  ■  ■  Machine A – Redis Master, Machine B – Redis Slave Machine A loses network connectivity Machine C has Redis, but no copy of data ■  Solution A ■  Make a fresh snapshot using Machine B using SAVE Copy snapshot to Machine C Start Redis on Machine C ■  Tell Machine B to be a slave of Machine C ■  ■ 
  • 15. + Replacing Failed Master {Scenario and Solution} ■  What will we do in case of system failure? ■  Solution ■  ■  ■  ■  B Use Machine B (Slave) as Master Create a new Slave (maybe Machine C) Update client configuration to read/write to proper servers (optional) update server configuration if restart is needed
  • 16. + Transactions ■  Begin transaction with MULTI ■  Execute commands with EXEC ■  Delayed execution with multi/exec can improve performance ■  ■  Holds off sending commands until all of them are known When all of the commands are known, MULTI is sent by client
  • 17. + Transactions ■  Pipelining ■  ■  ■  Send multiple commands at once Wait for all replies Reduces number of network roundtrips that the client waits for
  • 18. + Reducing Memory Use {Short Structures} ■  Method of reducing memory use ■  Ziplist – compact storage and unstructured representation of LISTs HASHes and ZSETs ■  Intset – compact representation of SET ■  As structures grow beyond limits, they are converted back to their original data structure type ■  Manipulating compact versions can become slow as they grow
  • 19. + Ziplist ■  Basic configuration for the 3 data types are similar ■  *-max-ziplist-value – max number of items to be encoded as ziplist ■  If limits are exceeded, redis will convert the list/hash/zset into nonziplist structure
  • 22. + Sharded Structures ■  Sharding – takes data, partitions it to smaller pieces and sends data to different locations depending on which partition the data is assigned to ■  Sharding ■  Sharding LISTs – uses LUA scripting ZSETs – zset operations on shards violate how quickly zsets perform, sharding is not useful on zsets
  • 23. + Sharded Structures ■  Sharding ■  ■  ■  HASHes Method of partitioning data must be chosen Hash’s keys can be used as source of info for sharding To partition keys: ■  Calculate hash function on the key ■  Calculate number of shards needed depending on number of keys we want to fit in one shard and the total number of keys ■  Resulting number of shards along with hash value will be used to find out which shard we’ll use
  • 24. + Scaling {read capacity} ■  In using small structures, make sure max ziplist is not too large ■  Use structures that offer good performance for the types of queries we want to perform ■  Compress large data sent to redis for caching to reduce network reads and writes ■  Use pipelining and connection pooling
  • 25. + Scaling {read capacity} ■  Increase total read throughput using read only slave servers ■  ■  Always remember to WRITE TO THE MASTER Writing on SLAVE will cause an error ■  Redis ■  ■  ■  Sentinel Mode where redis server binary doesn’t act like the typical one Watches behavior and health of master(s) and slave(s) Intended to offer automated failover
  • 26. + Scaling {memory capacity} ■  Make sure to check all methods to reduce read data volume ■  Make sure larger pieces of unrelated functionality are moved to different servers ■  Aggregate writes in local memory before writing to redis ■  Consider using locks or LUA when limitations such as watch/multi/exec are encountered ■  When using AOF, keep in mind that the disk needs to keep up with the volume we’re writing
  • 27. + Scaling {write capability} ■  Presharding ■  ■  for growth Run multiple redis servers on your machine (listen on diff. ports) Use multiple redis database on your database server
  • 28. + Scaling {complex queries} ■  Scenario : machines have enough memory to hold index, but we need to execute more queries that server can handle ■  Use : SUNIONSTORE, SINTERSTORE, SDIFFSTORE, ZINTERSTORE, and/or ZUNIONSTORE ■  Since we “read” from slave, set : slave-read-only no
  • 29. + Reference ■  Carlson, Josiah. (2013) Redis in Action. Shelter Island, NY: Manning Publications