SlideShare a Scribd company logo
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

More Related Content

What's hot

Scaling Rails with Memcached
Scaling Rails with MemcachedScaling Rails with Memcached
Scaling Rails with Memcached
guest2259ea
 
[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 Fast
Barry Jones
 
Maximize your Cache for No Cash
Maximize your Cache for No CashMaximize your Cache for No Cash
Maximize your Cache for No Cash
Yorick Phoenix
 
Websites On Speed
Websites On SpeedWebsites On Speed
Websites On Speed
Tom Croucher
 
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
Cssbestpracticesjstyleguidejandtips 150830184202-lva1-app6892
Deepak 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 Study
Mitch Pirtle
 
Intro to HTML 5 / CSS 3
Intro to HTML 5 / CSS 3Intro to HTML 5 / CSS 3
Intro to HTML 5 / CSS 3
Tadpole Collective
 
CSS and image optimization
CSS and image optimizationCSS and image optimization
CSS and image optimization
Stoyan 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 Redis
Ricard Clau
 
A web app in pure Clojure
A web app in pure ClojureA web app in pure Clojure
A web app in pure Clojure
Dane 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 2009
Jason Davies
 
Developing cacheable PHP applications - PHPLimburgBE 2018
Developing cacheable PHP applications - PHPLimburgBE 2018Developing cacheable PHP applications - PHPLimburgBE 2018
Developing cacheable PHP applications - PHPLimburgBE 2018
Thijs Feryn
 
Gofer 200707
Gofer 200707Gofer 200707
Gofer 200707oscon2007
 
Page Performance
Page PerformancePage Performance
Page Performance
atorreno
 
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
Rogue 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 cloud
Rogue Wave Software
 
Resource registries plone conf 2014
Resource registries plone conf 2014Resource registries plone conf 2014
Resource registries plone conf 2014
Ramon 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
 

What's hot (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
 

Similar to Blazing Data With Redis (and LEGOS!)

DSpace Under the Hood
DSpace Under the HoodDSpace Under the Hood
DSpace Under the Hood
DuraSpace
 
Scaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQLScaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQL
Richard Schneeman
 
Why ruby and rails
Why ruby and railsWhy ruby and rails
Why ruby and rails
Reuven Lerner
 
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 enterprise
Sarel van der Walt
 
Redis - The Universal NoSQL Tool
Redis - The Universal NoSQL ToolRedis - The Universal NoSQL Tool
Redis - The Universal NoSQL Tool
Eberhard 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 Code
Michael 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 101
MongoDB
 
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 Minutes
MongoDB
 
eMusic: WordPress in the Enterprise
eMusic: WordPress in the EnterpriseeMusic: WordPress in the Enterprise
eMusic: WordPress in the Enterprise
Scott Taylor
 
RavenDB in the wild
RavenDB in the wildRavenDB in the wild
RavenDB in the wild
Mauro Servienti
 
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
 
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
Chicago Hadoop Users Group
 
Devops kc meetup_5_20_2013
Devops kc meetup_5_20_2013Devops kc meetup_5_20_2013
Devops kc meetup_5_20_2013Aaron Blythe
 

Similar to 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
 

Recently uploaded

Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 

Recently uploaded (20)

Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 

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

Editor's Notes

  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