SlideShare una empresa de Scribd logo
1 de 55
Descargar para leer sin conexión
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)

Más contenido relacionado

Destacado

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
 

Destacado (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
 

Último

A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
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
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
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
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
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
 
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
 
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
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
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
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 

Último (20)

A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software 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...
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
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
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
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
 
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
 
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
 
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
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
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
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
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
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 

Rediscover Speed with Redis(and PHP)