SlideShare a Scribd company logo
1 of 52
Download to read offline
SPEED UP YOUR SYMFONY2 
APPLICATION AND BUILD 
AWESOME FEATURES WITH REDIS
HELLO WORLD 
• Ricard Clau, born and grown up in Barcelona 
• Server engineer at Another Place Productions 
• Symfony2 lover and PHP believer (sometimes…) 
• Open-source contributor, sometimes I give talks 
• Twitter @ricardclau / Gmail ricard.clau@gmail.com
AGENDA 
• REDIS introduction, data types and commands 
• Getting started with Redis in PHP / Symfony2 
• Options out of the box in SncRedisBundle 
• Cookbooks implemented in Real World Applications 
• Sharding data and the new Redis Cluster
INTRODUCTION TO REDIS 
And some demystifications
WHAT IS REDIS? 
• REmote DIctionary Server 
• Created in 2009 by Salvatore Sanfilipo (@antirez) 
• Open source (https://github.com/antirez/redis) 
• Advanced in-memory key-value data-structure server 
• Part of the NoSQL movement, think back to structures!
TO ME REDIS IS LIKE...
ONLY IN-MEMORY? 
• Your data needs to fit in your memory 
• It has configurable persistence: RDB snapshots, AOF 
persistence logs, combine both or no persistence at all 
• Think like memcached on steroids with persistence 
• http://redis.io/topics/persistence 
• “Memory is the new disk, disk is the new tape”
INTERESTING FEATURES 
• Master-slave replication 
• Pipelining to improve performance 
• Transactions (kind of with MULTI ... EXEC) 
• Scripting with LUA (~stored procedures) 
• Iterators for Keyspaces and SETS and HASHES (>= 2.8) 
!
COMMANDS 
http://redis.io/commands
NO QUERIES 
•We communicate with Redis via commands 
• No indexes, no schemas, just structures under a key 
• Very good documentation and sandbox 
• All commands have their complexity documented
DATA TYPES 
• Strings (binary-safe) up to 512 Mb 
• Lists of elements sorted by insertion order (max 2^32 - 1) 
• Sets supporting unions, intersections and diffs (max 2^32 - 1) 
• Hashes key-value pairs (max 2^32 - 1) 
• Sorted sets automatically ordered by score (max 2^32 - 1) 
• HyperLogLog to compute cardinality of BIG sets (2^64)
STRINGS COMMANDS 
• GET, SET, STRLEN, APPEND 
• GETRANGE, SETRANGE 
• Bitmap operations: GETBIT, SETBIT, BITCOUNT 
• Counter operations: INCR, DECR, INCRBY, DECRBY 
• If the value is a number, Redis tries to store it efficiently
LISTS COMMANDS 
Key S1 S2 S3 … SN 
• Order of insertion matters 
• Easy to implement Queues and Stacks 
• RPUSH, LPUSH, RPOP, LPOP 
• Blocking versions BLPOP, BRPOP, BRPOPLPUSH with timeout
SETS COMMANDS 
Key 
S1 
S5 
S3 
S2 
S4 
• Collection of unique unordered elements 
• SCARD (Size), SADD, SREM, SISMEMBER, SMEMBERS 
• Intersections, Unions and Diffs: SINTER, SUNION, SDIFF, 
SINTERSTORE, SUNIONSTORE, SDIFFSTORE 
• Iterators with SSCAN (Redis >= 2.8)
HASHES COMMANDS 
Key 
K1 V1 
K2 V2 
K3 V3 
K4 V4 
• Many key-value pairs under the same key 
• HSET, HGET, HGETALL, HLEN, HEXISTS 
• Counters HINCR, HINCRBY, HINCRBYFLOAT 
• Iterators with HSCAN (Redis >= 2.8)
SORTED SETS COMMANDS 
S4 - 1000 
Key S2 - 20 
S3 - 15 
S1 - 0 
• Collection of unique elements ordered by score 
• ZCARD (Size), ZADD, ZREM, ZSCORE 
• Ranking: ZRANGE, ZREVRANGE (optional WITHSCORES) 
• Iterators with ZSCAN (Redis >= 2.8)
HYPERLOGLOG COMMANDS 
• Counting unique things in massive data sets using a very 
small amount of memory 
• PFADD, PFCOUNT, PFMERGE 
• HyperLogLog has an standard error of 0.81% 
• PF prefix in honor of Philippe Flajolet
GETTING STARTED 
Easy steps
PHP CLIENTS 
• Predis (PHP) vs phpredis (PHP extension) 
• Predis is very mature, actively maintained, feature complete, 
extendable, composer friendly and supports all Redis versions 
• Phpredis is faster, but not always backwards compatible 
• Network latency is the biggest performance killer 
• http://redis.io/clients
EASY STEPS (I) 
$ composer require snc/redis-bundle 1.1.* 
$ composer require predis/predis 0.8.* 
or install the phpredis extension 
https://github.com/nicolasff/phpredis
EASY STEPS (II) 
Add the bundle to the Symfony2 kernel
EASY STEPS (III) 
Add some magic to your config.yml
EASY STEPS (IV) 
You can now use Redis as a Symfony2 service! 
! 
In your controller extending 
SymfonyBundleFrameworkBundleControllerController.php
EASY STEPS (V) 
Or inject it to your services via your services.xml
REDIS-CLI AND MONITOR 
• Redis-cli to connect to a Redis instance 
• Experiment with http://redis.io/commands 
•With Monitor we can watch live activity!
SNCREDISBUNDLE 
So many options out of the box!
CLIENTS EVERYWHERE
PHP SESSION SUPPORT 
! 
TTL is the session lifetime, Redis expires it for you 
Session Locking implementation (not optimal) 
Added not so 
many months ago
LOCKING PROBLEM 
• Problem in heavy-write applications: 2 almost concurrent 
requests trying to update same records 
• Concurrent AJAX requests for the same user 
timeline 
R1read 
R1 R2 
R2save 
R2read 
R1save 
R1 updates 
are lost!!!!!
DOCTRINE CACHING 
Implemented with SET / SETEX / GET 
Be careful with expirations! 
No expiring 
Possibly better 
use APC 
entities data 
(annotations / xml / yaml) 
RecordSets 
Setting TTL explicitly 
DQL parsing
MONOLOG (I) 
Implemented with LISTS using RPUSH 
Be careful with memory!
MONOLOG (II) 
And add a new monolog handler using the service 
Level recommended at least warning
SWIFTMAILER SPOOL 
Implemented with LISTS using RPUSH 
Serialized Swift_Mime_Messages in the list
COOKBOOKS 
From Real World applications
REDIS AS A QUEUE 
• Using Lists and LPUSH / RPOP instructions 
•We can have different languages accessing data 
• I used this to send OpenGraph requests to Facebook 
(REALLY slow API) with Python daemons 
• If you need some advanced message queuing features check 
RabbitMQ (@cakper last month´s talk) and others
REAL-TIME DASHBOARDS 
•We can use hashes to group many stats under one key 
• Most of the times we have counters: 
HINCRBY “stats" <key> <increment> 
• HMGET “stats” <key1> <key2> ... to retrieve values and 
HMSET “stats” “stat1” <value1> “stat2” <value2> to set them 
• HGETALL to get the full hash
LEADERBOARDS 
• Super-easy with Redis, heavy consuming with other systems 
• Each board with a single key, using sorted sets 
• ZINCRBY “rankXXX” <increment> <userId> 
• Top N ZREVRANGE “rankXXX” 0 N [WITHSCORES] 
• You can store several millions of members under 1 key
WHO IS ONLINE? (I) 
•We can use SETS to achieve it! 
• One set for every minute, SADD <minute> <userId> 
Time +1m +2m +3m 
2 
2 
7 
4 1 
2 
3 
1 
1 
5 
3 1 
SUNION 
1 
2 
3 
5 
7 
4
WHO IS ONLINE? (II) 
• Online users == everyone active in the last N minutes 
• SUNION <now> <now-1> <now-2> ... 
• SUNIONSTORE “online” <now> <now-1> <now-2> ... 
• Number of users: SCARD “online” 
• Obtain online users with SMEMBERS “online”
FRIENDS ONLINE? 
• If we store user´s friends in a SET with key friends-<user-id> 
• Friends online: SINTERSTORE “friends-<userid>-online” 
“online” “friends-<userid>” 
! 
! 
1 
7 
3 
5 
2 
4 
15 
1 
! 
• Imagine how you would do it without Redis! 
9 
3 
10 
7 
ONLINE 
FRIENDS-12 
SINTER 
FRIENDS-12-ONLINE
SHARDING / CLUSTERING 
This is when it gets tricky…
NEEDS TO FIT IN MEMORY 
• Redis Cluster will be available in 3.0 (currently RC1) 
• Proxy servers: Twemproxy (also for memcached) 
• Client-side partitioning (supported in many clients) 
• Sharding strategies (range vs hash partitioning) 
• Presharding can help scaling horizontally
CONFIGS WARNING! 
! 
The default behaviour is RandomDistributionStrategy! 
PHPRedis has a RedisArray class for client-side sharding 
but this is not supported yet in the bundle!
1-99999 100000-199999 
200000-299999 300000-399999 
id % 4 == 0 id % 4 == 1 
id % 4 == 2 id % 4 == 3 
Easy to predict scale 
Load not properly distributed 
Load distributed ok 
Fairly easy to reshard 
RANGE PARTITIONING 
May work in some cases, not a silver bullet
hash(key) % 4 == 0 hash(key) % 4 == 1 
hash(key) % 4 == 2 hash(key) % 4 == 3 
Distribution also depending on hash algorithm 
Complicated resharding 
HASH PARTITIONING 
Better distribution... but still issues 
If few keys, it also becomes useless 
HASH 
CRC16 
CRC32 
MD5 
SHA1 
MURMUR3 
! 
DIST 
MODULUS 
KETAMA
Many Redis instances in one 
PRESHARDING 
Maybe overengineered 
initial server 
! 
When needed, just split it 
into more servers and you 
don´t need resharding!!! 
! 
Be careful configuring 
memory limits
REDIS CLUSTER 
• Shards the dataset among N nodes 
• Has a responsive failover in order to survive certain failures 
(this was partially covered already with Sentinel) 
• Ability to reshard keys internally 
• Neither CP nor AP, eventually consistent, not very resistant 
to network partitions in some scenarios 
• Many disagree with some of the decisions and tradeoffs
FINAL THOUGHTS 
When and when not to consider Redis
REDIS IS PERFECT FOR... 
• Intensive read-write data applications 
• Temporary stored data 
• Data that fits in memory 
• Problems that fit Redis built-in data types 
• Predictability in performance needed
BUT IS NOT SUITABLE WHEN.. 
• Big data sets, archive data 
• Relational data (RDBMS are absolutely fine to scale) 
•We don´t know how we will access data 
• Reporting applications (no where clauses) 
• It gets tricky for distributed applications (replication, clustering) 
• ALWAYS choose the right tool for the job!
SPECIAL THANKS 
• Ronny López (@ronnylt) & Alonso Vidales (@alonsovidales) 
• Salvatore Sanfilippo (@antirez) 
• Henrik Westphal (https://github.com/snc) 
• Danielle Alessandri (https://github.com/nrk) 
• Nicolas Favre-Felix (https://github.com/nicolasff) 
• Of course, to all of you for being here today!
QUESTIONS? 
• Twitter: @ricardclau 
• E-mail: ricard.clau@gmail.com 
• Github: https://github.com/ricardclau 
• Blog about PHP and Symfony2: http://www.ricardclau.com

More Related Content

What's hot

An Introduction to Redis for Developers.pdf
An Introduction to Redis for Developers.pdfAn Introduction to Redis for Developers.pdf
An Introduction to Redis for Developers.pdfStephen Lorello
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to RedisArnab Mitra
 
Windows 2012 and DNSSEC
Windows 2012 and DNSSECWindows 2012 and DNSSEC
Windows 2012 and DNSSECMen and Mice
 
ceph optimization on ssd ilsoo byun-short
ceph optimization on ssd ilsoo byun-shortceph optimization on ssd ilsoo byun-short
ceph optimization on ssd ilsoo byun-shortNAVER D2
 
Service Discovery in Prometheus
Service Discovery in PrometheusService Discovery in Prometheus
Service Discovery in PrometheusOliver Moser
 
DNSSEC Tutorial; USENIX LISA 2013
DNSSEC Tutorial; USENIX LISA 2013DNSSEC Tutorial; USENIX LISA 2013
DNSSEC Tutorial; USENIX LISA 2013Shumon Huque
 
2021.02 new in Ceph Pacific Dashboard
2021.02 new in Ceph Pacific Dashboard2021.02 new in Ceph Pacific Dashboard
2021.02 new in Ceph Pacific DashboardCeph Community
 
Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...
Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...
Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...Henning Jacobs
 
Build an High-Performance and High-Durable Block Storage Service Based on Ceph
Build an High-Performance and High-Durable Block Storage Service Based on CephBuild an High-Performance and High-Durable Block Storage Service Based on Ceph
Build an High-Performance and High-Durable Block Storage Service Based on CephRongze Zhu
 
Redis at Lyft: 2,000 Instances and Beyond
Redis at Lyft: 2,000 Instances and BeyondRedis at Lyft: 2,000 Instances and Beyond
Redis at Lyft: 2,000 Instances and BeyondDaniel Hochman
 
How Safe is Asynchronous Master-Master Setup?
 How Safe is Asynchronous Master-Master Setup? How Safe is Asynchronous Master-Master Setup?
How Safe is Asynchronous Master-Master Setup?Sveta Smirnova
 
Sistemas Distribuídos - Aspectos de Segurança em Sistemas Distribuídos e JAAS
Sistemas Distribuídos - Aspectos de Segurança em Sistemas Distribuídos e JAASSistemas Distribuídos - Aspectos de Segurança em Sistemas Distribuídos e JAAS
Sistemas Distribuídos - Aspectos de Segurança em Sistemas Distribuídos e JAASAdriano Teixeira de Souza
 
A simple introduction to redis
A simple introduction to redisA simple introduction to redis
A simple introduction to redisZhichao Liang
 

What's hot (20)

Introduction to redis
Introduction to redisIntroduction to redis
Introduction to redis
 
Redis overview
Redis overviewRedis overview
Redis overview
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Solaris basics
Solaris basicsSolaris basics
Solaris basics
 
An Introduction to Redis for Developers.pdf
An Introduction to Redis for Developers.pdfAn Introduction to Redis for Developers.pdf
An Introduction to Redis for Developers.pdf
 
Redis database
Redis databaseRedis database
Redis database
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Windows 2012 and DNSSEC
Windows 2012 and DNSSECWindows 2012 and DNSSEC
Windows 2012 and DNSSEC
 
ceph optimization on ssd ilsoo byun-short
ceph optimization on ssd ilsoo byun-shortceph optimization on ssd ilsoo byun-short
ceph optimization on ssd ilsoo byun-short
 
Service Discovery in Prometheus
Service Discovery in PrometheusService Discovery in Prometheus
Service Discovery in Prometheus
 
DNSSEC Tutorial; USENIX LISA 2013
DNSSEC Tutorial; USENIX LISA 2013DNSSEC Tutorial; USENIX LISA 2013
DNSSEC Tutorial; USENIX LISA 2013
 
2021.02 new in Ceph Pacific Dashboard
2021.02 new in Ceph Pacific Dashboard2021.02 new in Ceph Pacific Dashboard
2021.02 new in Ceph Pacific Dashboard
 
redis basics
redis basicsredis basics
redis basics
 
Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...
Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...
Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...
 
Build an High-Performance and High-Durable Block Storage Service Based on Ceph
Build an High-Performance and High-Durable Block Storage Service Based on CephBuild an High-Performance and High-Durable Block Storage Service Based on Ceph
Build an High-Performance and High-Durable Block Storage Service Based on Ceph
 
Redis at Lyft: 2,000 Instances and Beyond
Redis at Lyft: 2,000 Instances and BeyondRedis at Lyft: 2,000 Instances and Beyond
Redis at Lyft: 2,000 Instances and Beyond
 
Redis and it's data types
Redis and it's data typesRedis and it's data types
Redis and it's data types
 
How Safe is Asynchronous Master-Master Setup?
 How Safe is Asynchronous Master-Master Setup? How Safe is Asynchronous Master-Master Setup?
How Safe is Asynchronous Master-Master Setup?
 
Sistemas Distribuídos - Aspectos de Segurança em Sistemas Distribuídos e JAAS
Sistemas Distribuídos - Aspectos de Segurança em Sistemas Distribuídos e JAASSistemas Distribuídos - Aspectos de Segurança em Sistemas Distribuídos e JAAS
Sistemas Distribuídos - Aspectos de Segurança em Sistemas Distribuídos e JAAS
 
A simple introduction to redis
A simple introduction to redisA simple introduction to redis
A simple introduction to redis
 

Viewers also liked

Rationally boost your symfony2 application with caching tips and monitoring
Rationally boost your symfony2 application with caching tips and monitoringRationally boost your symfony2 application with caching tips and monitoring
Rationally boost your symfony2 application with caching tips and monitoringGiulio De Donato
 
Effective Doctrine2: Performance Tips for Symfony2 Developers
Effective Doctrine2: Performance Tips for Symfony2 DevelopersEffective Doctrine2: Performance Tips for Symfony2 Developers
Effective Doctrine2: Performance Tips for Symfony2 DevelopersMarcin Chwedziak
 
Asynchronous processing with PHP and Symfony2. Do it simple
Asynchronous processing with PHP and Symfony2. Do it simpleAsynchronous processing with PHP and Symfony2. Do it simple
Asynchronous processing with PHP and Symfony2. Do it simpleKirill Chebunin
 
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupScaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupKacper Gunia
 
Расширенное кеширование в Doctrine2
Расширенное кеширование в Doctrine2Расширенное кеширование в Doctrine2
Расширенное кеширование в Doctrine2Ilyas Salikhov
 
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...Ville Mattila
 
Theres a rabbit on my symfony
Theres a rabbit on my symfonyTheres a rabbit on my symfony
Theres a rabbit on my symfonyAlvaro Videla
 
Behat c'est plus que ça | Behat is more than that
Behat c'est plus que ça | Behat is more than thatBehat c'est plus que ça | Behat is more than that
Behat c'est plus que ça | Behat is more than thatSamuel ROZE
 
Symfony 2 : Performances et Optimisations
Symfony 2 : Performances et OptimisationsSymfony 2 : Performances et Optimisations
Symfony 2 : Performances et OptimisationsLes-Tilleuls.coop
 
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreSymfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreRyan Weaver
 
Макс Волошин: Php + shell = ♥
Макс Волошин: Php + shell = ♥Макс Волошин: Php + shell = ♥
Макс Волошин: Php + shell = ♥Oleg Poludnenko
 
How to Clear Cache in a Symfony Cross Application
How to Clear Cache in a Symfony Cross ApplicationHow to Clear Cache in a Symfony Cross Application
How to Clear Cache in a Symfony Cross ApplicationMike Taylor
 
Symfony y Admin Generator
Symfony y Admin GeneratorSymfony y Admin Generator
Symfony y Admin GeneratorJavier López
 
What RabbitMQ Can Do For You (Nomad PHP May 2014)
What RabbitMQ Can Do For You (Nomad PHP May 2014)What RabbitMQ Can Do For You (Nomad PHP May 2014)
What RabbitMQ Can Do For You (Nomad PHP May 2014)James Titcumb
 
Cómo alcanzar el éxito SEO Internacional #SEOnthebeach
Cómo alcanzar el éxito SEO Internacional #SEOnthebeachCómo alcanzar el éxito SEO Internacional #SEOnthebeach
Cómo alcanzar el éxito SEO Internacional #SEOnthebeachAleyda Solís
 
Mis primeros pasos con Symfony 2
Mis primeros pasos con Symfony 2Mis primeros pasos con Symfony 2
Mis primeros pasos con Symfony 2Edgar Dueñas
 
How GZIP compression works - JS Conf EU 2014
How GZIP compression works - JS Conf EU 2014How GZIP compression works - JS Conf EU 2014
How GZIP compression works - JS Conf EU 2014Raul Fraile
 

Viewers also liked (20)

Rationally boost your symfony2 application with caching tips and monitoring
Rationally boost your symfony2 application with caching tips and monitoringRationally boost your symfony2 application with caching tips and monitoring
Rationally boost your symfony2 application with caching tips and monitoring
 
Effective Doctrine2: Performance Tips for Symfony2 Developers
Effective Doctrine2: Performance Tips for Symfony2 DevelopersEffective Doctrine2: Performance Tips for Symfony2 Developers
Effective Doctrine2: Performance Tips for Symfony2 Developers
 
Asynchronous processing with PHP and Symfony2. Do it simple
Asynchronous processing with PHP and Symfony2. Do it simpleAsynchronous processing with PHP and Symfony2. Do it simple
Asynchronous processing with PHP and Symfony2. Do it simple
 
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupScaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
 
Scaling symfony apps
Scaling symfony appsScaling symfony apps
Scaling symfony apps
 
Расширенное кеширование в Doctrine2
Расширенное кеширование в Doctrine2Расширенное кеширование в Doctrine2
Расширенное кеширование в Doctrine2
 
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
 
Theres a rabbit on my symfony
Theres a rabbit on my symfonyTheres a rabbit on my symfony
Theres a rabbit on my symfony
 
Behat c'est plus que ça | Behat is more than that
Behat c'est plus que ça | Behat is more than thatBehat c'est plus que ça | Behat is more than that
Behat c'est plus que ça | Behat is more than that
 
Symfony 2 : Performances et Optimisations
Symfony 2 : Performances et OptimisationsSymfony 2 : Performances et Optimisations
Symfony 2 : Performances et Optimisations
 
Symfonytn
SymfonytnSymfonytn
Symfonytn
 
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreSymfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
 
Макс Волошин: Php + shell = ♥
Макс Волошин: Php + shell = ♥Макс Волошин: Php + shell = ♥
Макс Волошин: Php + shell = ♥
 
Keeping up with PHP
Keeping up with PHPKeeping up with PHP
Keeping up with PHP
 
How to Clear Cache in a Symfony Cross Application
How to Clear Cache in a Symfony Cross ApplicationHow to Clear Cache in a Symfony Cross Application
How to Clear Cache in a Symfony Cross Application
 
Symfony y Admin Generator
Symfony y Admin GeneratorSymfony y Admin Generator
Symfony y Admin Generator
 
What RabbitMQ Can Do For You (Nomad PHP May 2014)
What RabbitMQ Can Do For You (Nomad PHP May 2014)What RabbitMQ Can Do For You (Nomad PHP May 2014)
What RabbitMQ Can Do For You (Nomad PHP May 2014)
 
Cómo alcanzar el éxito SEO Internacional #SEOnthebeach
Cómo alcanzar el éxito SEO Internacional #SEOnthebeachCómo alcanzar el éxito SEO Internacional #SEOnthebeach
Cómo alcanzar el éxito SEO Internacional #SEOnthebeach
 
Mis primeros pasos con Symfony 2
Mis primeros pasos con Symfony 2Mis primeros pasos con Symfony 2
Mis primeros pasos con Symfony 2
 
How GZIP compression works - JS Conf EU 2014
How GZIP compression works - JS Conf EU 2014How GZIP compression works - JS Conf EU 2014
How GZIP compression works - JS Conf EU 2014
 

Similar to Speed up your Symfony2 application and build awesome features with Redis

Redis everywhere - PHP London
Redis everywhere - PHP LondonRedis everywhere - PHP London
Redis everywhere - PHP LondonRicard Clau
 
Redis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHPRedis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHPRicard Clau
 
Big Data! Great! Now What? #SymfonyCon 2014
Big Data! Great! Now What? #SymfonyCon 2014Big Data! Great! Now What? #SymfonyCon 2014
Big Data! Great! Now What? #SymfonyCon 2014Ricard Clau
 
Your backend architecture is what matters slideshare
Your backend architecture is what matters slideshareYour backend architecture is what matters slideshare
Your backend architecture is what matters slideshareColin Charles
 
Big Data Developers Moscow Meetup 1 - sql on hadoop
Big Data Developers Moscow Meetup 1  - sql on hadoopBig Data Developers Moscow Meetup 1  - sql on hadoop
Big Data Developers Moscow Meetup 1 - sql on hadoopbddmoscow
 
Redis Streams - Fiverr Tech5 meetup
Redis Streams - Fiverr Tech5 meetupRedis Streams - Fiverr Tech5 meetup
Redis Streams - Fiverr Tech5 meetupItamar Haber
 
Intro to big data choco devday - 23-01-2014
Intro to big data   choco devday - 23-01-2014Intro to big data   choco devday - 23-01-2014
Intro to big data choco devday - 23-01-2014Hassan Islamov
 
Scaling with Symfony - PHP UK
Scaling with Symfony - PHP UKScaling with Symfony - PHP UK
Scaling with Symfony - PHP UKRicard Clau
 
Modern software architectures - PHP UK Conference 2015
Modern software architectures - PHP UK Conference 2015Modern software architectures - PHP UK Conference 2015
Modern software architectures - PHP UK Conference 2015Ricard Clau
 
Why databases cry at night
Why databases cry at nightWhy databases cry at night
Why databases cry at nightMichael Yarichuk
 
Share winter 2016 encryption
Share winter 2016 encryptionShare winter 2016 encryption
Share winter 2016 encryptionbigendiansmalls
 
New York REDIS Meetup Welcome Session
New York REDIS Meetup Welcome SessionNew York REDIS Meetup Welcome Session
New York REDIS Meetup Welcome SessionAleksandr Yampolskiy
 
Designs, Lessons and Advice from Building Large Distributed Systems
Designs, Lessons and Advice from Building Large Distributed SystemsDesigns, Lessons and Advice from Building Large Distributed Systems
Designs, Lessons and Advice from Building Large Distributed SystemsDaehyeok Kim
 
SFScon14: Schrödinger’s elephant: why PostgreSQL can solve all your database ...
SFScon14: Schrödinger’s elephant: why PostgreSQL can solve all your database ...SFScon14: Schrödinger’s elephant: why PostgreSQL can solve all your database ...
SFScon14: Schrödinger’s elephant: why PostgreSQL can solve all your database ...South Tyrol Free Software Conference
 
What's new with enterprise Redis - Leena Joshi, Redis Labs
What's new with enterprise Redis - Leena Joshi, Redis LabsWhat's new with enterprise Redis - Leena Joshi, Redis Labs
What's new with enterprise Redis - Leena Joshi, Redis LabsRedis Labs
 

Similar to Speed up your Symfony2 application and build awesome features with Redis (20)

Redis everywhere - PHP London
Redis everywhere - PHP LondonRedis everywhere - PHP London
Redis everywhere - PHP London
 
Redis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHPRedis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHP
 
Redis Labcamp
Redis LabcampRedis Labcamp
Redis Labcamp
 
Big Data! Great! Now What? #SymfonyCon 2014
Big Data! Great! Now What? #SymfonyCon 2014Big Data! Great! Now What? #SymfonyCon 2014
Big Data! Great! Now What? #SymfonyCon 2014
 
REDIS327
REDIS327REDIS327
REDIS327
 
Your backend architecture is what matters slideshare
Your backend architecture is what matters slideshareYour backend architecture is what matters slideshare
Your backend architecture is what matters slideshare
 
Big Data Developers Moscow Meetup 1 - sql on hadoop
Big Data Developers Moscow Meetup 1  - sql on hadoopBig Data Developers Moscow Meetup 1  - sql on hadoop
Big Data Developers Moscow Meetup 1 - sql on hadoop
 
Redis Streams - Fiverr Tech5 meetup
Redis Streams - Fiverr Tech5 meetupRedis Streams - Fiverr Tech5 meetup
Redis Streams - Fiverr Tech5 meetup
 
Intro to big data choco devday - 23-01-2014
Intro to big data   choco devday - 23-01-2014Intro to big data   choco devday - 23-01-2014
Intro to big data choco devday - 23-01-2014
 
Scaling with Symfony - PHP UK
Scaling with Symfony - PHP UKScaling with Symfony - PHP UK
Scaling with Symfony - PHP UK
 
Modern software architectures - PHP UK Conference 2015
Modern software architectures - PHP UK Conference 2015Modern software architectures - PHP UK Conference 2015
Modern software architectures - PHP UK Conference 2015
 
Redis in 20 minutes
Redis in 20 minutesRedis in 20 minutes
Redis in 20 minutes
 
Why databases cry at night
Why databases cry at nightWhy databases cry at night
Why databases cry at night
 
Share winter 2016 encryption
Share winter 2016 encryptionShare winter 2016 encryption
Share winter 2016 encryption
 
New York REDIS Meetup Welcome Session
New York REDIS Meetup Welcome SessionNew York REDIS Meetup Welcome Session
New York REDIS Meetup Welcome Session
 
Designs, Lessons and Advice from Building Large Distributed Systems
Designs, Lessons and Advice from Building Large Distributed SystemsDesigns, Lessons and Advice from Building Large Distributed Systems
Designs, Lessons and Advice from Building Large Distributed Systems
 
Oracle OpenWo2014 review part 03 three_paa_s_database
Oracle OpenWo2014 review part 03 three_paa_s_databaseOracle OpenWo2014 review part 03 three_paa_s_database
Oracle OpenWo2014 review part 03 three_paa_s_database
 
Redis acc 2015_eng
Redis acc 2015_engRedis acc 2015_eng
Redis acc 2015_eng
 
SFScon14: Schrödinger’s elephant: why PostgreSQL can solve all your database ...
SFScon14: Schrödinger’s elephant: why PostgreSQL can solve all your database ...SFScon14: Schrödinger’s elephant: why PostgreSQL can solve all your database ...
SFScon14: Schrödinger’s elephant: why PostgreSQL can solve all your database ...
 
What's new with enterprise Redis - Leena Joshi, Redis Labs
What's new with enterprise Redis - Leena Joshi, Redis LabsWhat's new with enterprise Redis - Leena Joshi, Redis Labs
What's new with enterprise Redis - Leena Joshi, Redis Labs
 

More from Ricard Clau

NoEresTanEspecial-PulpoCon22.pdf
NoEresTanEspecial-PulpoCon22.pdfNoEresTanEspecial-PulpoCon22.pdf
NoEresTanEspecial-PulpoCon22.pdfRicard Clau
 
DevOps & Infraestructura como código: Promesas Rotas
DevOps & Infraestructura como código: Promesas RotasDevOps & Infraestructura como código: Promesas Rotas
DevOps & Infraestructura como código: Promesas RotasRicard Clau
 
DevOps Barcelona Conference 2018 - Intro
DevOps Barcelona Conference 2018 - IntroDevOps Barcelona Conference 2018 - Intro
DevOps Barcelona Conference 2018 - IntroRicard Clau
 
Hashicorp at holaluz
Hashicorp at holaluzHashicorp at holaluz
Hashicorp at holaluzRicard Clau
 
What we talk about when we talk about DevOps
What we talk about when we talk about DevOpsWhat we talk about when we talk about DevOps
What we talk about when we talk about DevOpsRicard Clau
 
Building a bakery of Windows servers with Packer - London WinOps
Building a bakery of Windows servers with Packer - London WinOpsBuilding a bakery of Windows servers with Packer - London WinOps
Building a bakery of Windows servers with Packer - London WinOpsRicard Clau
 
Escalabilidad y alto rendimiento con Symfony2
Escalabilidad y alto rendimiento con Symfony2Escalabilidad y alto rendimiento con Symfony2
Escalabilidad y alto rendimiento con Symfony2Ricard Clau
 
Betabeers Barcelona - Buenas prácticas
Betabeers Barcelona - Buenas prácticasBetabeers Barcelona - Buenas prácticas
Betabeers Barcelona - Buenas prácticasRicard Clau
 
Desymfony - Servicios
Desymfony  - ServiciosDesymfony  - Servicios
Desymfony - ServiciosRicard Clau
 

More from Ricard Clau (11)

devopsbcn23.pdf
devopsbcn23.pdfdevopsbcn23.pdf
devopsbcn23.pdf
 
devopsbcn22.pdf
devopsbcn22.pdfdevopsbcn22.pdf
devopsbcn22.pdf
 
NoEresTanEspecial-PulpoCon22.pdf
NoEresTanEspecial-PulpoCon22.pdfNoEresTanEspecial-PulpoCon22.pdf
NoEresTanEspecial-PulpoCon22.pdf
 
DevOps & Infraestructura como código: Promesas Rotas
DevOps & Infraestructura como código: Promesas RotasDevOps & Infraestructura como código: Promesas Rotas
DevOps & Infraestructura como código: Promesas Rotas
 
DevOps Barcelona Conference 2018 - Intro
DevOps Barcelona Conference 2018 - IntroDevOps Barcelona Conference 2018 - Intro
DevOps Barcelona Conference 2018 - Intro
 
Hashicorp at holaluz
Hashicorp at holaluzHashicorp at holaluz
Hashicorp at holaluz
 
What we talk about when we talk about DevOps
What we talk about when we talk about DevOpsWhat we talk about when we talk about DevOps
What we talk about when we talk about DevOps
 
Building a bakery of Windows servers with Packer - London WinOps
Building a bakery of Windows servers with Packer - London WinOpsBuilding a bakery of Windows servers with Packer - London WinOps
Building a bakery of Windows servers with Packer - London WinOps
 
Escalabilidad y alto rendimiento con Symfony2
Escalabilidad y alto rendimiento con Symfony2Escalabilidad y alto rendimiento con Symfony2
Escalabilidad y alto rendimiento con Symfony2
 
Betabeers Barcelona - Buenas prácticas
Betabeers Barcelona - Buenas prácticasBetabeers Barcelona - Buenas prácticas
Betabeers Barcelona - Buenas prácticas
 
Desymfony - Servicios
Desymfony  - ServiciosDesymfony  - Servicios
Desymfony - Servicios
 

Recently uploaded

AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyRaymond Okyere-Forson
 
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Jaydeep Chhasatia
 
Deep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampDeep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampVICTOR MAESTRE RAMIREZ
 
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLBig Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLAlluxio, Inc.
 
20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기Chiwon Song
 
online pdf editor software solutions.pdf
online pdf editor software solutions.pdfonline pdf editor software solutions.pdf
online pdf editor software solutions.pdfMeon Technology
 
Mastering Kubernetes - Basics and Advanced Concepts using Example Project
Mastering Kubernetes - Basics and Advanced Concepts using Example ProjectMastering Kubernetes - Basics and Advanced Concepts using Example Project
Mastering Kubernetes - Basics and Advanced Concepts using Example Projectwajrcs
 
About .NET 8 and a first glimpse into .NET9
About .NET 8 and a first glimpse into .NET9About .NET 8 and a first glimpse into .NET9
About .NET 8 and a first glimpse into .NET9Jürgen Gutsch
 
Kubernetes go-live checklist for your microservices.pptx
Kubernetes go-live checklist for your microservices.pptxKubernetes go-live checklist for your microservices.pptx
Kubernetes go-live checklist for your microservices.pptxPrakarsh -
 
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine HarmonyLeveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmonyelliciumsolutionspun
 
Webinar - IA generativa e grafi Neo4j: RAG time!
Webinar - IA generativa e grafi Neo4j: RAG time!Webinar - IA generativa e grafi Neo4j: RAG time!
Webinar - IA generativa e grafi Neo4j: RAG time!Neo4j
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadIvo Andreev
 
IA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeIA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeNeo4j
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesShyamsundar Das
 
Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesSoftwareMill
 
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfTobias Schneck
 
How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?AmeliaSmith90
 
eAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionseAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionsNirav Modi
 

Recently uploaded (20)

AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human Beauty
 
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
 
Deep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampDeep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - Datacamp
 
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLBig Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
 
20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기
 
online pdf editor software solutions.pdf
online pdf editor software solutions.pdfonline pdf editor software solutions.pdf
online pdf editor software solutions.pdf
 
Mastering Kubernetes - Basics and Advanced Concepts using Example Project
Mastering Kubernetes - Basics and Advanced Concepts using Example ProjectMastering Kubernetes - Basics and Advanced Concepts using Example Project
Mastering Kubernetes - Basics and Advanced Concepts using Example Project
 
About .NET 8 and a first glimpse into .NET9
About .NET 8 and a first glimpse into .NET9About .NET 8 and a first glimpse into .NET9
About .NET 8 and a first glimpse into .NET9
 
Kubernetes go-live checklist for your microservices.pptx
Kubernetes go-live checklist for your microservices.pptxKubernetes go-live checklist for your microservices.pptx
Kubernetes go-live checklist for your microservices.pptx
 
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine HarmonyLeveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
 
Webinar - IA generativa e grafi Neo4j: RAG time!
Webinar - IA generativa e grafi Neo4j: RAG time!Webinar - IA generativa e grafi Neo4j: RAG time!
Webinar - IA generativa e grafi Neo4j: RAG time!
 
Program with GUTs
Program with GUTsProgram with GUTs
Program with GUTs
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and Bad
 
IA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeIA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG time
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security Challenges
 
Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retries
 
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
 
Sustainable Web Design - Claire Thornewill
Sustainable Web Design - Claire ThornewillSustainable Web Design - Claire Thornewill
Sustainable Web Design - Claire Thornewill
 
How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?
 
eAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionseAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspections
 

Speed up your Symfony2 application and build awesome features with Redis

  • 1. SPEED UP YOUR SYMFONY2 APPLICATION AND BUILD AWESOME FEATURES WITH REDIS
  • 2. HELLO WORLD • Ricard Clau, born and grown up in Barcelona • Server engineer at Another Place Productions • Symfony2 lover and PHP believer (sometimes…) • Open-source contributor, sometimes I give talks • Twitter @ricardclau / Gmail ricard.clau@gmail.com
  • 3. AGENDA • REDIS introduction, data types and commands • Getting started with Redis in PHP / Symfony2 • Options out of the box in SncRedisBundle • Cookbooks implemented in Real World Applications • Sharding data and the new Redis Cluster
  • 4. INTRODUCTION TO REDIS And some demystifications
  • 5. WHAT IS REDIS? • REmote DIctionary Server • Created in 2009 by Salvatore Sanfilipo (@antirez) • Open source (https://github.com/antirez/redis) • Advanced in-memory key-value data-structure server • Part of the NoSQL movement, think back to structures!
  • 6. TO ME REDIS IS LIKE...
  • 7. ONLY IN-MEMORY? • Your data needs to fit in your memory • It has configurable persistence: RDB snapshots, AOF persistence logs, combine both or no persistence at all • Think like memcached on steroids with persistence • http://redis.io/topics/persistence • “Memory is the new disk, disk is the new tape”
  • 8. INTERESTING FEATURES • Master-slave replication • Pipelining to improve performance • Transactions (kind of with MULTI ... EXEC) • Scripting with LUA (~stored procedures) • Iterators for Keyspaces and SETS and HASHES (>= 2.8) !
  • 10. NO QUERIES •We communicate with Redis via commands • No indexes, no schemas, just structures under a key • Very good documentation and sandbox • All commands have their complexity documented
  • 11. DATA TYPES • Strings (binary-safe) up to 512 Mb • Lists of elements sorted by insertion order (max 2^32 - 1) • Sets supporting unions, intersections and diffs (max 2^32 - 1) • Hashes key-value pairs (max 2^32 - 1) • Sorted sets automatically ordered by score (max 2^32 - 1) • HyperLogLog to compute cardinality of BIG sets (2^64)
  • 12. STRINGS COMMANDS • GET, SET, STRLEN, APPEND • GETRANGE, SETRANGE • Bitmap operations: GETBIT, SETBIT, BITCOUNT • Counter operations: INCR, DECR, INCRBY, DECRBY • If the value is a number, Redis tries to store it efficiently
  • 13. LISTS COMMANDS Key S1 S2 S3 … SN • Order of insertion matters • Easy to implement Queues and Stacks • RPUSH, LPUSH, RPOP, LPOP • Blocking versions BLPOP, BRPOP, BRPOPLPUSH with timeout
  • 14. SETS COMMANDS Key S1 S5 S3 S2 S4 • Collection of unique unordered elements • SCARD (Size), SADD, SREM, SISMEMBER, SMEMBERS • Intersections, Unions and Diffs: SINTER, SUNION, SDIFF, SINTERSTORE, SUNIONSTORE, SDIFFSTORE • Iterators with SSCAN (Redis >= 2.8)
  • 15. HASHES COMMANDS Key K1 V1 K2 V2 K3 V3 K4 V4 • Many key-value pairs under the same key • HSET, HGET, HGETALL, HLEN, HEXISTS • Counters HINCR, HINCRBY, HINCRBYFLOAT • Iterators with HSCAN (Redis >= 2.8)
  • 16. SORTED SETS COMMANDS S4 - 1000 Key S2 - 20 S3 - 15 S1 - 0 • Collection of unique elements ordered by score • ZCARD (Size), ZADD, ZREM, ZSCORE • Ranking: ZRANGE, ZREVRANGE (optional WITHSCORES) • Iterators with ZSCAN (Redis >= 2.8)
  • 17. HYPERLOGLOG COMMANDS • Counting unique things in massive data sets using a very small amount of memory • PFADD, PFCOUNT, PFMERGE • HyperLogLog has an standard error of 0.81% • PF prefix in honor of Philippe Flajolet
  • 19. PHP CLIENTS • Predis (PHP) vs phpredis (PHP extension) • Predis is very mature, actively maintained, feature complete, extendable, composer friendly and supports all Redis versions • Phpredis is faster, but not always backwards compatible • Network latency is the biggest performance killer • http://redis.io/clients
  • 20. EASY STEPS (I) $ composer require snc/redis-bundle 1.1.* $ composer require predis/predis 0.8.* or install the phpredis extension https://github.com/nicolasff/phpredis
  • 21. EASY STEPS (II) Add the bundle to the Symfony2 kernel
  • 22. EASY STEPS (III) Add some magic to your config.yml
  • 23. EASY STEPS (IV) You can now use Redis as a Symfony2 service! ! In your controller extending SymfonyBundleFrameworkBundleControllerController.php
  • 24. EASY STEPS (V) Or inject it to your services via your services.xml
  • 25. REDIS-CLI AND MONITOR • Redis-cli to connect to a Redis instance • Experiment with http://redis.io/commands •With Monitor we can watch live activity!
  • 26. SNCREDISBUNDLE So many options out of the box!
  • 28. PHP SESSION SUPPORT ! TTL is the session lifetime, Redis expires it for you Session Locking implementation (not optimal) Added not so many months ago
  • 29. LOCKING PROBLEM • Problem in heavy-write applications: 2 almost concurrent requests trying to update same records • Concurrent AJAX requests for the same user timeline R1read R1 R2 R2save R2read R1save R1 updates are lost!!!!!
  • 30. DOCTRINE CACHING Implemented with SET / SETEX / GET Be careful with expirations! No expiring Possibly better use APC entities data (annotations / xml / yaml) RecordSets Setting TTL explicitly DQL parsing
  • 31. MONOLOG (I) Implemented with LISTS using RPUSH Be careful with memory!
  • 32. MONOLOG (II) And add a new monolog handler using the service Level recommended at least warning
  • 33. SWIFTMAILER SPOOL Implemented with LISTS using RPUSH Serialized Swift_Mime_Messages in the list
  • 34. COOKBOOKS From Real World applications
  • 35. REDIS AS A QUEUE • Using Lists and LPUSH / RPOP instructions •We can have different languages accessing data • I used this to send OpenGraph requests to Facebook (REALLY slow API) with Python daemons • If you need some advanced message queuing features check RabbitMQ (@cakper last month´s talk) and others
  • 36. REAL-TIME DASHBOARDS •We can use hashes to group many stats under one key • Most of the times we have counters: HINCRBY “stats" <key> <increment> • HMGET “stats” <key1> <key2> ... to retrieve values and HMSET “stats” “stat1” <value1> “stat2” <value2> to set them • HGETALL to get the full hash
  • 37. LEADERBOARDS • Super-easy with Redis, heavy consuming with other systems • Each board with a single key, using sorted sets • ZINCRBY “rankXXX” <increment> <userId> • Top N ZREVRANGE “rankXXX” 0 N [WITHSCORES] • You can store several millions of members under 1 key
  • 38. WHO IS ONLINE? (I) •We can use SETS to achieve it! • One set for every minute, SADD <minute> <userId> Time +1m +2m +3m 2 2 7 4 1 2 3 1 1 5 3 1 SUNION 1 2 3 5 7 4
  • 39. WHO IS ONLINE? (II) • Online users == everyone active in the last N minutes • SUNION <now> <now-1> <now-2> ... • SUNIONSTORE “online” <now> <now-1> <now-2> ... • Number of users: SCARD “online” • Obtain online users with SMEMBERS “online”
  • 40. FRIENDS ONLINE? • If we store user´s friends in a SET with key friends-<user-id> • Friends online: SINTERSTORE “friends-<userid>-online” “online” “friends-<userid>” ! ! 1 7 3 5 2 4 15 1 ! • Imagine how you would do it without Redis! 9 3 10 7 ONLINE FRIENDS-12 SINTER FRIENDS-12-ONLINE
  • 41. SHARDING / CLUSTERING This is when it gets tricky…
  • 42. NEEDS TO FIT IN MEMORY • Redis Cluster will be available in 3.0 (currently RC1) • Proxy servers: Twemproxy (also for memcached) • Client-side partitioning (supported in many clients) • Sharding strategies (range vs hash partitioning) • Presharding can help scaling horizontally
  • 43. CONFIGS WARNING! ! The default behaviour is RandomDistributionStrategy! PHPRedis has a RedisArray class for client-side sharding but this is not supported yet in the bundle!
  • 44. 1-99999 100000-199999 200000-299999 300000-399999 id % 4 == 0 id % 4 == 1 id % 4 == 2 id % 4 == 3 Easy to predict scale Load not properly distributed Load distributed ok Fairly easy to reshard RANGE PARTITIONING May work in some cases, not a silver bullet
  • 45. hash(key) % 4 == 0 hash(key) % 4 == 1 hash(key) % 4 == 2 hash(key) % 4 == 3 Distribution also depending on hash algorithm Complicated resharding HASH PARTITIONING Better distribution... but still issues If few keys, it also becomes useless HASH CRC16 CRC32 MD5 SHA1 MURMUR3 ! DIST MODULUS KETAMA
  • 46. Many Redis instances in one PRESHARDING Maybe overengineered initial server ! When needed, just split it into more servers and you don´t need resharding!!! ! Be careful configuring memory limits
  • 47. REDIS CLUSTER • Shards the dataset among N nodes • Has a responsive failover in order to survive certain failures (this was partially covered already with Sentinel) • Ability to reshard keys internally • Neither CP nor AP, eventually consistent, not very resistant to network partitions in some scenarios • Many disagree with some of the decisions and tradeoffs
  • 48. FINAL THOUGHTS When and when not to consider Redis
  • 49. REDIS IS PERFECT FOR... • Intensive read-write data applications • Temporary stored data • Data that fits in memory • Problems that fit Redis built-in data types • Predictability in performance needed
  • 50. BUT IS NOT SUITABLE WHEN.. • Big data sets, archive data • Relational data (RDBMS are absolutely fine to scale) •We don´t know how we will access data • Reporting applications (no where clauses) • It gets tricky for distributed applications (replication, clustering) • ALWAYS choose the right tool for the job!
  • 51. SPECIAL THANKS • Ronny López (@ronnylt) & Alonso Vidales (@alonsovidales) • Salvatore Sanfilippo (@antirez) • Henrik Westphal (https://github.com/snc) • Danielle Alessandri (https://github.com/nrk) • Nicolas Favre-Felix (https://github.com/nicolasff) • Of course, to all of you for being here today!
  • 52. QUESTIONS? • Twitter: @ricardclau • E-mail: ricard.clau@gmail.com • Github: https://github.com/ricardclau • Blog about PHP and Symfony2: http://www.ricardclau.com