SlideShare une entreprise Scribd logo
1  sur  28
Télécharger pour lire hors ligne
Use Redis in Odd and
Unusual Ways
Percona LIVE!
Europe 2015
@itamarhaber
A Redis Geek and Chief Developer Advocate
at
Have you signed for newsletter?
[1] http://bit.ly/RedisWatch
Have you heard of Redis?
Please raise your hand if you have (raise the
other hand if you haven’t)
● “… an [3] open source (BSD licensed), in-memory
data structure store, used as database, cache and
message broker."
● ~5 data structures, 180+ commands, in-memory,
persistable to disk, atomic operations, Lua scripting,
replication, high availibility, clustering
and an active & vibrant community
● Nee circa 2009, by [4] antirez
(a.k.a Salvatore Sanfilippo)
● Sponsored by [5] Redis Labs
[2] Redis (REmote DIctionary Server)
Why use it? Redis is Blazing Fast™!
“Why is a Ferrari™ so fast?”
Answer: Performance dictates Design
Redis is designed for performance
• [6] The Redis Manifesto: We’re against complexity
• RAM is fast ([7] Latency Numbers Every Programmer
Should Know)
• C is fast ([8] Programming Languages Benchmark)
• (mostly) single-threaded event loops are fast
• Data structures are optimized for performance
• Time-space tradeoff knobs for practically everything ([9]
redis.conf), transparent complexity
• …and it’s made in Italy!
What’s a “Data Structure Store”?
• NoSQL (as in “Not Only SQL”)
• A key-value store (e.g. memcached) maps
string keys to string values:
CREATE TABLE kv (
k VARCHAR(512MB) NOT NULL,
v VARCHAR(512MB),
PRIMARY KEY (k));
• In a data structure store, v is a data structure
Redis’ primary data structures…
…are so much FUN!
Do you like Redis
Keys in RAM?
I am San.
I am San.
San I am.
large*…
* Keys and values can
be up to 512MB and are
binary safe.
… or small?
Would you like them
Would you like them as a String?
Would you serialize everything? (& INCR, APPEND…)
Would you like them as a
Hash?
Would you like a Hash
as cache?
Dictionary
Hashmap
Map
Symbol
table
Associative
array…
Would you want them as a List instead?
Do you want to access
tail, body and head?
LRANGE…
Would you? Could you? As a Set?
Get the difference,
Store a union!
Or just intersect...
You may like them,
you'll see for sure.
You may like
Sorted Sets
by score?
You do not like them.
So you say.
http://try.redis.io!
Try them! And you may.
I would not, could not by a score.
No more Sets! I say no more!
I do not like them as a List.
Stop this now - I do insist.
I do not like them as String or Hash.
I do not like an in-memory database or cache.
Say! I like Redis keys in RAM!
I do! I like them, San-I-am!
Data structures are so much
FUN!
An Odd way for saving Redis RAM
[10] Hashes as embedded KV stores
Pros
Less per-key space overhead (40 bytes vs 12 bytes)
An encoding that plays well with CPU cache locality
Lower utilization of the keyspace size (max 2^32)
Keep “related” values together (superficially like a table)
“Con”
increased computational complexity, but still O(1)
Other than that, even odder
Redis is a data structure server but if the data
is gibberish, it is only a data server.
So:
• For opaque data do (application-side)
compression
• Semi-opaque - custom compression & Lua
to manipulate in place
Oddly enough, it is unusual that we
Read the [x] documentation:
• Learn to use the correct data structure
• Understand the tradeoffs
• Be familiar with complexity
Review the configuration:
• Validate the default settings
• Customize the tradeoffs
Bit arrays
1. Are arrays made up of 0s and 1s
1. AND them, OR them! Or just NOT…
0. Are unusually good for things like tracking (user
login dates, daily active users), population counts
or even simple graphs
1. A foundation to roll out your own analytics or
just use an open source such as [11] bitmapist,
[12] minuteman and [13] bitesized
Geohashes (new in v3.2)
• Despite the name are “just” Sorted Sets
• A [14] Geohash is an encoding where the
longitude bits (odd) are interleaved with the
latitude’s bits (even)
• Cool property: the shorter the geohash, the
less accurate it is
• [15] GEOADD translates lon/lat to score
• GEORADIUS[BYMEMBER]
HyperLogLog
• Invented by Philippe Flajolet et al
• A probabilistic data structure
• Counts unique things…
…but with constant
space-time complexity
(12296 bytes) and %0.81
standard error
Set “algebra” with HLLs
• HLLs are “cheap” so you can have lot of them
• Lossless unions with PFMERGE (think parallel)
• Intersects a la inclusion/exclusion principle:
𝐴 ∩ 𝐵 = 𝐴 + 𝐵 − 𝐴 ∪ 𝐵
But [16] empirically this is shown to be reliable
only under certain conditions
• Better intersect estimated can be obtained [17]
using MinHash (but read parts 1 & 2 first!)
The Time(out) Tunnel
Redis keys can have a TTL, that once
reached, causes expiry
Expiry can trigger a
[18] notification
Note: pub/sub does
not ensure delivery,
use [19] Disque for that
Yes Tony. That will let us
track many things quite easily…
but will we ever get back
home?
Getting started with Redis
1. Try it online: [20] http://try.redis.io/
2. Build it from the source:
3. [21] Try Redis Labs Enterprise Cluster
4. Run it in a container:
5. [22] Connect to it from any language
git clone https://github.com/antirez/redis
cd redis; make; make test; make install
docker run -d --name redis -p 6379:6379 redis
Questions? Contact me!
Itamar Haber
a.k.a. DR.ediseuss
Chief Developer Advocate
📧 itamar@redislabs.com
@itamarhaber
Follow us on Twitter
@redislabs

Contenu connexe

Tendances

Redis Introduction
Redis IntroductionRedis Introduction
Redis Introduction
Alex Su
 
Hive vs Pig for HadoopSourceCodeReading
Hive vs Pig for HadoopSourceCodeReadingHive vs Pig for HadoopSourceCodeReading
Hive vs Pig for HadoopSourceCodeReading
Mitsuharu Hamba
 

Tendances (19)

Redis 101 Data Structure
Redis 101 Data StructureRedis 101 Data Structure
Redis 101 Data Structure
 
A Brief Introduction to Redis
A Brief Introduction to RedisA Brief Introduction to Redis
A Brief Introduction to Redis
 
Python redis talk
Python redis talkPython redis talk
Python redis talk
 
PySpark with Juypter
PySpark with JuypterPySpark with Juypter
PySpark with Juypter
 
Redis Introduction
Redis IntroductionRedis Introduction
Redis Introduction
 
RedisConf17 - 3 Redis Scenarios, 3 Programming Languages
RedisConf17 - 3 Redis Scenarios, 3 Programming LanguagesRedisConf17 - 3 Redis Scenarios, 3 Programming Languages
RedisConf17 - 3 Redis Scenarios, 3 Programming Languages
 
SQL for Elasticsearch
SQL for ElasticsearchSQL for Elasticsearch
SQL for Elasticsearch
 
Simplified Data Management And Process Scheduling in Hadoop
Simplified Data Management And Process Scheduling in HadoopSimplified Data Management And Process Scheduling in Hadoop
Simplified Data Management And Process Scheduling in Hadoop
 
9b. Document-Oriented Databases lab
9b. Document-Oriented Databases lab9b. Document-Oriented Databases lab
9b. Document-Oriented Databases lab
 
Onyx data processing the clojure way
Onyx   data processing  the clojure wayOnyx   data processing  the clojure way
Onyx data processing the clojure way
 
Hive vs Pig for HadoopSourceCodeReading
Hive vs Pig for HadoopSourceCodeReadingHive vs Pig for HadoopSourceCodeReading
Hive vs Pig for HadoopSourceCodeReading
 
Hypertable
HypertableHypertable
Hypertable
 
Introduction to Spark
Introduction to SparkIntroduction to Spark
Introduction to Spark
 
Hypertable - massively scalable nosql database
Hypertable - massively scalable nosql databaseHypertable - massively scalable nosql database
Hypertable - massively scalable nosql database
 
Introduction to Pig & Pig Latin | Big Data Hadoop Spark Tutorial | CloudxLab
Introduction to Pig & Pig Latin | Big Data Hadoop Spark Tutorial | CloudxLabIntroduction to Pig & Pig Latin | Big Data Hadoop Spark Tutorial | CloudxLab
Introduction to Pig & Pig Latin | Big Data Hadoop Spark Tutorial | CloudxLab
 
Database Architectures and Hypertable
Database Architectures and HypertableDatabase Architectures and Hypertable
Database Architectures and Hypertable
 
How to use Parquet as a basis for ETL and analytics
How to use Parquet as a basis for ETL and analyticsHow to use Parquet as a basis for ETL and analytics
How to use Parquet as a basis for ETL and analytics
 
Practical Hadoop using Pig
Practical Hadoop using PigPractical Hadoop using Pig
Practical Hadoop using Pig
 
KeyValue Stores
KeyValue StoresKeyValue Stores
KeyValue Stores
 

En vedette

En vedette (18)

Get more than a cache back! The Microsoft Azure Redis Cache (NDC Oslo)
Get more than a cache back! The Microsoft Azure Redis Cache (NDC Oslo)Get more than a cache back! The Microsoft Azure Redis Cache (NDC Oslo)
Get more than a cache back! The Microsoft Azure Redis Cache (NDC Oslo)
 
Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prad...
Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prad...Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prad...
Build a Geospatial App with Redis 3.2- Andrew Bass, Sean Yesmunt, Sergio Prad...
 
Getting Started with Redis
Getting Started with RedisGetting Started with Redis
Getting Started with Redis
 
UV logic using redis bitmap
UV logic using redis bitmapUV logic using redis bitmap
UV logic using redis bitmap
 
RespClient - Minimal Redis Client for PowerShell
RespClient - Minimal Redis Client for PowerShellRespClient - Minimal Redis Client for PowerShell
RespClient - Minimal Redis Client for PowerShell
 
HIgh Performance Redis- Tague Griffith, GoPro
HIgh Performance Redis- Tague Griffith, GoProHIgh Performance Redis- Tague Griffith, GoPro
HIgh Performance Redis- Tague Griffith, GoPro
 
Using Redis as Distributed Cache for ASP.NET apps - Peter Kellner, 73rd Stre...
 Using Redis as Distributed Cache for ASP.NET apps - Peter Kellner, 73rd Stre... Using Redis as Distributed Cache for ASP.NET apps - Peter Kellner, 73rd Stre...
Using Redis as Distributed Cache for ASP.NET apps - Peter Kellner, 73rd Stre...
 
RedisConf 2016 talk - The Redis API: Simple, Composable, Powerful
RedisConf 2016 talk - The Redis API: Simple, Composable, PowerfulRedisConf 2016 talk - The Redis API: Simple, Composable, Powerful
RedisConf 2016 talk - The Redis API: Simple, Composable, Powerful
 
Troubleshooting Redis- DaeMyung Kang, Kakao
Troubleshooting Redis- DaeMyung Kang, KakaoTroubleshooting Redis- DaeMyung Kang, Kakao
Troubleshooting Redis- DaeMyung Kang, Kakao
 
Scalable Streaming Data Pipelines with Redis
Scalable Streaming Data Pipelines with RedisScalable Streaming Data Pipelines with Redis
Scalable Streaming Data Pipelines with Redis
 
Cloud Foundry for Data Science
Cloud Foundry for Data ScienceCloud Foundry for Data Science
Cloud Foundry for Data Science
 
Back your App with MySQL & Redis, the Cloud Foundry Way- Kenny Bastani, Pivotal
Back your App with MySQL & Redis, the Cloud Foundry Way- Kenny Bastani, PivotalBack your App with MySQL & Redis, the Cloud Foundry Way- Kenny Bastani, Pivotal
Back your App with MySQL & Redis, the Cloud Foundry Way- Kenny Bastani, Pivotal
 
Redis & MongoDB: Stop Big Data Indigestion Before It Starts
Redis & MongoDB: Stop Big Data Indigestion Before It StartsRedis & MongoDB: Stop Big Data Indigestion Before It Starts
Redis & MongoDB: Stop Big Data Indigestion Before It Starts
 
Redis High availability and fault tolerance in a multitenant environment
Redis High availability and fault tolerance in a multitenant environmentRedis High availability and fault tolerance in a multitenant environment
Redis High availability and fault tolerance in a multitenant environment
 
March 29, 2016 Dr. Josiah Carlson talks about using Redis as a Time Series DB
March 29, 2016 Dr. Josiah Carlson talks about using Redis as a Time Series DBMarch 29, 2016 Dr. Josiah Carlson talks about using Redis as a Time Series DB
March 29, 2016 Dr. Josiah Carlson talks about using Redis as a Time Series DB
 
Benchmarking Redis by itself and versus other NoSQL databases
Benchmarking Redis by itself and versus other NoSQL databasesBenchmarking Redis by itself and versus other NoSQL databases
Benchmarking Redis by itself and versus other NoSQL databases
 
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, HerokuPostgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
 
Redis acc 2015_eng
Redis acc 2015_engRedis acc 2015_eng
Redis acc 2015_eng
 

Similaire à Use Redis in Odd and Unusual Ways

Hw09 Practical HBase Getting The Most From Your H Base Install
Hw09   Practical HBase  Getting The Most From Your H Base InstallHw09   Practical HBase  Getting The Most From Your H Base Install
Hw09 Practical HBase Getting The Most From Your H Base Install
Cloudera, Inc.
 
Redis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHPRedis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHP
Ricard Clau
 
Implementing the Databese Server session 02
Implementing the Databese Server session 02Implementing the Databese Server session 02
Implementing the Databese Server session 02
Guillermo Julca
 

Similaire à Use Redis in Odd and Unusual Ways (20)

Redis and Bloom Filters - Atlanta Java Users Group 9/2014
Redis and Bloom Filters - Atlanta Java Users Group 9/2014Redis and Bloom Filters - Atlanta Java Users Group 9/2014
Redis and Bloom Filters - Atlanta Java Users Group 9/2014
 
#SydPHP - The Magic of Redis
#SydPHP - The Magic of Redis#SydPHP - The Magic of Redis
#SydPHP - The Magic of Redis
 
SQL on Hadoop for the Oracle Professional
SQL on Hadoop for the Oracle ProfessionalSQL on Hadoop for the Oracle Professional
SQL on Hadoop for the Oracle Professional
 
Hw09 Practical HBase Getting The Most From Your H Base Install
Hw09   Practical HBase  Getting The Most From Your H Base InstallHw09   Practical HBase  Getting The Most From Your H Base Install
Hw09 Practical HBase Getting The Most From Your H Base Install
 
Lightning Fast Dataframes with Polars
Lightning Fast Dataframes with PolarsLightning Fast Dataframes with Polars
Lightning Fast Dataframes with Polars
 
Why databases cry at night
Why databases cry at nightWhy databases cry at night
Why databases cry at night
 
Hadoop with Python
Hadoop with PythonHadoop with Python
Hadoop with Python
 
Finding the needles in the haystack. An Overview of Analyzing Big Data with H...
Finding the needles in the haystack. An Overview of Analyzing Big Data with H...Finding the needles in the haystack. An Overview of Analyzing Big Data with H...
Finding the needles in the haystack. An Overview of Analyzing Big Data with H...
 
Redis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHPRedis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHP
 
Implementing the Databese Server session 02
Implementing the Databese Server session 02Implementing the Databese Server session 02
Implementing the Databese Server session 02
 
OSDC 2018 | The Computer science behind a modern distributed data store by Ma...
OSDC 2018 | The Computer science behind a modern distributed data store by Ma...OSDC 2018 | The Computer science behind a modern distributed data store by Ma...
OSDC 2018 | The Computer science behind a modern distributed data store by Ma...
 
Redis: An introduction
Redis: An introductionRedis: An introduction
Redis: An introduction
 
The Computer Science Behind a modern Distributed Database
The Computer Science Behind a modern Distributed DatabaseThe Computer Science Behind a modern Distributed Database
The Computer Science Behind a modern Distributed Database
 
Get more than a cache back! - ConFoo Montreal
Get more than a cache back! - ConFoo MontrealGet more than a cache back! - ConFoo Montreal
Get more than a cache back! - ConFoo Montreal
 
Introduction to Google BigQuery
Introduction to Google BigQueryIntroduction to Google BigQuery
Introduction to Google BigQuery
 
Apache kudu
Apache kuduApache kudu
Apache kudu
 
Apache Hive for modern DBAs
Apache Hive for modern DBAsApache Hive for modern DBAs
Apache Hive for modern DBAs
 
The computer science behind a modern disributed data store
The computer science behind a modern disributed data storeThe computer science behind a modern disributed data store
The computer science behind a modern disributed data store
 
Hbase: an introduction
Hbase: an introductionHbase: an introduction
Hbase: an introduction
 
Oslo baksia2014
Oslo baksia2014Oslo baksia2014
Oslo baksia2014
 

Plus de Itamar Haber

Plus de Itamar Haber (10)

Redis v5 & Streams
Redis v5 & StreamsRedis v5 & Streams
Redis v5 & Streams
 
Redis Modules API - an introduction
Redis Modules API - an introductionRedis Modules API - an introduction
Redis Modules API - an introduction
 
Redis Lua Scripts
Redis Lua ScriptsRedis Lua Scripts
Redis Lua Scripts
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
How I Implemented the #1 Requested Feature In Redis In Less than 1 Hour with ...
How I Implemented the #1 Requested Feature In Redis In Less than 1 Hour with ...How I Implemented the #1 Requested Feature In Redis In Less than 1 Hour with ...
How I Implemented the #1 Requested Feature In Redis In Less than 1 Hour with ...
 
Redis Streams - Fiverr Tech5 meetup
Redis Streams - Fiverr Tech5 meetupRedis Streams - Fiverr Tech5 meetup
Redis Streams - Fiverr Tech5 meetup
 
Extend Redis with Modules
Extend Redis with ModulesExtend Redis with Modules
Extend Redis with Modules
 
Power to the People: Redis Lua Scripts
Power to the People: Redis Lua ScriptsPower to the People: Redis Lua Scripts
Power to the People: Redis Lua Scripts
 
Why Your MongoDB Needs Redis
Why Your MongoDB Needs RedisWhy Your MongoDB Needs Redis
Why Your MongoDB Needs Redis
 
Redis Use Patterns (DevconTLV June 2014)
Redis Use Patterns (DevconTLV June 2014)Redis Use Patterns (DevconTLV June 2014)
Redis Use Patterns (DevconTLV June 2014)
 

Dernier

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Dernier (20)

%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 

Use Redis in Odd and Unusual Ways

  • 1. Use Redis in Odd and Unusual Ways Percona LIVE! Europe 2015
  • 2. @itamarhaber A Redis Geek and Chief Developer Advocate at Have you signed for newsletter? [1] http://bit.ly/RedisWatch
  • 3. Have you heard of Redis? Please raise your hand if you have (raise the other hand if you haven’t)
  • 4. ● “… an [3] open source (BSD licensed), in-memory data structure store, used as database, cache and message broker." ● ~5 data structures, 180+ commands, in-memory, persistable to disk, atomic operations, Lua scripting, replication, high availibility, clustering and an active & vibrant community ● Nee circa 2009, by [4] antirez (a.k.a Salvatore Sanfilippo) ● Sponsored by [5] Redis Labs [2] Redis (REmote DIctionary Server)
  • 5. Why use it? Redis is Blazing Fast™! “Why is a Ferrari™ so fast?” Answer: Performance dictates Design
  • 6. Redis is designed for performance • [6] The Redis Manifesto: We’re against complexity • RAM is fast ([7] Latency Numbers Every Programmer Should Know) • C is fast ([8] Programming Languages Benchmark) • (mostly) single-threaded event loops are fast • Data structures are optimized for performance • Time-space tradeoff knobs for practically everything ([9] redis.conf), transparent complexity • …and it’s made in Italy!
  • 7. What’s a “Data Structure Store”? • NoSQL (as in “Not Only SQL”) • A key-value store (e.g. memcached) maps string keys to string values: CREATE TABLE kv ( k VARCHAR(512MB) NOT NULL, v VARCHAR(512MB), PRIMARY KEY (k)); • In a data structure store, v is a data structure
  • 8. Redis’ primary data structures… …are so much FUN!
  • 9.
  • 10. Do you like Redis Keys in RAM? I am San. I am San. San I am.
  • 11. large*… * Keys and values can be up to 512MB and are binary safe. … or small? Would you like them
  • 12. Would you like them as a String? Would you serialize everything? (& INCR, APPEND…)
  • 13. Would you like them as a Hash? Would you like a Hash as cache? Dictionary Hashmap Map Symbol table Associative array…
  • 14. Would you want them as a List instead? Do you want to access tail, body and head? LRANGE…
  • 15. Would you? Could you? As a Set? Get the difference, Store a union! Or just intersect... You may like them, you'll see for sure. You may like Sorted Sets by score?
  • 16. You do not like them. So you say. http://try.redis.io! Try them! And you may. I would not, could not by a score. No more Sets! I say no more! I do not like them as a List. Stop this now - I do insist. I do not like them as String or Hash. I do not like an in-memory database or cache.
  • 17. Say! I like Redis keys in RAM! I do! I like them, San-I-am! Data structures are so much FUN!
  • 18. An Odd way for saving Redis RAM [10] Hashes as embedded KV stores Pros Less per-key space overhead (40 bytes vs 12 bytes) An encoding that plays well with CPU cache locality Lower utilization of the keyspace size (max 2^32) Keep “related” values together (superficially like a table) “Con” increased computational complexity, but still O(1)
  • 19. Other than that, even odder Redis is a data structure server but if the data is gibberish, it is only a data server. So: • For opaque data do (application-side) compression • Semi-opaque - custom compression & Lua to manipulate in place
  • 20. Oddly enough, it is unusual that we Read the [x] documentation: • Learn to use the correct data structure • Understand the tradeoffs • Be familiar with complexity Review the configuration: • Validate the default settings • Customize the tradeoffs
  • 21. Bit arrays 1. Are arrays made up of 0s and 1s 1. AND them, OR them! Or just NOT… 0. Are unusually good for things like tracking (user login dates, daily active users), population counts or even simple graphs 1. A foundation to roll out your own analytics or just use an open source such as [11] bitmapist, [12] minuteman and [13] bitesized
  • 22. Geohashes (new in v3.2) • Despite the name are “just” Sorted Sets • A [14] Geohash is an encoding where the longitude bits (odd) are interleaved with the latitude’s bits (even) • Cool property: the shorter the geohash, the less accurate it is • [15] GEOADD translates lon/lat to score • GEORADIUS[BYMEMBER]
  • 23. HyperLogLog • Invented by Philippe Flajolet et al • A probabilistic data structure • Counts unique things… …but with constant space-time complexity (12296 bytes) and %0.81 standard error
  • 24. Set “algebra” with HLLs • HLLs are “cheap” so you can have lot of them • Lossless unions with PFMERGE (think parallel) • Intersects a la inclusion/exclusion principle: 𝐴 ∩ 𝐵 = 𝐴 + 𝐵 − 𝐴 ∪ 𝐵 But [16] empirically this is shown to be reliable only under certain conditions • Better intersect estimated can be obtained [17] using MinHash (but read parts 1 & 2 first!)
  • 25.
  • 26. The Time(out) Tunnel Redis keys can have a TTL, that once reached, causes expiry Expiry can trigger a [18] notification Note: pub/sub does not ensure delivery, use [19] Disque for that Yes Tony. That will let us track many things quite easily… but will we ever get back home?
  • 27. Getting started with Redis 1. Try it online: [20] http://try.redis.io/ 2. Build it from the source: 3. [21] Try Redis Labs Enterprise Cluster 4. Run it in a container: 5. [22] Connect to it from any language git clone https://github.com/antirez/redis cd redis; make; make test; make install docker run -d --name redis -p 6379:6379 redis
  • 28. Questions? Contact me! Itamar Haber a.k.a. DR.ediseuss Chief Developer Advocate 📧 itamar@redislabs.com @itamarhaber Follow us on Twitter @redislabs