SlideShare a Scribd company logo
Ofer Zelig
@oferzelig
What is Redis?
• Key-Value Store / “Data Structure Server”

• Value data types: string, list, set, sorted set, hash

• Memory-based
which means…
very fast reads and writes!!

•

BUT with disk persistence, so you enjoy all the goods

• The only limitation is physical memory on the machine.
What is Redis?
• Extremely easy to use; clearly documented
• Mainly used as Cache layer but some use it as their
first-class database
• Hmm… and BTW… it’s also a great Pub/Sub engine!
• All of its config is done in one very clear text file
• DEMO

• Single-threaded
Redis vs Memcached
• Rich set of data types, not just key-value pairs
• Supports persistence, you don’t lose what’s in the
RAM when server reboots
• Replication out-of-the-box
• You can even create replication trees
What is Redis?
• Open Source (BSD 3-Clause)
• Written by Salvatore Sanfilippo (@antirez)
and other very smart contributors
• Full time sponsored by VMware and now by Pivotal
Who uses Redis?

I’ve almost forgot…

Source: http://blog.togo.io/redisphere/redis-roundup-what-companies-use-redis/
DATA TYPES
DATA TYPES

STRING

users:1

{name:’John’,email:’a@b.com’}

images:5

#h•ChhµLT5•OJ

z‹ H

• Up to 2^32 bits (512MB) in each key!
• Binary safe
• Can hold, and ideal for:
• Plain strings – page/post cache etc.
• Full JSON objects
• Raw bits / flags (great usage: realtime metrics – daily
active users - http://blog.getspool.com/2011/11/29/fast-easyrealtime-metrics-using-redis-bitmaps/)

• Even binary file content (hence binary file
manipulation for example)
DATA TYPES

STRING

users:1

{name:’John’,email:’a@b.com’}

images:5

#h•ChhµLT5•OJ

• Examples:
•
•
•
•

SET
GETSET
SETBIT
INCR, INCRBY

z‹ H
DATA TYPES

STRING

users:1

{name:’John’,email:’a@b.com’}

images:5

#h•ChhµLT5•OJ

z‹ H

• Sample usages:
• Lock:
SET resource-name anystring NX EX max-lock-time

• General Cache
• Flags
• Picture masking (BITOP)
• A/B Testing stats
DATA TYPES
bus:messages

1

LIST
4

{age:3}

1

• Up to 2^32 elements in each key (about 4 billion!)
• Internally maintained as linked-lists
• O(N) - Extremely fast near both ends of the list, less
in the middle
• Ideal for:
• Queues (private and shared)
• Stacks
• Top N, Recent News
DATA TYPES
bus:messages

1

LIST
4

{age:3}

• Examples:
•
•
•
•

LPUSH / RPUSH / LPOP / RPOP
RPOPLPUSH
LRANGE
BLPOP / BRPOP

1
DATA TYPES
bus:messages

1

LIST
4

{age:3}

1

• Sample usages:
• Timeline of a social network – LPUSH to add new
items, LRANGE to retrieve most recently added items
• LPUSH+LTRIM together to always keep top/latest N
• Useful for logging of recent user actions / errors

• RPOPLPUSH using same source and destination to
create a rotation of “ring” of items
• Blocking/waiting
DATA TYPES
page:home:uniquevi
sitors:20140225

•
•
•
•

80.55.203.40

SET
201.3.14.185

55.67.100.120

40.77.232.204

Maintains a unique set of items (but unordered)
Up to 2^32 members in each key (about 4 billion)!
Supports intersections, unions etc.
Quickly check whether a member exists –
SISMEMBER - O(1)

• Ideal for:
• Storing relations (i.e. followers, friends etc.) – the key
represents the User ID, the value (set members) is the
users they follow.
DATA TYPES
page:home:uniquevi
sitors:20140225

80.55.203.40

SET
201.3.14.185

55.67.100.120

40.77.232.204

• Examples:
• SRANDMEMBER / SPOP
• SINTERSTORE / SUNIONSTORE / SDIFFSTORE etc.
• Sample usages:
• Tracking unique IPs (just use SADD every view, then use
SCARD whenever you want)
• Tagging: Use a set for each tag (each member is, say, a
picture ID). You can easily get all pictures that have 3
different tags using SINTER
• Extract random members (ads, lottery balls, tip of the day…)
using SPOP / SRANDMEMBER
DATA TYPES

SORTED SET

sam
Leaders

neville

devon

matt

4236

5870

7615

7615

• Same as set, but ordered
• The order is defined by score. Each member has a score
assigned to.
• Up to 2^32 members in each key (about 4 billion)!
• Supports intersections, unions etc. – basically all commands
that a SET supports
• O(LOG(N)), O(N) and such
• But hey! It’s still a millisecond or so even for big sorted sets
• Sorting takes place upon insert, so queries for ranges, even in the
middle, are still fast

• Members are still unique, but scores may be repeated.
DATA TYPES

SORTED SET

sam
Leaders

neville

devon

matt

4236

5870

7615

7615

• Sample usages:
• Maintain a leader board of a game, get top X etc.
• In general, any top something. Such as top posts by
pageviews etc.
• Index other data in Redis. For example: a sorted set
where each member is a user ID and the score is their
age. You can query for all users within a given age
range.
• Search text statistics
DATA TYPES

HASH

name
age

29

gender

m

active

user:13

Bob

1

• If Redis keys/values are a big hash, then a HASH key
holds a value that is itself a HASH
• But that can’t be nested further

• Up to 2^32 key/value pairs in each hash
• Fields in a hash can still be atomically incremented,
for example
DATA TYPES

HASH

name
age

29

gender

m

active

user:13

Bob

1

• Sample usages:
• Saving properties of a business object (very similar to
plain DB table)
• Saving sessions & CSRF tokens
• Maintaining many-to-many mappings and such
PERSISTENCE

• Two options: RDB and AOF
• Each has advantages & disadvantages (of course…)
PERSISTENCE

RDB

• Point-in-time snapshot of all dataset
• Compact, ideal for regular backup/archive, can be
delivered to S3 etc.
• Multiple save-points available, set in redis.conf
PERSISTENCE
•
•
•
•

AOF == Append Only File
Writes every command, like a tape
Gets re-written when it gets too big
Can be easily parsed & edited

AOF
PERSISTENCE
OK, so what should I use?

• I don’t have clear answer, as always “it depends”
• Visit http://redis.io/topics/persistence for much
more explanation including “What Should I Use”
• Bottom line – defaults are OK, just start and worry
about that when your app gets bigger
KEY EXPIRATION
• Each key can be set to expire:

• EXPIRE / EXPIREAT
• There is at least one command that allows setting
expire time within the command: SETEX
• Cancel expiration - PERSIST

• TTL - returns the remaining time to live of a key
that has a timeout.
• Overwrite of a whole key (i.e. SET) clears the
timeout.
KEY EXPIRATION
• Updating a value doesn’t clear and doesn’t reset the timeout.
• Very interesting read on how Redis actually deletes expired
keys - http://redis.io/commands/expire
• Global expiration policy can be set in redis.conf.
Ideal: when Redis is used as a cache layer:
• maxmemory 2mb
maxmemory-policy allkeys-lru
• There are more options – read the comments inside
redis.conf
MULTI / EXEC
•
•
•
•
•

Transactions
Very safe, no other conflicting clients in the middle
Persistency safe
Optimistic locking using WATCH
EVAL and Lua Scripts
PUB / SUB
• SUBSCRIBE / PUBLISH

• Very easy (DEMO)
• Example usages:
• Chat
• Bus
GLOBAL COMMANDS
•
•
•
•
•
•
•

KEYS / SCAN / SSCAN / HSCAN / ZSCAN
SELECT / DBSIZE
PING / ECHO
INFO / INFO ALL / TIME
MONITOR
SAVE / BGSAVE
CLIENT LIST / CLIENT KILL

• Advanced: SORT (http://redis.io/commands/sort)
BENCHMARKS

• http://redis.io/topics/benchmarks
• DEMO: redis-benchmark -q
MAKING REDIS EVEN FASTER

• Pipelining
• EVAL and Lua Scripts
SERVER
• Windows setup
• https://github.com/MSOpenTech/redis
• Currently v2.6.12
• For development only

• Linux setup
•
•
•
•

Recommended for production
Currently v2.8.6
First of all, don’t be afraid!
Clear instructions on the Redis site
• http://redis.io/topics/quickstart
• You can skip most manual steps and just run a server
installation script:
• http://download.redis.io/redis-stable/README
.NET CLIENTS
• ServiceStack.Redis
• https://github.com/ServiceStack/ServiceStack.Redis

• BookSleeve
•
•
•
•

https://code.google.com/p/booksleeve/
Written by Marc Gravell from Stack Exchange
Pipelined, Task API, async/await etc.
Maintain 1 connection throughout the app
• http://stackoverflow.com/a/8777999/290343

• DEMO
MANAGERS / VIEWERS
• Redsmin - https://redsmin.com/
• Robust
• Priced (except for a very basic plan)
• SaaS

• Redis Desktop Manager - http://redisdesktop.com/
• Open Source Desktop GUI
• Pretty basic

• redis-commander - https://github.com/joeferner/redis-commander
• Node.js, Open Source
• Pretty basic
Clustering
• A long task in process, current Alpha-grade code
•
•

http://redis.io/topics/cluster-tutorial
http://redis.io/presentation/Redis_Cluster.pdf

• In the mean time:

• Replication (master / slaves) – works great
• Redis Sentinel: http://redis.io/topics/sentinel
• A system designed to help managing Redis instances
• Monitoring. constantly checks if master and slave instances are
working as expected.
• Notification. notify sysadmin or other program, that something
is wrong with one of the monitored Redis instances.
• Automatic failover. if the master failed (a slave is promoted to
be master, everyone is updated).
Resources
• http://redis.io – Main Redis site
• Clients, servers, full documentation

• Interactive tutorial - http://try.redis.io/
• The Little Redis Book - http://openmymind.net/redis.pdf
• Various Stack Exchange articles about their infrastructure
including Redis:
• Canonical answer about Stack Exchange cache layers:
http://meta.stackoverflow.com/a/69172
• Great answer from Antirez himself about usage of the
different data types:
• http://stackoverflow.com/a/9626334
SO WHAT ARE YOU
WAITING FOR?
 Super fast
 Easy to install & maintain
 Stable & robust
 Easy to consume with .Net
 High quality documentation

More Related Content

What's hot

Cool MariaDB Plugins
Cool MariaDB Plugins Cool MariaDB Plugins
Cool MariaDB Plugins
Colin Charles
 
Sphinx - High performance full-text search for MySQL
Sphinx - High performance full-text search for MySQLSphinx - High performance full-text search for MySQL
Sphinx - High performance full-text search for MySQL
Nguyen Van Vuong
 
SearchHub - How to Spend Your Summer Keeping it Real: Presented by Grant Inge...
SearchHub - How to Spend Your Summer Keeping it Real: Presented by Grant Inge...SearchHub - How to Spend Your Summer Keeping it Real: Presented by Grant Inge...
SearchHub - How to Spend Your Summer Keeping it Real: Presented by Grant Inge...
Lucidworks
 
Gizzard, DAL and more
Gizzard, DAL and moreGizzard, DAL and more
Gizzard, DAL and more
fulin tang
 
Cassandra vs. Redis
Cassandra vs. RedisCassandra vs. Redis
Cassandra vs. RedisTim Lossen
 
Introduction to Apache Solr
Introduction to Apache SolrIntroduction to Apache Solr
Introduction to Apache Solr
Alexandre Rafalovitch
 
Apache Solr - Enterprise search platform
Apache Solr - Enterprise search platformApache Solr - Enterprise search platform
Apache Solr - Enterprise search platform
Tommaso Teofili
 
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and CapabilitiesNot Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
Brett Meyer
 
Enterprise Search Using Apache Solr
Enterprise Search Using Apache SolrEnterprise Search Using Apache Solr
Enterprise Search Using Apache Solr
sagar chaturvedi
 
State-of-the-Art Drupal Search with Apache Solr
State-of-the-Art Drupal Search with Apache SolrState-of-the-Art Drupal Search with Apache Solr
State-of-the-Art Drupal Search with Apache Solr
guest432cd6
 
Cassandra and Clojure
Cassandra and ClojureCassandra and Clojure
Cassandra and Clojure
nickmbailey
 
Apache Solr
Apache SolrApache Solr
Apache Solr
Minh Tran
 
Introduction to Apache solr
Introduction to Apache solrIntroduction to Apache solr
Introduction to Apache solr
Knoldus Inc.
 
Rebuilding Solr 6 examples - layer by layer (LuceneSolrRevolution 2016)
Rebuilding Solr 6 examples - layer by layer (LuceneSolrRevolution 2016)Rebuilding Solr 6 examples - layer by layer (LuceneSolrRevolution 2016)
Rebuilding Solr 6 examples - layer by layer (LuceneSolrRevolution 2016)
Alexandre Rafalovitch
 
Tuning Linux for your database FLOSSUK 2016
Tuning Linux for your database FLOSSUK 2016Tuning Linux for your database FLOSSUK 2016
Tuning Linux for your database FLOSSUK 2016
Colin Charles
 
Cloudera - Using morphlines for on the-fly ETL by Wolfgang Hoschek
Cloudera - Using morphlines for on the-fly ETL by Wolfgang HoschekCloudera - Using morphlines for on the-fly ETL by Wolfgang Hoschek
Cloudera - Using morphlines for on the-fly ETL by Wolfgang Hoschek
Hakka Labs
 
Solr Indexing and Analysis Tricks
Solr Indexing and Analysis TricksSolr Indexing and Analysis Tricks
Solr Indexing and Analysis Tricks
Erik Hatcher
 
Redis everywhere - PHP London
Redis everywhere - PHP LondonRedis everywhere - PHP London
Redis everywhere - PHP LondonRicard Clau
 
20130310 solr tuorial
20130310 solr tuorial20130310 solr tuorial
20130310 solr tuorialChris Huang
 

What's hot (20)

Cool MariaDB Plugins
Cool MariaDB Plugins Cool MariaDB Plugins
Cool MariaDB Plugins
 
Sphinx - High performance full-text search for MySQL
Sphinx - High performance full-text search for MySQLSphinx - High performance full-text search for MySQL
Sphinx - High performance full-text search for MySQL
 
SearchHub - How to Spend Your Summer Keeping it Real: Presented by Grant Inge...
SearchHub - How to Spend Your Summer Keeping it Real: Presented by Grant Inge...SearchHub - How to Spend Your Summer Keeping it Real: Presented by Grant Inge...
SearchHub - How to Spend Your Summer Keeping it Real: Presented by Grant Inge...
 
Gizzard, DAL and more
Gizzard, DAL and moreGizzard, DAL and more
Gizzard, DAL and more
 
Cassandra vs. Redis
Cassandra vs. RedisCassandra vs. Redis
Cassandra vs. Redis
 
Introduction to Apache Solr
Introduction to Apache SolrIntroduction to Apache Solr
Introduction to Apache Solr
 
Apache Solr - Enterprise search platform
Apache Solr - Enterprise search platformApache Solr - Enterprise search platform
Apache Solr - Enterprise search platform
 
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and CapabilitiesNot Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
 
Enterprise Search Using Apache Solr
Enterprise Search Using Apache SolrEnterprise Search Using Apache Solr
Enterprise Search Using Apache Solr
 
State-of-the-Art Drupal Search with Apache Solr
State-of-the-Art Drupal Search with Apache SolrState-of-the-Art Drupal Search with Apache Solr
State-of-the-Art Drupal Search with Apache Solr
 
Apache Solr
Apache SolrApache Solr
Apache Solr
 
Cassandra and Clojure
Cassandra and ClojureCassandra and Clojure
Cassandra and Clojure
 
Apache Solr
Apache SolrApache Solr
Apache Solr
 
Introduction to Apache solr
Introduction to Apache solrIntroduction to Apache solr
Introduction to Apache solr
 
Rebuilding Solr 6 examples - layer by layer (LuceneSolrRevolution 2016)
Rebuilding Solr 6 examples - layer by layer (LuceneSolrRevolution 2016)Rebuilding Solr 6 examples - layer by layer (LuceneSolrRevolution 2016)
Rebuilding Solr 6 examples - layer by layer (LuceneSolrRevolution 2016)
 
Tuning Linux for your database FLOSSUK 2016
Tuning Linux for your database FLOSSUK 2016Tuning Linux for your database FLOSSUK 2016
Tuning Linux for your database FLOSSUK 2016
 
Cloudera - Using morphlines for on the-fly ETL by Wolfgang Hoschek
Cloudera - Using morphlines for on the-fly ETL by Wolfgang HoschekCloudera - Using morphlines for on the-fly ETL by Wolfgang Hoschek
Cloudera - Using morphlines for on the-fly ETL by Wolfgang Hoschek
 
Solr Indexing and Analysis Tricks
Solr Indexing and Analysis TricksSolr Indexing and Analysis Tricks
Solr Indexing and Analysis Tricks
 
Redis everywhere - PHP London
Redis everywhere - PHP LondonRedis everywhere - PHP London
Redis everywhere - PHP London
 
20130310 solr tuorial
20130310 solr tuorial20130310 solr tuorial
20130310 solr tuorial
 

Similar to Introduction to Redis

Redis - The Universal NoSQL Tool
Redis - The Universal NoSQL ToolRedis - The Universal NoSQL Tool
Redis - The Universal NoSQL Tool
Eberhard Wolff
 
Redis in 20 minutes
Redis in 20 minutesRedis in 20 minutes
Redis in 20 minutes
András Fehér
 
Redis: An introduction
Redis: An introductionRedis: An introduction
Redis: An introduction
Đặng Thảo
 
Redis Labcamp
Redis LabcampRedis Labcamp
Redis Labcamp
Angelo Simone Scotto
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASSDC User Gr...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASSDC User Gr...Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASSDC User Gr...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASSDC User Gr...
Bob Pusateri
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (New England SQ...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (New England SQ...Locks, Blocks, and Snapshots: Maximizing Database Concurrency (New England SQ...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (New England SQ...
Bob Pusateri
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
TO THE NEW | Technology
 
Hbase schema design and sizing apache-con europe - nov 2012
Hbase schema design and sizing   apache-con europe - nov 2012Hbase schema design and sizing   apache-con europe - nov 2012
Hbase schema design and sizing apache-con europe - nov 2012Chris Huang
 
Implementing the Databese Server session 02
Implementing the Databese Server session 02Implementing the Databese Server session 02
Implementing the Databese Server session 02Guillermo Julca
 
Technical Introduction to PostgreSQL and PPAS
Technical Introduction to PostgreSQL and PPASTechnical Introduction to PostgreSQL and PPAS
Technical Introduction to PostgreSQL and PPAS
Ashnikbiz
 
Still All on One Server: Perforce at Scale
Still All on One Server: Perforce at Scale Still All on One Server: Perforce at Scale
Still All on One Server: Perforce at Scale
Perforce
 
Redis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHPRedis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHPRicard Clau
 
HBase Advanced - Lars George
HBase Advanced - Lars GeorgeHBase Advanced - Lars George
HBase Advanced - Lars George
JAX London
 
Database Technologies
Database TechnologiesDatabase Technologies
Database Technologies
Michel de Goede
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASS DBA Virtu...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASS DBA Virtu...Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASS DBA Virtu...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASS DBA Virtu...
Bob Pusateri
 
April, 2021 OpenNTF Webinar - Domino Administration Best Practices
April, 2021 OpenNTF Webinar - Domino Administration Best PracticesApril, 2021 OpenNTF Webinar - Domino Administration Best Practices
April, 2021 OpenNTF Webinar - Domino Administration Best Practices
Howard Greenberg
 
Azure Redis Cache - Cache on Steroids!
Azure Redis Cache - Cache on Steroids!Azure Redis Cache - Cache on Steroids!
Azure Redis Cache - Cache on Steroids!
François Boucher
 
Speed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with RedisSpeed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with Redis
Ricard Clau
 

Similar to Introduction to Redis (20)

Redis - The Universal NoSQL Tool
Redis - The Universal NoSQL ToolRedis - The Universal NoSQL Tool
Redis - The Universal NoSQL Tool
 
Redis in 20 minutes
Redis in 20 minutesRedis in 20 minutes
Redis in 20 minutes
 
Redis: An introduction
Redis: An introductionRedis: An introduction
Redis: An introduction
 
Redis Labcamp
Redis LabcampRedis Labcamp
Redis Labcamp
 
REDIS327
REDIS327REDIS327
REDIS327
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASSDC User Gr...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASSDC User Gr...Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASSDC User Gr...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASSDC User Gr...
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (New England SQ...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (New England SQ...Locks, Blocks, and Snapshots: Maximizing Database Concurrency (New England SQ...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (New England SQ...
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Hbase schema design and sizing apache-con europe - nov 2012
Hbase schema design and sizing   apache-con europe - nov 2012Hbase schema design and sizing   apache-con europe - nov 2012
Hbase schema design and sizing apache-con europe - nov 2012
 
Implementing the Databese Server session 02
Implementing the Databese Server session 02Implementing the Databese Server session 02
Implementing the Databese Server session 02
 
Technical Introduction to PostgreSQL and PPAS
Technical Introduction to PostgreSQL and PPASTechnical Introduction to PostgreSQL and PPAS
Technical Introduction to PostgreSQL and PPAS
 
Still All on One Server: Perforce at Scale
Still All on One Server: Perforce at Scale Still All on One Server: Perforce at Scale
Still All on One Server: Perforce at Scale
 
Redis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHPRedis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHP
 
HBase Advanced - Lars George
HBase Advanced - Lars GeorgeHBase Advanced - Lars George
HBase Advanced - Lars George
 
Database Technologies
Database TechnologiesDatabase Technologies
Database Technologies
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASS DBA Virtu...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASS DBA Virtu...Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASS DBA Virtu...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASS DBA Virtu...
 
April, 2021 OpenNTF Webinar - Domino Administration Best Practices
April, 2021 OpenNTF Webinar - Domino Administration Best PracticesApril, 2021 OpenNTF Webinar - Domino Administration Best Practices
April, 2021 OpenNTF Webinar - Domino Administration Best Practices
 
Azure Redis Cache - Cache on Steroids!
Azure Redis Cache - Cache on Steroids!Azure Redis Cache - Cache on Steroids!
Azure Redis Cache - Cache on Steroids!
 
Speed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with RedisSpeed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with Redis
 
Revision
RevisionRevision
Revision
 

Recently uploaded

Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
UiPathCommunity
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 

Recently uploaded (20)

Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 

Introduction to Redis

  • 2. What is Redis? • Key-Value Store / “Data Structure Server” • Value data types: string, list, set, sorted set, hash • Memory-based which means… very fast reads and writes!! • BUT with disk persistence, so you enjoy all the goods • The only limitation is physical memory on the machine.
  • 3. What is Redis? • Extremely easy to use; clearly documented • Mainly used as Cache layer but some use it as their first-class database • Hmm… and BTW… it’s also a great Pub/Sub engine! • All of its config is done in one very clear text file • DEMO • Single-threaded
  • 4. Redis vs Memcached • Rich set of data types, not just key-value pairs • Supports persistence, you don’t lose what’s in the RAM when server reboots • Replication out-of-the-box • You can even create replication trees
  • 5. What is Redis? • Open Source (BSD 3-Clause) • Written by Salvatore Sanfilippo (@antirez) and other very smart contributors • Full time sponsored by VMware and now by Pivotal
  • 6. Who uses Redis? I’ve almost forgot… Source: http://blog.togo.io/redisphere/redis-roundup-what-companies-use-redis/
  • 8. DATA TYPES STRING users:1 {name:’John’,email:’a@b.com’} images:5 #h•ChhµLT5•OJ z‹ H • Up to 2^32 bits (512MB) in each key! • Binary safe • Can hold, and ideal for: • Plain strings – page/post cache etc. • Full JSON objects • Raw bits / flags (great usage: realtime metrics – daily active users - http://blog.getspool.com/2011/11/29/fast-easyrealtime-metrics-using-redis-bitmaps/) • Even binary file content (hence binary file manipulation for example)
  • 10. DATA TYPES STRING users:1 {name:’John’,email:’a@b.com’} images:5 #h•ChhµLT5•OJ z‹ H • Sample usages: • Lock: SET resource-name anystring NX EX max-lock-time • General Cache • Flags • Picture masking (BITOP) • A/B Testing stats
  • 11. DATA TYPES bus:messages 1 LIST 4 {age:3} 1 • Up to 2^32 elements in each key (about 4 billion!) • Internally maintained as linked-lists • O(N) - Extremely fast near both ends of the list, less in the middle • Ideal for: • Queues (private and shared) • Stacks • Top N, Recent News
  • 12. DATA TYPES bus:messages 1 LIST 4 {age:3} • Examples: • • • • LPUSH / RPUSH / LPOP / RPOP RPOPLPUSH LRANGE BLPOP / BRPOP 1
  • 13. DATA TYPES bus:messages 1 LIST 4 {age:3} 1 • Sample usages: • Timeline of a social network – LPUSH to add new items, LRANGE to retrieve most recently added items • LPUSH+LTRIM together to always keep top/latest N • Useful for logging of recent user actions / errors • RPOPLPUSH using same source and destination to create a rotation of “ring” of items • Blocking/waiting
  • 14. DATA TYPES page:home:uniquevi sitors:20140225 • • • • 80.55.203.40 SET 201.3.14.185 55.67.100.120 40.77.232.204 Maintains a unique set of items (but unordered) Up to 2^32 members in each key (about 4 billion)! Supports intersections, unions etc. Quickly check whether a member exists – SISMEMBER - O(1) • Ideal for: • Storing relations (i.e. followers, friends etc.) – the key represents the User ID, the value (set members) is the users they follow.
  • 15. DATA TYPES page:home:uniquevi sitors:20140225 80.55.203.40 SET 201.3.14.185 55.67.100.120 40.77.232.204 • Examples: • SRANDMEMBER / SPOP • SINTERSTORE / SUNIONSTORE / SDIFFSTORE etc. • Sample usages: • Tracking unique IPs (just use SADD every view, then use SCARD whenever you want) • Tagging: Use a set for each tag (each member is, say, a picture ID). You can easily get all pictures that have 3 different tags using SINTER • Extract random members (ads, lottery balls, tip of the day…) using SPOP / SRANDMEMBER
  • 16. DATA TYPES SORTED SET sam Leaders neville devon matt 4236 5870 7615 7615 • Same as set, but ordered • The order is defined by score. Each member has a score assigned to. • Up to 2^32 members in each key (about 4 billion)! • Supports intersections, unions etc. – basically all commands that a SET supports • O(LOG(N)), O(N) and such • But hey! It’s still a millisecond or so even for big sorted sets • Sorting takes place upon insert, so queries for ranges, even in the middle, are still fast • Members are still unique, but scores may be repeated.
  • 17. DATA TYPES SORTED SET sam Leaders neville devon matt 4236 5870 7615 7615 • Sample usages: • Maintain a leader board of a game, get top X etc. • In general, any top something. Such as top posts by pageviews etc. • Index other data in Redis. For example: a sorted set where each member is a user ID and the score is their age. You can query for all users within a given age range. • Search text statistics
  • 18. DATA TYPES HASH name age 29 gender m active user:13 Bob 1 • If Redis keys/values are a big hash, then a HASH key holds a value that is itself a HASH • But that can’t be nested further • Up to 2^32 key/value pairs in each hash • Fields in a hash can still be atomically incremented, for example
  • 19. DATA TYPES HASH name age 29 gender m active user:13 Bob 1 • Sample usages: • Saving properties of a business object (very similar to plain DB table) • Saving sessions & CSRF tokens • Maintaining many-to-many mappings and such
  • 20. PERSISTENCE • Two options: RDB and AOF • Each has advantages & disadvantages (of course…)
  • 21. PERSISTENCE RDB • Point-in-time snapshot of all dataset • Compact, ideal for regular backup/archive, can be delivered to S3 etc. • Multiple save-points available, set in redis.conf
  • 22. PERSISTENCE • • • • AOF == Append Only File Writes every command, like a tape Gets re-written when it gets too big Can be easily parsed & edited AOF
  • 23. PERSISTENCE OK, so what should I use? • I don’t have clear answer, as always “it depends” • Visit http://redis.io/topics/persistence for much more explanation including “What Should I Use” • Bottom line – defaults are OK, just start and worry about that when your app gets bigger
  • 24. KEY EXPIRATION • Each key can be set to expire: • EXPIRE / EXPIREAT • There is at least one command that allows setting expire time within the command: SETEX • Cancel expiration - PERSIST • TTL - returns the remaining time to live of a key that has a timeout. • Overwrite of a whole key (i.e. SET) clears the timeout.
  • 25. KEY EXPIRATION • Updating a value doesn’t clear and doesn’t reset the timeout. • Very interesting read on how Redis actually deletes expired keys - http://redis.io/commands/expire • Global expiration policy can be set in redis.conf. Ideal: when Redis is used as a cache layer: • maxmemory 2mb maxmemory-policy allkeys-lru • There are more options – read the comments inside redis.conf
  • 26. MULTI / EXEC • • • • • Transactions Very safe, no other conflicting clients in the middle Persistency safe Optimistic locking using WATCH EVAL and Lua Scripts
  • 27. PUB / SUB • SUBSCRIBE / PUBLISH • Very easy (DEMO) • Example usages: • Chat • Bus
  • 28. GLOBAL COMMANDS • • • • • • • KEYS / SCAN / SSCAN / HSCAN / ZSCAN SELECT / DBSIZE PING / ECHO INFO / INFO ALL / TIME MONITOR SAVE / BGSAVE CLIENT LIST / CLIENT KILL • Advanced: SORT (http://redis.io/commands/sort)
  • 30. MAKING REDIS EVEN FASTER • Pipelining • EVAL and Lua Scripts
  • 31. SERVER • Windows setup • https://github.com/MSOpenTech/redis • Currently v2.6.12 • For development only • Linux setup • • • • Recommended for production Currently v2.8.6 First of all, don’t be afraid! Clear instructions on the Redis site • http://redis.io/topics/quickstart • You can skip most manual steps and just run a server installation script: • http://download.redis.io/redis-stable/README
  • 32. .NET CLIENTS • ServiceStack.Redis • https://github.com/ServiceStack/ServiceStack.Redis • BookSleeve • • • • https://code.google.com/p/booksleeve/ Written by Marc Gravell from Stack Exchange Pipelined, Task API, async/await etc. Maintain 1 connection throughout the app • http://stackoverflow.com/a/8777999/290343 • DEMO
  • 33. MANAGERS / VIEWERS • Redsmin - https://redsmin.com/ • Robust • Priced (except for a very basic plan) • SaaS • Redis Desktop Manager - http://redisdesktop.com/ • Open Source Desktop GUI • Pretty basic • redis-commander - https://github.com/joeferner/redis-commander • Node.js, Open Source • Pretty basic
  • 34. Clustering • A long task in process, current Alpha-grade code • • http://redis.io/topics/cluster-tutorial http://redis.io/presentation/Redis_Cluster.pdf • In the mean time: • Replication (master / slaves) – works great • Redis Sentinel: http://redis.io/topics/sentinel • A system designed to help managing Redis instances • Monitoring. constantly checks if master and slave instances are working as expected. • Notification. notify sysadmin or other program, that something is wrong with one of the monitored Redis instances. • Automatic failover. if the master failed (a slave is promoted to be master, everyone is updated).
  • 35. Resources • http://redis.io – Main Redis site • Clients, servers, full documentation • Interactive tutorial - http://try.redis.io/ • The Little Redis Book - http://openmymind.net/redis.pdf • Various Stack Exchange articles about their infrastructure including Redis: • Canonical answer about Stack Exchange cache layers: http://meta.stackoverflow.com/a/69172 • Great answer from Antirez himself about usage of the different data types: • http://stackoverflow.com/a/9626334
  • 36. SO WHAT ARE YOU WAITING FOR?  Super fast  Easy to install & maintain  Stable & robust  Easy to consume with .Net  High quality documentation

Editor's Notes

  1. WATCH - a command that will make the EXEC conditional: we are asking Redis to perform the transaction only if no other client modified any of the WATCHed keys