SlideShare ist ein Scribd-Unternehmen logo
1 von 55
Downloaden Sie, um offline zu lesen
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)

Weitere ähnliche Inhalte

Andere mochten auch

Europycon2011: Implementing distributed application using ZeroMQ
Europycon2011: Implementing distributed application using ZeroMQEuropycon2011: Implementing distributed application using ZeroMQ
Europycon2011: Implementing distributed application using ZeroMQ
fcrippa
 

Andere mochten auch (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
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 

Rediscover Speed with Redis(and PHP)