SlideShare a Scribd company logo
1 of 76
Download to read offline
Jordi Boggiano
@seldaek
http://nelm.io/

Redis - Your Advanced
In-Memory Key-Value Store
About Me
              Belgian living in Zürich, Switzerland
              Weby stuff for 10 years
               http://seld.be
              Symfony2, Composer and other OSS contributions
               http://github.com/Seldaek
              Working at Nelmio
               http://nelm.io
               Symfony2 & frontend performance consulting




Jordi Boggiano                                                 Company nelm.io
Twitter @seldaek                                                   Blog seld.be
Agenda
                   Intro
                   Features
                   Use Cases
                   Using it with PHP




Jordi Boggiano                             Company nelm.io
Twitter @seldaek                               Blog seld.be
Redis
                   Wut?




Jordi Boggiano             Company nelm.io
Twitter @seldaek               Blog seld.be
Store
                   You put data in it




Jordi Boggiano                          Company nelm.io
Twitter @seldaek                            Blog seld.be
Key-Value Store
                    Like NoSQL?




Jordi Boggiano                       Company nelm.io
Twitter @seldaek                         Blog seld.be
In-Memory Key-Value Store
                       Like Memcached?




Jordi Boggiano                                 Company nelm.io
Twitter @seldaek                                   Blog seld.be
In-Memory Key-Value Store
                   Memory is fast, but ephemeral




Jordi Boggiano                                     Company nelm.io
Twitter @seldaek                                       Blog seld.be
Persist to Disk
                   Fast and lasting




Jordi Boggiano                        Company nelm.io
Twitter @seldaek                          Blog seld.be
Created by @antirez
                   Sponsored by VMWare




Jordi Boggiano                            Company nelm.io
Twitter @seldaek                              Blog seld.be
So how does it work?




Jordi Boggiano                            Company nelm.io
Twitter @seldaek                              Blog seld.be
Simple Text Protocol
                    Human Readable!




Jordi Boggiano                            Company nelm.io
Twitter @seldaek                              Blog seld.be
Example - Client Library
               1 SET key value




Jordi Boggiano                                              Company nelm.io
Twitter @seldaek                                                Blog seld.be
Example - Client Library
               1 SET key value
               2 > OK




Jordi Boggiano                                              Company nelm.io
Twitter @seldaek                                                Blog seld.be
Example - Client Library
               1 SET key value
               2 > OK
               3 GET key




Jordi Boggiano                                              Company nelm.io
Twitter @seldaek                                                Blog seld.be
Example - Client Library
               1   SET key value
               2   > OK
               3   GET key
               4   > "value"




Jordi Boggiano                                                Company nelm.io
Twitter @seldaek                                                  Blog seld.be
Example - Low Level
               1   *3
               2   $3
               3   SET
               4   $3
               5   key
               6   $5
               7   value
               1 +OK
               1   *2
               2   $3
               3   GET
               4   $3
               5   key
               1 $5
               2 value




Jordi Boggiano                                   Company nelm.io
Twitter @seldaek                                     Blog seld.be
Example - Low Level
               1   *3rn
               2   $3rn
               3   SETrn
               4   $3rn
               5   keyrn
               6   $5rn
               7   valuern
               1 +OKrn
               1   *2rn
               2   $3rn
               3   GETrn
               4   $3rn
               5   keyrn
               1 $5rn
               2 valuern




Jordi Boggiano                                       Company nelm.io
Twitter @seldaek                                         Blog seld.be
Data Types




Jordi Boggiano                  Company nelm.io
Twitter @seldaek                    Blog seld.be
Strings
                   1   SET name Bob
                   2   SET age 20
                   3   MGET name age
                   4   > Bob
                   5   > 20
                   1 GETSET name Alice
                   2 > Bob




Jordi Boggiano                                   Company nelm.io
Twitter @seldaek                                     Blog seld.be
Strings
                   1   SETEX age 3 20
                   2   GET age
                   3   > 20
                   4   // .. 3 seconds later ..
                   5   GET age
                   6   > null




Jordi Boggiano                                    Company nelm.io
Twitter @seldaek                                      Blog seld.be
Integers
                   1   INCR count
                   2   > 1
                   3   INCR count
                   4   > 2
                   5   INCRBY count 3
                   6   > 5




Jordi Boggiano                                Company nelm.io
Twitter @seldaek                                  Blog seld.be
Hashes
              01 HMSET user name Alice email
                 alice@example.org
              02 HGET user email
              03 > alice@example.org
              04 HKEYS user
              05 > name
              06 > email
              07 HGETALL user
              08 > name
              09 > Alice
              10 > email
              11 > alice@example.org


Jordi Boggiano                                 Company nelm.io
Twitter @seldaek                                   Blog seld.be
Lists
              01   RPUSH admins Alice
              02   > 1
              03   RPUSH admins Bob
              04   > 2
              05   LINDEX admins 0
              06   > Alice
              07   LLEN admins
              08   > 2
              09   RPOP admins
              10   > Bob




Jordi Boggiano                            Company nelm.io
Twitter @seldaek                              Blog seld.be
Sets
              01   SADD page:3:visitors 134
              02   > 1
              03   SADD page:3:visitors 253
              04   > 1
              05   SADD page:3:visitors 253
              06   > 0
              07   SCARD page:3:visitors
              08   > 2
              09   SMEMBERS page:3:visitors
              10   > 134
              11   > 253
              12   SISMEMBER page:3:visitors 349
              13   > 0

Jordi Boggiano                                     Company nelm.io
Twitter @seldaek                                       Blog seld.be
Sets
                   1   SADD page:6:visitors 253
                   2   SADD page:6:visitors 923
                   3   SADD page:6:visitors 13
                   4   SINTER page:3:visitors page:6:visitors
                   5   > 253




Jordi Boggiano                                                  Company nelm.io
Twitter @seldaek                                                    Blog seld.be
Sorted Sets
                   1   ZADD highscores 2930 Alice
                   2   ZADD highscores 1546 Bob
                   3   ZREVRANGE highscores 0 10 WITHSCORES
                   4   > Alice
                   5   > 2930
                   6   > Bob
                   7   > 1546




Jordi Boggiano                                                Company nelm.io
Twitter @seldaek                                                  Blog seld.be
Sort of Lists? Listed Sets?
              Lists
                   1 array('foo', 'bar')

              Sets
                   1 shuffle(array('foo', 'bar'))

              Sorted Sets
                   1 ksort(array(3 => 'foo', 1 => 'bar'))



Jordi Boggiano                                              Company nelm.io
Twitter @seldaek                                                Blog seld.be
The basic datatypes of every
                     language exist in Redis




Jordi Boggiano                                    Company nelm.io
Twitter @seldaek                                      Blog seld.be
Process data in Redis
                      instead of PHP




Jordi Boggiano                             Company nelm.io
Twitter @seldaek                               Blog seld.be
A Few Features




Jordi Boggiano                      Company nelm.io
Twitter @seldaek                        Blog seld.be
Atomic Operations
                   1   SETNX name Alice
                   2   GET name
                   3   > Alice
                   4   SETNX name Bob
                   5   GET name
                   6   > Alice
                   1   INCR foo
                   2   GET foo
                   3   > 1
                   4   INCRBY foo 3
                   5   GET foo
                   6   > 4


Jordi Boggiano                                  Company nelm.io
Twitter @seldaek                                    Blog seld.be
EXPIRE / EXPIREAT / PERSIST




Jordi Boggiano                               Company nelm.io
Twitter @seldaek                                 Blog seld.be
Pipelining




Jordi Boggiano                  Company nelm.io
Twitter @seldaek                    Blog seld.be
SORT - SQL in your NoSQL
                   1   SORT key
                   2   SORT key LIMIT 0 10 DESC
                   3   SORT key ALPHA
                   4   SORT page:6:visitors BY user_*->rank GET
                       user_* DESC




Jordi Boggiano                                                    Company nelm.io
Twitter @seldaek                                                      Blog seld.be
Append-Only File & Snapshots




Jordi Boggiano                                    Company nelm.io
Twitter @seldaek                                      Blog seld.be
Pub/Sub
                   1 SUBSCRIBE foo1
                   2 PSUBSCRIBE foo*
                   3 PUBLISH foo0 message




Jordi Boggiano                              Company nelm.io
Twitter @seldaek                                Blog seld.be
Master/Slave Replication




Jordi Boggiano                                Company nelm.io
Twitter @seldaek                                  Blog seld.be
Transactions: MULTI / EXEC /
                         DISCARD
              Optimistic Locking with WATCH



Jordi Boggiano                            Company nelm.io
Twitter @seldaek                              Blog seld.be
Upcoming Features




Jordi Boggiano                         Company nelm.io
Twitter @seldaek                           Blog seld.be
Lua Scripting: EVAL / EVALSHA
                        This is great.




Jordi Boggiano                             Company nelm.io
Twitter @seldaek                               Blog seld.be
EVAL
               1 EVAL <body> <num_keys_in_args> [<arg1> <arg2> ... <arg_N>]
               1 GET A
               2 EVAL "return redis.call('get', KEYS[1])" 1 A




Jordi Boggiano                                                                Company nelm.io
Twitter @seldaek                                                                  Blog seld.be
EVAL
              Example: Atomic Conditional Decrement, Client-Side
               1   WATCH foo
               2   $val = GET foo
               3   $newVal = max(0, $val - 1); // decrement if foo > 0 client-side
               4   MULTI
               5   SET foo $newVal
               6   EXEC

              This may return -ERR, or will block.




Jordi Boggiano                                                                       Company nelm.io
Twitter @seldaek                                                                         Blog seld.be
EVAL
              Example: Atomic Conditional Decrement, Server-Side
              01 EVAL "local value = tonumber(redis.call('get', KEYS[1]))
              02     if value == nil
              03     then
              04         return {err="Value at key is not integer"}
              05     end
              06     if value > tonumber(ARGV[1])
              07     then
              08         value = value - 1
              09         redis.call('set', KEYS[1], value)
              10     end
              11     return value" 1 foo 0

              This is instant and can not fail.




Jordi Boggiano                                                              Company nelm.io
Twitter @seldaek                                                                Blog seld.be
Redis Cluster
                   Almost as delayed as
                   Duke Nukem Forever



Jordi Boggiano                            Company nelm.io
Twitter @seldaek                              Blog seld.be
Speed
                        Redis is FAST.
                   CPU is unlikely to be the
                         bottleneck.
                    What do you do when
                    you run out of RAM?


Jordi Boggiano                                 Company nelm.io
Twitter @seldaek                                   Blog seld.be
Wait for Redis Cluster?
                   If you can. Cluster looks great.




Jordi Boggiano                                        Company nelm.io
Twitter @seldaek                                          Blog seld.be
Use sharding, most client
                      libraries can do it.




Jordi Boggiano                                 Company nelm.io
Twitter @seldaek                                   Blog seld.be
Use Edis, a protocol compatible
                  storage-oriented server.
                   http://inaka.github.com/edis/index.html




Jordi Boggiano                                               Company nelm.io
Twitter @seldaek                                                 Blog seld.be
Use it without persistence,
                          store to disk/DB
                   and load hot data in memory.
                    A good example in these slides from Wooga




Jordi Boggiano                                                  Company nelm.io
Twitter @seldaek                                                    Blog seld.be
Ok, great. But..
                   What is it good for?




Jordi Boggiano                            Company nelm.io
Twitter @seldaek                              Blog seld.be
WEB SCALE
                       THE CLOUD
                         NOSQL
                        ELASTIC
                   HORIZONTAL SCALING
                      VERTICAL TOO

Jordi Boggiano                          Company nelm.io
Twitter @seldaek                            Blog seld.be
WEB SCALE
                       THE CLOUD
                         NOSQL
                        ELASTIC
                   HORIZONTAL SCALING
                      VERTICAL TOO

Jordi Boggiano                          Company nelm.io
Twitter @seldaek                            Blog seld.be
BULLSHIT




Jordi Boggiano                Company nelm.io
Twitter @seldaek                  Blog seld.be
Get real
                   "If you do actually have to scale,
                   then your database isn't going to
                        magically do it for you."




Jordi Boggiano                                          Company nelm.io
Twitter @seldaek                                            Blog seld.be
Really.
                   What is it good for?




Jordi Boggiano                            Company nelm.io
Twitter @seldaek                              Blog seld.be
Storing Sessions
                           Caching Data
                   Other typical Memcached uses



Jordi Boggiano                                    Company nelm.io
Twitter @seldaek                                      Blog seld.be
Caching: Newspaper Site
                   Expensive reads
                   Fast-changing pages
                   Dynamic tracking of what's read for users




Jordi Boggiano                                                 Company nelm.io
Twitter @seldaek                                                   Blog seld.be
Caching: Newspaper Site
              Cache generic results:
                   1 SETEX <pageid>:content 600 <data>
              Store user read-state in sets
                   1 SADD <pageid>:views <userid>
              Combine and render for each user
                   1 GET <pageid>:content
                   2 SISMEMBER <pageid>:views <userid>



Jordi Boggiano                                           Company nelm.io
Twitter @seldaek                                             Blog seld.be
Logging, games and other
                        write-heavy usages
                   1 LPUSH logs "Log message"
                   2 // keep the last 1000 entries
                   3 LTRIM logs 0 999




Jordi Boggiano                                       Company nelm.io
Twitter @seldaek                                         Blog seld.be
Highscore tables
                   1   ZADD scores 4290 <playerid>
                   2   ZADD scores 390 <playerid2>
                   3   // ...
                   4   ZREVRANK scores <playerid> // 0
                   5   ZREVRANGE scores 0 10 WITHSCORES
              Note: players will only be listed once since it is a set.




Jordi Boggiano                                                            Company nelm.io
Twitter @seldaek                                                              Blog seld.be
Who's online now?
                   1   ZADD visits <unix> <userid>
                   2   ZADD visits 1327681399 52
                   3   ZADD visits 1327683245 18
                   4   ZRANGEBYSCORE visits <unix>-3600 <unix>
                   5   ZREMRANGEBYSCORE visits 0 <unix>-3600




Jordi Boggiano                                                   Company nelm.io
Twitter @seldaek                                                     Blog seld.be
Job Queues
              Workers:
                   1 BRPOP queue
              Application:
                   1 LPUSH queue "job description"

               e.g. the Resque lib from GitHub


Jordi Boggiano                                       Company nelm.io
Twitter @seldaek                                         Blog seld.be
Behavior Tracking
                   1 SETBIT click:<item>:<date> <userid> 1
                   2 GETBIT click:3:2012-01-28 55239




Jordi Boggiano                                               Company nelm.io
Twitter @seldaek                                                 Blog seld.be
Last but not least, it puts the
                     fun back in Datafunbases




Jordi Boggiano                                       Company nelm.io
Twitter @seldaek                                         Blog seld.be
Usage with PHP




Jordi Boggiano                      Company nelm.io
Twitter @seldaek                        Blog seld.be
Extension: phpredis




Jordi Boggiano                           Company nelm.io
Twitter @seldaek                             Blog seld.be
Extension: phpredis
              Comes with a session handler, sharding, up to date.
               1   $redis = new Redis();
               2   $redis->connect('127.0.0.1', 6379);
               3   $redis->watch('x');
               4   $val = $redis->get('x');
               5   $newVal = max(0, $val - 1);
               6   $result = $redis->multi()
               7       ->set('x', $newVal)
               8       ->exec();
               9   echo $result !== false ? 'Success' : 'Race lost, try again';

              http://github.com/nicolasff/phpredis




Jordi Boggiano                                                                    Company nelm.io
Twitter @seldaek                                                                      Blog seld.be
Extension: phpiredis




Jordi Boggiano                            Company nelm.io
Twitter @seldaek                              Blog seld.be
Extension: phpiredis
              Basic hiredis bindings, protocol parsing, low level.
               1   $redis = phpiredis_connect('127.0.0.1', 6379);
               2   phpiredis_command($redis, 'WATCH x');
               3   $val = phpiredis_command($redis, 'GET x');
               4   $newVal = max(0, $val - 1);
               5   phpiredis_command($redis, 'MULTI');
               6   phpiredis_command($redis, 'SET x '.$newVal);
               7   $result = phpiredis_command($redis, 'EXEC');
               8   echo $result !== false ? 'Success' : 'Race lost, try again';

              http://github.com/seppo0010/phpiredis




Jordi Boggiano                                                                    Company nelm.io
Twitter @seldaek                                                                      Blog seld.be
Plain PHP: Predis




Jordi Boggiano                         Company nelm.io
Twitter @seldaek                           Blog seld.be
Plain PHP: Predis
              Very complete, sharding, master/slave auto-select,
              can use phpiredis for parsing.
              01   $redis = new PredisClient('tcp://10.0.0.1:6379');
              02
              03   $options = array(
              04       'cas' => true,    // enable Check-and-Set
              05       'watch' => 'x',
              06       'retry' => 10,    // automatic retries
              07   );
              08
              09   $result = $redis->multiExec($options, function($transaction) {
              10       $val = $transaction->get('x');
              11       $newVal = max(0, $val - 1);
              12       $transaction->multi();
              13       $transaction->set('x', $newVal);
              14   });
              15
              16   echo $result !== false ? 'Success' : 'Race lost 10 times, giving up';

              http://github.com/nrk/predis
              http://github.com/snc/SncRedisBundle (Symfony2
              integration)
Jordi Boggiano                                                                             Company nelm.io
Twitter @seldaek                                                                               Blog seld.be
It's fast. It's fun. Try it.
                       try.redis-db.com




Jordi Boggiano                                    Company nelm.io
Twitter @seldaek                                      Blog seld.be
Thank you.
                   Slides: http://slides.seld.be




Jordi Boggiano                                     Company nelm.io
Twitter @seldaek                                       Blog seld.be
Find Out More
                   Redis.io
                   Try Redis
                   The Little Redis Book
                   Redis Cluster Specification




Jordi Boggiano                                   Company nelm.io
Twitter @seldaek                                     Blog seld.be
Questions?
                      jordi@nelm.io
                         @seldaek

                        Feedback:
                   http://joind.in/4764


Jordi Boggiano                            Company nelm.io
Twitter @seldaek                              Blog seld.be

More Related Content

Recently uploaded

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate AgentsRyan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate AgentsRyan Mahoney
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 

Recently uploaded (20)

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate AgentsRyan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 

Featured

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

Redis - Your Advanced In-Memory Key-Value Store

  • 1. Jordi Boggiano @seldaek http://nelm.io/ Redis - Your Advanced In-Memory Key-Value Store
  • 2. About Me Belgian living in Zürich, Switzerland Weby stuff for 10 years http://seld.be Symfony2, Composer and other OSS contributions http://github.com/Seldaek Working at Nelmio http://nelm.io Symfony2 & frontend performance consulting Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 3. Agenda Intro Features Use Cases Using it with PHP Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 4. Redis Wut? Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 5. Store You put data in it Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 6. Key-Value Store Like NoSQL? Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 7. In-Memory Key-Value Store Like Memcached? Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 8. In-Memory Key-Value Store Memory is fast, but ephemeral Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 9. Persist to Disk Fast and lasting Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 10. Created by @antirez Sponsored by VMWare Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 11. So how does it work? Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 12. Simple Text Protocol Human Readable! Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 13. Example - Client Library 1 SET key value Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 14. Example - Client Library 1 SET key value 2 > OK Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 15. Example - Client Library 1 SET key value 2 > OK 3 GET key Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 16. Example - Client Library 1 SET key value 2 > OK 3 GET key 4 > "value" Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 17. Example - Low Level 1 *3 2 $3 3 SET 4 $3 5 key 6 $5 7 value 1 +OK 1 *2 2 $3 3 GET 4 $3 5 key 1 $5 2 value Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 18. Example - Low Level 1 *3rn 2 $3rn 3 SETrn 4 $3rn 5 keyrn 6 $5rn 7 valuern 1 +OKrn 1 *2rn 2 $3rn 3 GETrn 4 $3rn 5 keyrn 1 $5rn 2 valuern Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 19. Data Types Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 20. Strings 1 SET name Bob 2 SET age 20 3 MGET name age 4 > Bob 5 > 20 1 GETSET name Alice 2 > Bob Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 21. Strings 1 SETEX age 3 20 2 GET age 3 > 20 4 // .. 3 seconds later .. 5 GET age 6 > null Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 22. Integers 1 INCR count 2 > 1 3 INCR count 4 > 2 5 INCRBY count 3 6 > 5 Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 23. Hashes 01 HMSET user name Alice email alice@example.org 02 HGET user email 03 > alice@example.org 04 HKEYS user 05 > name 06 > email 07 HGETALL user 08 > name 09 > Alice 10 > email 11 > alice@example.org Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 24. Lists 01 RPUSH admins Alice 02 > 1 03 RPUSH admins Bob 04 > 2 05 LINDEX admins 0 06 > Alice 07 LLEN admins 08 > 2 09 RPOP admins 10 > Bob Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 25. Sets 01 SADD page:3:visitors 134 02 > 1 03 SADD page:3:visitors 253 04 > 1 05 SADD page:3:visitors 253 06 > 0 07 SCARD page:3:visitors 08 > 2 09 SMEMBERS page:3:visitors 10 > 134 11 > 253 12 SISMEMBER page:3:visitors 349 13 > 0 Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 26. Sets 1 SADD page:6:visitors 253 2 SADD page:6:visitors 923 3 SADD page:6:visitors 13 4 SINTER page:3:visitors page:6:visitors 5 > 253 Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 27. Sorted Sets 1 ZADD highscores 2930 Alice 2 ZADD highscores 1546 Bob 3 ZREVRANGE highscores 0 10 WITHSCORES 4 > Alice 5 > 2930 6 > Bob 7 > 1546 Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 28. Sort of Lists? Listed Sets? Lists 1 array('foo', 'bar') Sets 1 shuffle(array('foo', 'bar')) Sorted Sets 1 ksort(array(3 => 'foo', 1 => 'bar')) Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 29. The basic datatypes of every language exist in Redis Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 30. Process data in Redis instead of PHP Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 31. A Few Features Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 32. Atomic Operations 1 SETNX name Alice 2 GET name 3 > Alice 4 SETNX name Bob 5 GET name 6 > Alice 1 INCR foo 2 GET foo 3 > 1 4 INCRBY foo 3 5 GET foo 6 > 4 Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 33. EXPIRE / EXPIREAT / PERSIST Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 34. Pipelining Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 35. SORT - SQL in your NoSQL 1 SORT key 2 SORT key LIMIT 0 10 DESC 3 SORT key ALPHA 4 SORT page:6:visitors BY user_*->rank GET user_* DESC Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 36. Append-Only File & Snapshots Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 37. Pub/Sub 1 SUBSCRIBE foo1 2 PSUBSCRIBE foo* 3 PUBLISH foo0 message Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 38. Master/Slave Replication Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 39. Transactions: MULTI / EXEC / DISCARD Optimistic Locking with WATCH Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 40. Upcoming Features Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 41. Lua Scripting: EVAL / EVALSHA This is great. Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 42. EVAL 1 EVAL <body> <num_keys_in_args> [<arg1> <arg2> ... <arg_N>] 1 GET A 2 EVAL "return redis.call('get', KEYS[1])" 1 A Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 43. EVAL Example: Atomic Conditional Decrement, Client-Side 1 WATCH foo 2 $val = GET foo 3 $newVal = max(0, $val - 1); // decrement if foo > 0 client-side 4 MULTI 5 SET foo $newVal 6 EXEC This may return -ERR, or will block. Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 44. EVAL Example: Atomic Conditional Decrement, Server-Side 01 EVAL "local value = tonumber(redis.call('get', KEYS[1])) 02 if value == nil 03 then 04 return {err="Value at key is not integer"} 05 end 06 if value > tonumber(ARGV[1]) 07 then 08 value = value - 1 09 redis.call('set', KEYS[1], value) 10 end 11 return value" 1 foo 0 This is instant and can not fail. Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 45. Redis Cluster Almost as delayed as Duke Nukem Forever Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 46. Speed Redis is FAST. CPU is unlikely to be the bottleneck. What do you do when you run out of RAM? Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 47. Wait for Redis Cluster? If you can. Cluster looks great. Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 48. Use sharding, most client libraries can do it. Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 49. Use Edis, a protocol compatible storage-oriented server. http://inaka.github.com/edis/index.html Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 50. Use it without persistence, store to disk/DB and load hot data in memory. A good example in these slides from Wooga Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 51. Ok, great. But.. What is it good for? Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 52. WEB SCALE THE CLOUD NOSQL ELASTIC HORIZONTAL SCALING VERTICAL TOO Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 53. WEB SCALE THE CLOUD NOSQL ELASTIC HORIZONTAL SCALING VERTICAL TOO Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 54. BULLSHIT Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 55. Get real "If you do actually have to scale, then your database isn't going to magically do it for you." Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 56. Really. What is it good for? Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 57. Storing Sessions Caching Data Other typical Memcached uses Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 58. Caching: Newspaper Site Expensive reads Fast-changing pages Dynamic tracking of what's read for users Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 59. Caching: Newspaper Site Cache generic results: 1 SETEX <pageid>:content 600 <data> Store user read-state in sets 1 SADD <pageid>:views <userid> Combine and render for each user 1 GET <pageid>:content 2 SISMEMBER <pageid>:views <userid> Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 60. Logging, games and other write-heavy usages 1 LPUSH logs "Log message" 2 // keep the last 1000 entries 3 LTRIM logs 0 999 Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 61. Highscore tables 1 ZADD scores 4290 <playerid> 2 ZADD scores 390 <playerid2> 3 // ... 4 ZREVRANK scores <playerid> // 0 5 ZREVRANGE scores 0 10 WITHSCORES Note: players will only be listed once since it is a set. Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 62. Who's online now? 1 ZADD visits <unix> <userid> 2 ZADD visits 1327681399 52 3 ZADD visits 1327683245 18 4 ZRANGEBYSCORE visits <unix>-3600 <unix> 5 ZREMRANGEBYSCORE visits 0 <unix>-3600 Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 63. Job Queues Workers: 1 BRPOP queue Application: 1 LPUSH queue "job description" e.g. the Resque lib from GitHub Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 64. Behavior Tracking 1 SETBIT click:<item>:<date> <userid> 1 2 GETBIT click:3:2012-01-28 55239 Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 65. Last but not least, it puts the fun back in Datafunbases Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 66. Usage with PHP Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 67. Extension: phpredis Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 68. Extension: phpredis Comes with a session handler, sharding, up to date. 1 $redis = new Redis(); 2 $redis->connect('127.0.0.1', 6379); 3 $redis->watch('x'); 4 $val = $redis->get('x'); 5 $newVal = max(0, $val - 1); 6 $result = $redis->multi() 7 ->set('x', $newVal) 8 ->exec(); 9 echo $result !== false ? 'Success' : 'Race lost, try again'; http://github.com/nicolasff/phpredis Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 69. Extension: phpiredis Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 70. Extension: phpiredis Basic hiredis bindings, protocol parsing, low level. 1 $redis = phpiredis_connect('127.0.0.1', 6379); 2 phpiredis_command($redis, 'WATCH x'); 3 $val = phpiredis_command($redis, 'GET x'); 4 $newVal = max(0, $val - 1); 5 phpiredis_command($redis, 'MULTI'); 6 phpiredis_command($redis, 'SET x '.$newVal); 7 $result = phpiredis_command($redis, 'EXEC'); 8 echo $result !== false ? 'Success' : 'Race lost, try again'; http://github.com/seppo0010/phpiredis Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 71. Plain PHP: Predis Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 72. Plain PHP: Predis Very complete, sharding, master/slave auto-select, can use phpiredis for parsing. 01 $redis = new PredisClient('tcp://10.0.0.1:6379'); 02 03 $options = array( 04 'cas' => true, // enable Check-and-Set 05 'watch' => 'x', 06 'retry' => 10, // automatic retries 07 ); 08 09 $result = $redis->multiExec($options, function($transaction) { 10 $val = $transaction->get('x'); 11 $newVal = max(0, $val - 1); 12 $transaction->multi(); 13 $transaction->set('x', $newVal); 14 }); 15 16 echo $result !== false ? 'Success' : 'Race lost 10 times, giving up'; http://github.com/nrk/predis http://github.com/snc/SncRedisBundle (Symfony2 integration) Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 73. It's fast. It's fun. Try it. try.redis-db.com Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 74. Thank you. Slides: http://slides.seld.be Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 75. Find Out More Redis.io Try Redis The Little Redis Book Redis Cluster Specification Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be
  • 76. Questions? jordi@nelm.io @seldaek Feedback: http://joind.in/4764 Jordi Boggiano Company nelm.io Twitter @seldaek Blog seld.be