SlideShare ist ein Scribd-Unternehmen logo
1 von 72
Blazing Data with Redis S!)
        By: Justin Carmony
                                     LE GO
                             ( and
edis)
About Me                      (I <3
                                      R


•   Director of Development
    for DeseretNews.com

•   CIO of CEVO

•   I Make (and Break)
    Web Stuff

•   Focus on Scalable,
    Real-time Websites
    & APIs
About Presentation
•   We’ll ask for questions
    several times during
    presentation & the end.

•   I will post links, slides,
    resource, etc.

•   Goal: Educate & Inspire
    you on how, when, and
    why to use Redis!
by
         rt e
     S ta th
  ts ing
Le ur
  eas ence
M udi
    A
u ta
          abo em
        lk obl
      Ta Pr
  t’s
Le mon
C o m
in ja
         N
       a e
    re m
  u’ so
Yo e
   A w oper
      evel
    D
to
                 nt e
                a n
              W nli
            e
           W kO
             ac ers!
           Tr S
               U
  Bos
Rea  s: “W
   l-Ti e W
       me    ant
          Da
            ta!”
in ja
                    N
                  a e
               re m
             u’ so
           Yo e
              A w oper
                 evel
               D



We Want To Know Who
 Is Viewing Our Site!
“I’ll Just Add a Table
     to MySQl....”
Real-Time Data
Real-Time Data

         •   High Volume Writes

         •   High Volume Reads

         •   Low Latency / Delay

         •   Grows Exponentially
             compared to Rest of
             your Data
Traditional Data Stores
•   Examples: Databases (i.e.
    MySQL, Postgre)

•   Writing is Resource
    Intensive

•   Stored on Disk (aka
    Slower)

•   Slower as Volume Grows                   ds...)
                                           or
                                     the rw
•   Challenge for Replication
                                (i no
olu me
                  ighV
             ith H ites
          s w Wr
       wn s &
 el tdo ead
M       R
Many NoSQL Solutions
Redis - Built for Speed
•   Key-Value Storage

•   In-Memory

•
•
•
•                                     nd...)
                                  seco
                          ai   ta
                        (W
Isn’t This Just Memcached?
o!
        N

Isn’t This Just Memcached?
Redis - Built for Speed
•   Key-Value Storage

•   In-Memory

•   Persistence

•   Multiple Data Types

•   Transactions

•   Pub/Sub w/ Blocking                    ast ...)
                                 it ’s F
                          (and
Extremely Fast...
Ludicrous Speed Fast
0+ s
         ,00 rite
     1 00 W
        s & ond
      ad ec
    Re r S
       Pe




Ludicrous Speed Fast
It’s gone Plaid!
To
   w is
H o
     R ed
U se
Step One:
                 Install & Run
•   Linux & Mac: Compile
    from Source

    •   No Dependencies

    •   make && make install

•   Windows

    •   Download Binaries

    •   Compile? Best of Luck
Running Redis
•   Run: redis-server

•   Can use configuration
    file

•   Run as a “service”:
    http://redis.io/topics/
    quickstart

•   redis-cli to try out
    commands
Step Two:
Understand Keys
Redis Keys
• Keys MUST be UNIQUE
• Keys are Binary Safe Strings
• Super Long Keys (i.e. 1024 bytes) are costly to
  look up

• Cryptic Short Keys (i.e. u:1000:pwd) have
  little performance improvement over a
  descriptive key (i.e. user:1000:password)
Step Three:
Thinking Key-Value
This is not an RMDBS

•   It’s All About the Keys,
    Not the Values

•   There is no “Querying”

•   There are no “Indexes”

•   There are no “Schemas”
e nt
  oc um ta!
D      D a
 Yo ur
Step Four: Get to Know
    your Data Types g Your
                          in !
                        ow ces
                     Kn Pie
                L ike go
                     Le
Redis Strings

•   Store Simple Strings

•   Binary Safe

•   Great for JSON

•   Advanced
    Commands
Data-Type “Matrix”

              Sorted   Unsorted


              Sorted
Comparable               Sets
               Sets


Stand Alone    Lists    Hashes
Quick Variable Guide
•   Hashes - Small in Size,Very
    Efficient

•   Lists - Awesome Queues,
    Size Doesn’t Affect
    Performance

•   Sets - Great for
    Intersecting with others

•   Sorted Sets - Use to Keep
    “Indexes”, Sorts using
    Scores
Step Five:
Learn the Commands
Learning the
               Commands
•   Generic Commands for
    All Keys

•   Commands for Each
    Data Type

•   Each Command has
    Big O Notation for
    Performance

•   Simple,Yet Powerful
ive
      act s
  ter ple
In m
  E xa
g It
     tin her
 ut et
P      g
A ll To
Using Redis With PHP
•   Predis
    •   PHP Library
    •   Easy to Use
    •   Very Fast to Update
        New Features
•   phpredis
    •   PHP Extension
                                          ing
    •   Faster, but requires         Be Us
        compiling module        e ’ll dis
                               W Pre
Example: Simple Caching
Simple Cache
•   Data Types:

    •   Strings

•   Commands:

    •   SETEX <key> <seconds to expire> <value>

    •   GET <key>

    •   EXPIREAT <key> <timestamp>
Connecting
<?php

// Include the Predis Autoloader
require 'predis/lib/Predis/Autoloader.php';

// Register the Autoloader
PredisAutoloader::register();

// Create a Client with defaults
$redis = new PredisClient();

// Create with Connection String
$redis = new PredisClient('tcp://10.0.0.1:6379');

/** Our Examples Will Assume This Is Already Done **/
Simple Cache
$key = 'cache.user:justin';

$data_str = $redis->get($key);

if($data_str)
{
! $data = unserialize($data_str);
}
else
{
! // Really Expensive Method of Getting This Data
! $data = MyDatabase::GetExpensiveData();
! $redis->setex($key, 60, serialize($data));
}

/* Do something with the $data */
Example: Online Users
•   Data Types:

    •   Sets

•   Commands:

    •   SADD <key> <value>

    •   SUNION <key1> <key2> <key3> <key....>

    •   EXPIRE <key> <timestamp>
Example: Users Online
Marking Users Online
  /* Store Current User */
  // Current User ID
  $user_id = 1234;

// Get Current Time
$now = time();
$min = date("i",$now);

// Generate the Key
$key = "online:".$min;

// Adding user to online users
$redis->sadd($key, $user_id);
$redis->expire($key, 60 * 10); // Expire in 10 minutes
Getting Online Users
/* Getting Onling Users */
$keys = array();
// Get Current Time
$now = time();
$min = date("i",$now);

$count = 0;
$minutes_ago = 5;
while($count < $minutes_ago)
{
!   $keys[] = "online:".$min;
!
!   $count++;
!   $min--;
!   if($min < 0)
!   {
!   !    $min = 59;
!   }
}

$scmd = $redis->createCommand("sunion",$keys);
$online_ids = $redis->executeCommand($scmd);
Example: Friends Online

•   Data Types:

    •   Sets

•   Additional Commands:

    •   SUNIONSTORE <dest> <key1> <key2> <key....>

    •   SINTER <key1> <key2> <key...>
My Friends Online
/* My Friends Online */
$keys = array('online_users');
$user_id = '1234';
// Get Current Time
$min = date("i",time());

$count = 0;
$minutes_ago = 5;
while($count < $minutes_ago)
{
!   $keys[] = "online:".$min;
!   $count++;
!   $min--;
!   if($min < 0) { $min = 59; }
}

// SUNIONSTORE online_users online:10 online:9 online:8 online:7 online:6
$scmd = $redis->createCommand("sunionstore",$keys);
$redis->executeCommand($scmd);

$online_friend_ids = $redis->sinter('online_users'
!   , 'user:'.$user_id.'.friend_ids');
Under The Hood
Few Things About Redis
• Single Threaded
• Can “Shard” For More Capacity /
  Performance
• All Commands are Atomic
• Transactions for Multiple Atomic
  Commands
• Pipelining for High Performance
Persistence

• Snapshots on a Configurable Schedule
 • Will “fork” the process and write the
    DataSet to Disk
• Append-Only File
• Will Let You Survive a “Reboot”
New Stuff / On The
      Horizon

• Lua Scripting (Kinda Querying)
• Redis Clustering
aL ive
        ut
      bo ?
    A
H ow emo
     D
One Redis Server
50 Servers * 8 Clients =
     400 Workers
Rackspace Cloud
          +
Salt (saltstack.org)
          +
   Redis & PHP
Demo Time!
Questions?
Your Homework
Download & Play Around with Redis!
         It’s Awesome!
More Info?
http://www.justincarmony.com/redis
Flickr Credits & Images:
        http://gim.ie/jsLJ
Thanks!
Rate My Talk (PLEASE): https://joind.in/6486

         Twitter: @JustinCarmony

             IRC: carmony
           #uphpu #phpc #salt

                 Website:
    http://www.justincarmony.com/blog

                  Email:
        justin@justincarmony.com

Weitere ähnliche Inhalte

Was ist angesagt?

Scaling Rails with Memcached
Scaling Rails with MemcachedScaling Rails with Memcached
Scaling Rails with Memcachedguest2259ea
 
[D2]java 성능에 대한 오해와 편견
[D2]java 성능에 대한 오해와 편견[D2]java 성능에 대한 오해와 편견
[D2]java 성능에 대한 오해와 편견NAVER D2
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it FastBarry Jones
 
Maximize your Cache for No Cash
Maximize your Cache for No CashMaximize your Cache for No Cash
Maximize your Cache for No CashYorick Phoenix
 
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892Deepak Sharma
 
Mongodb and Totsy - E-commerce Case Study
Mongodb and Totsy - E-commerce Case StudyMongodb and Totsy - E-commerce Case Study
Mongodb and Totsy - E-commerce Case StudyMitch Pirtle
 
CSS and image optimization
CSS and image optimizationCSS and image optimization
CSS and image optimizationStoyan Stefanov
 
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
 
A web app in pure Clojure
A web app in pure ClojureA web app in pure Clojure
A web app in pure ClojureDane Schneider
 
CouchDB for Web Applications - Erlang Factory London 2009
CouchDB for Web Applications - Erlang Factory London 2009CouchDB for Web Applications - Erlang Factory London 2009
CouchDB for Web Applications - Erlang Factory London 2009Jason Davies
 
Developing cacheable PHP applications - PHPLimburgBE 2018
Developing cacheable PHP applications - PHPLimburgBE 2018Developing cacheable PHP applications - PHPLimburgBE 2018
Developing cacheable PHP applications - PHPLimburgBE 2018Thijs Feryn
 
Gofer 200707
Gofer 200707Gofer 200707
Gofer 200707oscon2007
 
Page Performance
Page PerformancePage Performance
Page Performanceatorreno
 
Real-time searching of big data with Solr and Hadoop
Real-time searching of big data with Solr and HadoopReal-time searching of big data with Solr and Hadoop
Real-time searching of big data with Solr and HadoopRogue Wave Software
 
Dbi Advanced Talk 200708
Dbi Advanced Talk 200708Dbi Advanced Talk 200708
Dbi Advanced Talk 200708oscon2007
 
Top 10 lessons learned from deploying hadoop in a private cloud
Top 10 lessons learned from deploying hadoop in a private cloudTop 10 lessons learned from deploying hadoop in a private cloud
Top 10 lessons learned from deploying hadoop in a private cloudRogue Wave Software
 
Resource registries plone conf 2014
Resource registries plone conf 2014Resource registries plone conf 2014
Resource registries plone conf 2014Ramon Navarro
 
Transforming WordPress Search and Query Performance with Elasticsearch
Transforming WordPress Search and Query Performance with Elasticsearch Transforming WordPress Search and Query Performance with Elasticsearch
Transforming WordPress Search and Query Performance with Elasticsearch Taylor Lovett
 

Was ist angesagt? (20)

Scaling Rails with Memcached
Scaling Rails with MemcachedScaling Rails with Memcached
Scaling Rails with Memcached
 
[D2]java 성능에 대한 오해와 편견
[D2]java 성능에 대한 오해와 편견[D2]java 성능에 대한 오해와 편견
[D2]java 성능에 대한 오해와 편견
 
Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it Fast
 
Maximize your Cache for No Cash
Maximize your Cache for No CashMaximize your Cache for No Cash
Maximize your Cache for No Cash
 
Websites On Speed
Websites On SpeedWebsites On Speed
Websites On Speed
 
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
 
Mongodb and Totsy - E-commerce Case Study
Mongodb and Totsy - E-commerce Case StudyMongodb and Totsy - E-commerce Case Study
Mongodb and Totsy - E-commerce Case Study
 
Intro to HTML 5 / CSS 3
Intro to HTML 5 / CSS 3Intro to HTML 5 / CSS 3
Intro to HTML 5 / CSS 3
 
CSS and image optimization
CSS and image optimizationCSS and image optimization
CSS and image optimization
 
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
 
A web app in pure Clojure
A web app in pure ClojureA web app in pure Clojure
A web app in pure Clojure
 
CouchDB for Web Applications - Erlang Factory London 2009
CouchDB for Web Applications - Erlang Factory London 2009CouchDB for Web Applications - Erlang Factory London 2009
CouchDB for Web Applications - Erlang Factory London 2009
 
Developing cacheable PHP applications - PHPLimburgBE 2018
Developing cacheable PHP applications - PHPLimburgBE 2018Developing cacheable PHP applications - PHPLimburgBE 2018
Developing cacheable PHP applications - PHPLimburgBE 2018
 
Gofer 200707
Gofer 200707Gofer 200707
Gofer 200707
 
Page Performance
Page PerformancePage Performance
Page Performance
 
Real-time searching of big data with Solr and Hadoop
Real-time searching of big data with Solr and HadoopReal-time searching of big data with Solr and Hadoop
Real-time searching of big data with Solr and Hadoop
 
Dbi Advanced Talk 200708
Dbi Advanced Talk 200708Dbi Advanced Talk 200708
Dbi Advanced Talk 200708
 
Top 10 lessons learned from deploying hadoop in a private cloud
Top 10 lessons learned from deploying hadoop in a private cloudTop 10 lessons learned from deploying hadoop in a private cloud
Top 10 lessons learned from deploying hadoop in a private cloud
 
Resource registries plone conf 2014
Resource registries plone conf 2014Resource registries plone conf 2014
Resource registries plone conf 2014
 
Transforming WordPress Search and Query Performance with Elasticsearch
Transforming WordPress Search and Query Performance with Elasticsearch Transforming WordPress Search and Query Performance with Elasticsearch
Transforming WordPress Search and Query Performance with Elasticsearch
 

Ähnlich wie Blazing Data With Redis (and LEGOS!)

DSpace Under the Hood
DSpace Under the HoodDSpace Under the Hood
DSpace Under the HoodDuraSpace
 
Scaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQLScaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQLRichard Schneeman
 
PlayNice.ly: Using Redis to store all our data, hahaha (Redis London Meetup)
PlayNice.ly: Using Redis to store all our data, hahaha (Redis London Meetup)PlayNice.ly: Using Redis to store all our data, hahaha (Redis London Meetup)
PlayNice.ly: Using Redis to store all our data, hahaha (Redis London Meetup)Adam Charnock
 
SDEC2011 NoSQL concepts and models
SDEC2011 NoSQL concepts and modelsSDEC2011 NoSQL concepts and models
SDEC2011 NoSQL concepts and modelsKorea Sdec
 
Php johannesburg meetup - talk 2014 - scaling php in the enterprise
Php johannesburg   meetup - talk 2014 - scaling php in the enterprisePhp johannesburg   meetup - talk 2014 - scaling php in the enterprise
Php johannesburg meetup - talk 2014 - scaling php in the enterpriseSarel van der Walt
 
Redis - The Universal NoSQL Tool
Redis - The Universal NoSQL ToolRedis - The Universal NoSQL Tool
Redis - The Universal NoSQL ToolEberhard Wolff
 
Redis everywhere - PHP London
Redis everywhere - PHP LondonRedis everywhere - PHP London
Redis everywhere - PHP LondonRicard Clau
 
The things we found in your website
The things we found in your websiteThe things we found in your website
The things we found in your websitehernanibf
 
DevOps Columbus Meetup Kickoff - Infrastructure as Code
DevOps Columbus Meetup Kickoff - Infrastructure as CodeDevOps Columbus Meetup Kickoff - Infrastructure as Code
DevOps Columbus Meetup Kickoff - Infrastructure as CodeMichael Ducy
 
Redis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHPRedis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHPRicard Clau
 
Ops Jumpstart: MongoDB Administration 101
Ops Jumpstart: MongoDB Administration 101Ops Jumpstart: MongoDB Administration 101
Ops Jumpstart: MongoDB Administration 101MongoDB
 
NoSQL for great good [hanoi.rb talk]
NoSQL for great good [hanoi.rb talk]NoSQL for great good [hanoi.rb talk]
NoSQL for great good [hanoi.rb talk]Huy Do
 
What Drove Wordnik Non-Relational?
What Drove Wordnik Non-Relational?What Drove Wordnik Non-Relational?
What Drove Wordnik Non-Relational?DATAVERSITY
 
Lightning Talk: What You Need to Know Before You Shard in 20 Minutes
Lightning Talk: What You Need to Know Before You Shard in 20 MinutesLightning Talk: What You Need to Know Before You Shard in 20 Minutes
Lightning Talk: What You Need to Know Before You Shard in 20 MinutesMongoDB
 
eMusic: WordPress in the Enterprise
eMusic: WordPress in the EnterpriseeMusic: WordPress in the Enterprise
eMusic: WordPress in the EnterpriseScott Taylor
 
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?DATAVERSITY
 
Devops kc meetup_5_20_2013
Devops kc meetup_5_20_2013Devops kc meetup_5_20_2013
Devops kc meetup_5_20_2013Aaron Blythe
 

Ähnlich wie Blazing Data With Redis (and LEGOS!) (20)

DSpace Under the Hood
DSpace Under the HoodDSpace Under the Hood
DSpace Under the Hood
 
Scaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQLScaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQL
 
Why ruby and rails
Why ruby and railsWhy ruby and rails
Why ruby and rails
 
PlayNice.ly: Using Redis to store all our data, hahaha (Redis London Meetup)
PlayNice.ly: Using Redis to store all our data, hahaha (Redis London Meetup)PlayNice.ly: Using Redis to store all our data, hahaha (Redis London Meetup)
PlayNice.ly: Using Redis to store all our data, hahaha (Redis London Meetup)
 
SDEC2011 NoSQL concepts and models
SDEC2011 NoSQL concepts and modelsSDEC2011 NoSQL concepts and models
SDEC2011 NoSQL concepts and models
 
Php johannesburg meetup - talk 2014 - scaling php in the enterprise
Php johannesburg   meetup - talk 2014 - scaling php in the enterprisePhp johannesburg   meetup - talk 2014 - scaling php in the enterprise
Php johannesburg meetup - talk 2014 - scaling php in the enterprise
 
Redis - The Universal NoSQL Tool
Redis - The Universal NoSQL ToolRedis - The Universal NoSQL Tool
Redis - The Universal NoSQL Tool
 
Redis everywhere - PHP London
Redis everywhere - PHP LondonRedis everywhere - PHP London
Redis everywhere - PHP London
 
The things we found in your website
The things we found in your websiteThe things we found in your website
The things we found in your website
 
DevOps Columbus Meetup Kickoff - Infrastructure as Code
DevOps Columbus Meetup Kickoff - Infrastructure as CodeDevOps Columbus Meetup Kickoff - Infrastructure as Code
DevOps Columbus Meetup Kickoff - Infrastructure as Code
 
Redis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHPRedis Everywhere - Sunshine PHP
Redis Everywhere - Sunshine PHP
 
Ops Jumpstart: MongoDB Administration 101
Ops Jumpstart: MongoDB Administration 101Ops Jumpstart: MongoDB Administration 101
Ops Jumpstart: MongoDB Administration 101
 
NoSQL for great good [hanoi.rb talk]
NoSQL for great good [hanoi.rb talk]NoSQL for great good [hanoi.rb talk]
NoSQL for great good [hanoi.rb talk]
 
What Drove Wordnik Non-Relational?
What Drove Wordnik Non-Relational?What Drove Wordnik Non-Relational?
What Drove Wordnik Non-Relational?
 
Lightning Talk: What You Need to Know Before You Shard in 20 Minutes
Lightning Talk: What You Need to Know Before You Shard in 20 MinutesLightning Talk: What You Need to Know Before You Shard in 20 Minutes
Lightning Talk: What You Need to Know Before You Shard in 20 Minutes
 
eMusic: WordPress in the Enterprise
eMusic: WordPress in the EnterpriseeMusic: WordPress in the Enterprise
eMusic: WordPress in the Enterprise
 
RavenDB in the wild
RavenDB in the wildRavenDB in the wild
RavenDB in the wild
 
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
 
Hadoop in a Windows Shop - CHUG - 20120416
Hadoop in a Windows Shop - CHUG - 20120416Hadoop in a Windows Shop - CHUG - 20120416
Hadoop in a Windows Shop - CHUG - 20120416
 
Devops kc meetup_5_20_2013
Devops kc meetup_5_20_2013Devops kc meetup_5_20_2013
Devops kc meetup_5_20_2013
 

Kürzlich hochgeladen

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 Pakistandanishmna97
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
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...apidays
 
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...Jeffrey Haguewood
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
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...DianaGray10
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
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 WorkerThousandEyes
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
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
 
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 Takeoffsammart93
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
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.pdfsudhanshuwaghmare1
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 

Kürzlich hochgeladen (20)

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
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
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...
 
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...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
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...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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...
 
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
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

Blazing Data With Redis (and LEGOS!)

  • 1. Blazing Data with Redis S!) By: Justin Carmony LE GO ( and
  • 2. edis) About Me (I <3 R • Director of Development for DeseretNews.com • CIO of CEVO • I Make (and Break) Web Stuff • Focus on Scalable, Real-time Websites & APIs
  • 3. About Presentation • We’ll ask for questions several times during presentation & the end. • I will post links, slides, resource, etc. • Goal: Educate & Inspire you on how, when, and why to use Redis!
  • 4. by rt e S ta th ts ing Le ur eas ence M udi A
  • 5. u ta abo em lk obl Ta Pr t’s Le mon C o m
  • 6. in ja N a e re m u’ so Yo e A w oper evel D
  • 7. to nt e a n W nli e W kO ac ers! Tr S U Bos Rea s: “W l-Ti e W me ant Da ta!”
  • 8. in ja N a e re m u’ so Yo e A w oper evel D We Want To Know Who Is Viewing Our Site!
  • 9. “I’ll Just Add a Table to MySQl....”
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 19. Real-Time Data • High Volume Writes • High Volume Reads • Low Latency / Delay • Grows Exponentially compared to Rest of your Data
  • 20. Traditional Data Stores • Examples: Databases (i.e. MySQL, Postgre) • Writing is Resource Intensive • Stored on Disk (aka Slower) • Slower as Volume Grows ds...) or the rw • Challenge for Replication (i no
  • 21. olu me ighV ith H ites s w Wr wn s & el tdo ead M R
  • 23. Redis - Built for Speed • Key-Value Storage • In-Memory • • • • nd...) seco ai ta (W
  • 24. Isn’t This Just Memcached?
  • 25. o! N Isn’t This Just Memcached?
  • 26. Redis - Built for Speed • Key-Value Storage • In-Memory • Persistence • Multiple Data Types • Transactions • Pub/Sub w/ Blocking ast ...) it ’s F (and
  • 29. 0+ s ,00 rite 1 00 W s & ond ad ec Re r S Pe Ludicrous Speed Fast
  • 31. To w is H o R ed U se
  • 32. Step One: Install & Run • Linux & Mac: Compile from Source • No Dependencies • make && make install • Windows • Download Binaries • Compile? Best of Luck
  • 33. Running Redis • Run: redis-server • Can use configuration file • Run as a “service”: http://redis.io/topics/ quickstart • redis-cli to try out commands
  • 35. Redis Keys • Keys MUST be UNIQUE • Keys are Binary Safe Strings • Super Long Keys (i.e. 1024 bytes) are costly to look up • Cryptic Short Keys (i.e. u:1000:pwd) have little performance improvement over a descriptive key (i.e. user:1000:password)
  • 37. This is not an RMDBS • It’s All About the Keys, Not the Values • There is no “Querying” • There are no “Indexes” • There are no “Schemas”
  • 38. e nt oc um ta! D D a Yo ur
  • 39. Step Four: Get to Know your Data Types g Your in ! ow ces Kn Pie L ike go Le
  • 40. Redis Strings • Store Simple Strings • Binary Safe • Great for JSON • Advanced Commands
  • 41. Data-Type “Matrix” Sorted Unsorted Sorted Comparable Sets Sets Stand Alone Lists Hashes
  • 42. Quick Variable Guide • Hashes - Small in Size,Very Efficient • Lists - Awesome Queues, Size Doesn’t Affect Performance • Sets - Great for Intersecting with others • Sorted Sets - Use to Keep “Indexes”, Sorts using Scores
  • 44. Learning the Commands • Generic Commands for All Keys • Commands for Each Data Type • Each Command has Big O Notation for Performance • Simple,Yet Powerful
  • 45.
  • 46. ive act s ter ple In m E xa
  • 47. g It tin her ut et P g A ll To
  • 48. Using Redis With PHP • Predis • PHP Library • Easy to Use • Very Fast to Update New Features • phpredis • PHP Extension ing • Faster, but requires Be Us compiling module e ’ll dis W Pre
  • 50. Simple Cache • Data Types: • Strings • Commands: • SETEX <key> <seconds to expire> <value> • GET <key> • EXPIREAT <key> <timestamp>
  • 51. Connecting <?php // Include the Predis Autoloader require 'predis/lib/Predis/Autoloader.php'; // Register the Autoloader PredisAutoloader::register(); // Create a Client with defaults $redis = new PredisClient(); // Create with Connection String $redis = new PredisClient('tcp://10.0.0.1:6379'); /** Our Examples Will Assume This Is Already Done **/
  • 52. Simple Cache $key = 'cache.user:justin'; $data_str = $redis->get($key); if($data_str) { ! $data = unserialize($data_str); } else { ! // Really Expensive Method of Getting This Data ! $data = MyDatabase::GetExpensiveData(); ! $redis->setex($key, 60, serialize($data)); } /* Do something with the $data */
  • 53. Example: Online Users • Data Types: • Sets • Commands: • SADD <key> <value> • SUNION <key1> <key2> <key3> <key....> • EXPIRE <key> <timestamp>
  • 55. Marking Users Online /* Store Current User */ // Current User ID $user_id = 1234; // Get Current Time $now = time(); $min = date("i",$now); // Generate the Key $key = "online:".$min; // Adding user to online users $redis->sadd($key, $user_id); $redis->expire($key, 60 * 10); // Expire in 10 minutes
  • 56. Getting Online Users /* Getting Onling Users */ $keys = array(); // Get Current Time $now = time(); $min = date("i",$now); $count = 0; $minutes_ago = 5; while($count < $minutes_ago) { ! $keys[] = "online:".$min; ! ! $count++; ! $min--; ! if($min < 0) ! { ! ! $min = 59; ! } } $scmd = $redis->createCommand("sunion",$keys); $online_ids = $redis->executeCommand($scmd);
  • 57. Example: Friends Online • Data Types: • Sets • Additional Commands: • SUNIONSTORE <dest> <key1> <key2> <key....> • SINTER <key1> <key2> <key...>
  • 58. My Friends Online /* My Friends Online */ $keys = array('online_users'); $user_id = '1234'; // Get Current Time $min = date("i",time()); $count = 0; $minutes_ago = 5; while($count < $minutes_ago) { ! $keys[] = "online:".$min; ! $count++; ! $min--; ! if($min < 0) { $min = 59; } } // SUNIONSTORE online_users online:10 online:9 online:8 online:7 online:6 $scmd = $redis->createCommand("sunionstore",$keys); $redis->executeCommand($scmd); $online_friend_ids = $redis->sinter('online_users' ! , 'user:'.$user_id.'.friend_ids');
  • 60. Few Things About Redis • Single Threaded • Can “Shard” For More Capacity / Performance • All Commands are Atomic • Transactions for Multiple Atomic Commands • Pipelining for High Performance
  • 61. Persistence • Snapshots on a Configurable Schedule • Will “fork” the process and write the DataSet to Disk • Append-Only File • Will Let You Survive a “Reboot”
  • 62. New Stuff / On The Horizon • Lua Scripting (Kinda Querying) • Redis Clustering
  • 63. aL ive ut bo ? A H ow emo D
  • 65. 50 Servers * 8 Clients = 400 Workers
  • 66. Rackspace Cloud + Salt (saltstack.org) + Redis & PHP
  • 69. Your Homework Download & Play Around with Redis! It’s Awesome!
  • 71. Flickr Credits & Images: http://gim.ie/jsLJ
  • 72. Thanks! Rate My Talk (PLEASE): https://joind.in/6486 Twitter: @JustinCarmony IRC: carmony #uphpu #phpc #salt Website: http://www.justincarmony.com/blog Email: justin@justincarmony.com

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n