SlideShare une entreprise Scribd logo
1  sur  55
Télécharger pour lire hors ligne
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)

Contenu connexe

En vedette

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
 

En vedette (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
 

Dernier

Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 

Dernier (20)

Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

Rediscover Speed with Redis(and PHP)