SlideShare a Scribd company logo
1 of 55
Download to read offline
Rediscover Speed With
Redis (and PHP)
Errazudin Ishak
Agenda
About Me
What on earth
For what reason
So how to do that
Can I use it with
Ok, now what
Summary
ABOUT ME
Day job
Staff Engineer @ Mimos Bhd Malaysia
Focuses on web application development,
  deployment, performance, security and
  stability.
I was here..
2009
foss.my , MyGOSSCON

2010
Entp. PHP Techtalk, BarcampKL, PHP Meetup, MOSC2010,
   PHP Northwest UK, MyGOSSCON

2011
INTAN Tech Update, Wordpress Conf. Asia, Joomla! Day, MOSC,
   OWASP Day

2012
OWASP Appsec Asia Pacific, Australia
WHAT ON EARTH
NoSQL Family
Key value stores : Redis, Voldemort,
 Cassandra
NoSQL Family
Column oriented : cass, hbase
NoSQL Family
Doc collection db : CouchDB, MongoDB
NoSQL Family
Graph DB : Neo4j, AllegroGraph
Redis
REmote Dictionary Server
Advanced Key-value store
Disk backed In-memory database (with virt
  mem)
High write throughput (30-150k ops/sec)
Data structures (list, hashes, sets, atomic
  ops)
Redis, unique?
Simple, lightweight
In memory (RAM).. Fast, fast, fast (very!)
Disk-backed, background writes
Master-slave config.
Multi language support
FOR WHAT REASON
Source : http://goo.gl/CM7wq




      “Memory is the new disk. Disk is the
           new tape.” - Jim Gray
Source : http://www.infoq.com/news/2008/06/ram-is-disk
Issue : Write heavy workload
Scaling reads : easy
Scaling write : headache
Advanced key-value store
Persistence
Replication
Transaction
Pipelining
Publish/Subscribe
Use cases
Realtime analytics
Caching server (memcached on steroid)
Queue (scheduler, take time to process)
Clicks (eg. Reddit, digg)
Who




  “We also use Redis extensively; it
powers our main feed, our activity feed,
       our sessions system…”
Who
Who
• flickr
Who
Who
Who
SO HOW TO DO THAT
Get, Set.. Go!
Installation
Download, extract and compile
http://redis.io/download

…and redis-server and redis-cli, ready to
 rumble
Get, Set.. Go!
$ wget http://redis.googlecode.com/files/redis-
  2.4.15.tar.gz
$ tar xzf redis-2.4.15.tar.gz
$ cd redis-2.4.15
$ make
Data Structure server

                 Strings
         SET, GET, SETRANGE, INCR, DECR


                   Lists
         LPUSH, RPUSH, RPOP, LRANGE…


                    Sets
        SADD, SINTER, SMEMBER, ZADD …



                 Hashes
             HSET, HMSET, HGETALL
Strings
Basic
512MB
As atomic counters
Append to Strings
Random access
Encode lots with little space
Lists
List of Strings

Max length of a list is 232 - 1 elements
 (4294967295, more than 4 billion of
 elements per list).
Sets
Collection of Strings (unordered)

Support a number of server side commands
  to compute sets

Max number of members in a set is 232 - 1
 (4294967295, more than 4 billion of
 members per set).
Hashes
Maps between string fields and string
 values
CAN I USE IT WITH …
PHP : Strings
$src/redis-cli
redis> set hello earth
OK
redis> get hello
“earth”

<?php
$redis = new Redis();
$redis->connect('127.0.0.1',6379);
$redis->set(„hello',„earth');
$stored = $redis->get(„hello');
echo $stored;
PHP : Strings
$src/redis-cli
redis>set mosc"{"a":"1","b":"2"}“
OK
redis>get mosc
"{"a":"1","b":"2"}“

<?php
$redis = new Redis();
$redis->connect('127.0.0.1',6379);
$data = array('a'=>'1','b'=>'2');
$json = json_encode($data);
$redis->set(„mosc',$json);
$stored = $redis->get(„mosc');
echo $stored;
PHP : Lists
redis>LPUSH mylist “earth"(integer)1
redis>LPUSH mylist "hello"(integer)2
//[„earth','hello']
redis>LRANGE mylist 0-1
1)"hello“
2)“earth"
PHP : Lists
<?php
$redis = new Redis();
$redis->connect('127.0.0.1',6379);
$redis->delete('key1');
$redis->rpush('key1','A');//returns 1
$redis->rpush('key1','B');//returns 2
$redis->rpush('key1','C');//returns 3
$redis->rpush('key1','A');//returns 4
/*key1nowpointstothefollowinglist:['A','B','C','A']*/
PHP : Sets
<?php
$redis = new Redis();
$redis->connect('127.0.0.1',6379);
$redis->delete('key2');
$redis->sadd('key2','A');//returns 1
$redis->sadd('key2','B');//returns 2
$redis->sadd('key2','C');//returns 3
$redis->sadd('key2','A');//returns false
/*key2nowpointstothefollowinglist:['A','B','C']*/
PHP : Hashes
redis>hmset firsthash a "1“ b “2“ c "3“ d "4“
OK
redis>hget firsthash c
"3“
redis>hset firsthash e "5“
(integer) 1
redis>hget firsthash e
"5“
redis>hget firsthash d
"4"
PHP : Hashes
<?php
$redis = new Redis();
$redis->connect('127.0.0.1',6379);
$redis->delete('user:1');
$redis->hmset('user:1',
array('name'=>„Zack','salary'=>3000));
//Give Zack a $200 Raise:
$redis->hincrby('user:1','salary',200);
PHP : Hashes
<?php
$redis = new Redis();
$redis->connect('127.0.0.1',6379);
$redis->hmset('user:2',
array('name'=>„Ali','salary'=>5000));
$redis->hmset('user:3',
array('name'=>„Jonah','salary'=>6000));
$uid=3;
$user=$redis->hgetall('user:'.$uid)
//{name:„Jonah',salary:6000}
echo $user['salary'];//6000
PHP : Pub/Sub
redis>subscribe chn801




redis>subscribe chn611
PHP : Pub/Sub
redis>publish chn801 “Kelantan 6-0 Perak”




redis>subscribe chn801
Reading messages…
1) “subscribe”
2) “chn801”
3) (integer) 1
1) “message”
2) “chn801”
3) “Kelantan 6-0 Perak”
PHP Clients
Predis
https://github.com/nrk/predis

Phpredis
https://github.com/nicolasff/phpredis
OK, NOW WHAT
Source : http://goo.gl/sPZQ6




“Redis is more than a key-value store,
   it’s a lifestyle” – Mathias Meyer
Redis Cluster?
Target : Redis 2.6
Unstable branch – Basis/fundamental parts
Release when rock solid and useful
End of 2012?
SUMMARY
“Different technologies excel at
 different things” – Weixi Yen
Resources
Redis commands
http://redis.io/commands

Redis Manifesto
http://antirez.com/post/redis-
  manifesto.html
Resources
Redis Cookbook
Resources
http://simonwillison.net/static/2010/redis-
  tutorial/
Diving deeper?
Peter Cooper’s
http://www.scribd.com/doc/33531219/Redi
  s-Presentation

Pre-order
Redis: The Definitive Guide
(Data modeling, caching, and
messaging)
Diving deeper?
Scaling Redis
http://petrohi.me/post/6323289515/scalin
  g-redis

Instagram Engineering blog
http://instagram-engineering.tumblr.com/
Rediscover Speed with Redis(and PHP)

More Related Content

Viewers also liked

Speed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with RedisSpeed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with RedisRicard Clau
 
Europycon2011: Implementing distributed application using ZeroMQ
Europycon2011: Implementing distributed application using ZeroMQEuropycon2011: Implementing distributed application using ZeroMQ
Europycon2011: Implementing distributed application using ZeroMQfcrippa
 
ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The AnswerIan Barber
 
PHP with Service BUS (RabbitMQ/Redis/MongoDB) - IMasters PHP Experience 2016
PHP with Service BUS (RabbitMQ/Redis/MongoDB) - IMasters PHP Experience 2016PHP with Service BUS (RabbitMQ/Redis/MongoDB) - IMasters PHP Experience 2016
PHP with Service BUS (RabbitMQ/Redis/MongoDB) - IMasters PHP Experience 2016Alexandre Brandão Lustosa
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationRedis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationrjsmelo
 
Overview of ZeroMQ
Overview of ZeroMQOverview of ZeroMQ
Overview of ZeroMQpieterh
 

Viewers also liked (6)

Speed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with RedisSpeed up your Symfony2 application and build awesome features with Redis
Speed up your Symfony2 application and build awesome features with Redis
 
Europycon2011: Implementing distributed application using ZeroMQ
Europycon2011: Implementing distributed application using ZeroMQEuropycon2011: Implementing distributed application using ZeroMQ
Europycon2011: Implementing distributed application using ZeroMQ
 
ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The Answer
 
PHP with Service BUS (RabbitMQ/Redis/MongoDB) - IMasters PHP Experience 2016
PHP with Service BUS (RabbitMQ/Redis/MongoDB) - IMasters PHP Experience 2016PHP with Service BUS (RabbitMQ/Redis/MongoDB) - IMasters PHP Experience 2016
PHP with Service BUS (RabbitMQ/Redis/MongoDB) - IMasters PHP Experience 2016
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationRedis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your application
 
Overview of ZeroMQ
Overview of ZeroMQOverview of ZeroMQ
Overview of ZeroMQ
 

Recently uploaded

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
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
 
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
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
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
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
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
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 

Recently uploaded (20)

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
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!
 
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
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
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!
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 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
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 

Rediscover Speed with Redis(and PHP)