SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Downloaden Sie, um offline zu lesen
http://redis.io




domingo, 11 de dezembro de 2011
“MEMORY IS THE NEW
            DISK. DISK IS THE NEW
                    TAPE.”



                                  Jim Gray




domingo, 11 de dezembro de 2011
VAMOS FALAR DE
                               REDIS
                                  Mas primeiro...




domingo, 11 de dezembro de 2011
NOSQL
                 Mudança de paradigma
                 SQL?
            Cada “problema” uma solução
          mais adequada de persistência.




domingo, 11 de dezembro de 2011
domingo, 11 de dezembro de 2011
domingo, 11 de dezembro de 2011
QUANDO USAR?

                      Cache
                      Stock prices
                      Sharding Directory Service

                      Real time data collection
                     Real time communication
                     Analytics



domingo, 11 de dezembro de 2011
REDIS, QUE DIABOS
                    É ISSO?



domingo, 11 de dezembro de 2011
CHAVE-VALOR
                                    Estrutura de dados
domingo, 11 de dezembro de 2011
CHAVE                              VALOR

                    user:1        name     Ayrton       age        23

                    user:2        name     João        phone    555-555

            user:1:friends        user:2   user:3      user:4    user:5
                    user:3        name      José       email    xp@a.com

                    user:4        name     Mario        age        34

                    user:5        name     Mara         age        25

              user:1:acess         140

             user:1:token         H13NDSME3MDSSR6MG6


domingo, 11 de dezembro de 2011
CLIENTS PARA REDIS:
              ActionScript        Java
              C                   Lua
              C#                  Node.js
              C++                 Objective-C
              Clojure             Perl
              Common Lisp         PHP
              Erlang              Pure Data
              Fancy               Python
              Go                  Ruby
              Haskell             Scala
              haXe                Smaltalk
              Io                  Tcl

domingo, 11 de dezembro de 2011
KEYS

              Você pesquisa pela chave.

              Todas as chaves ficam na memória.

              O(1)

              Chaves longas, má idéia.

              Chaves curtas, má idéia também.

              Tente seguir um padrão.


domingo, 11 de dezembro de 2011
No terminal...


        Inicie o server:




        Inicie o client:



        Insira um registro:




domingo, 11 de dezembro de 2011
REDIS DATA TYPES

                      String

                      Lists

                      Hashes

                      Sets

                      Sorted Sets
domingo, 11 de dezembro de 2011
STRINGS




domingo, 11 de dezembro de 2011
APPEND   key value

                                  DECR     key

                                  DECRBY   key decrement

                                  GET      key

                                  GETBIT   key offset

                                  GETRANGE key start end

                                  GETSET   key value

                                  INCR     key

                                  INCRBY   key increment

                                  MGET     key [key ...]

                                  MSET     key value [key value ...]

                                  MSETNX   key value [key value ...]

                                  SET      key value

                                  SETBIT   key offset value

                                  SETEX    key seconds value

                                  SETNX    key value

                                  SETRANGE key offset value

                                  STRLEN   key


domingo, 11 de dezembro de 2011
LISTS




domingo, 11 de dezembro de 2011
BLPOP       key [key ...] timeout

                                  BRPOP       key [key ...] timeout

                                  BRPOPLPUSH source destination timeout

                                  LINDEX      key index

                                  LINSERT     key BEFORE|AFTER pivot value

                                  LLEN        key

                                  LPOP        key

                                  LPUSH       key value [value ...]

                                  LPUSHX      key value

                                  LRANGE      key start stop

                                  LREM        key count value

                                  LSET        key index value

                                  LTRIM       key start stop

                                  RPOP        key

                                  RPOPLPUSH   source destination

                                  RPUSH       key value [value ...]

                                  RPUSHX      key value



domingo, 11 de dezembro de 2011
HASHES




domingo, 11 de dezembro de 2011
HDEL     key field [field ...]

                                  HEXISTS key field

                                  HGET     key field

                                  HGETALL key

                                  HINCRBY key field increment

                                  HKEYS    key

                                  HLEN     key

                                  HMGET    key field [field ...]

                                  HMSET    key field value [field value ...]

                                  HSET     key field value

                                  HSETNX   key field value

                                  HVALS    key




domingo, 11 de dezembro de 2011
SETS




domingo, 11 de dezembro de 2011
SADD         key member [member ...]

                                  SCARD        key

                                  SDIFF        key [key ...]

                                  SDIFFSTORE   destination key [key ...]

                                  SINTER       key [key ...]

                                  SINTERSTORE destination key [key ...]

                                  SISMEMBER    key member

                                  SMEMBERS     key

                                  SMOVE        source destination member

                                  SPOP         key

                                  SRANDMEMBER key

                                  SREM         key member [member ...]

                                  SUNION       key [key ...]

                                  SUNIONSTORE destination key [key ...]




domingo, 11 de dezembro de 2011
SORTED SETS




domingo, 11 de dezembro de 2011
ZADD                          key score member [score] [member]
    ZCARD                         key
    ZCOUNT                        key min max
    ZINCRBY                       key increment member
    ZINTERSTORE                   destination numkeys key [key ...][WEIGHTS weight [weight ...]]
    [AGGREGATE SUM|MIN|MAX]
    ZRANGE                        key start stop [WITHSCORES]
    ZRANGEBYSCORE                 key min max [WITHSCORES] [LIMIT offset count]
    ZRANK                         key member
    ZREM                          key member [member ...]
    ZREMRANGEBYRANK               key start stop
    ZREMRANGEBYSCORE key min max
    ZREVRANGE                     key start stop [WITHSCORES]
    ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]
    ZREVRANK                      key member
    ZSCORE                        key member
    ZUNIONSTORE                   destination numkeys key [key ...][WEIGHTS weight [weight ...]]
    [AGGREGATE SUM|MIN|MAX]




domingo, 11 de dezembro de 2011
SNAPSHOTTING
     redis.conf:
                                  save 900 1
                                  save 300 10
                                  save 60 10000

    Nome do arquivo:
                                  dbfilename dump.rdb

     Diretório do dump:
                                  dir ./


domingo, 11 de dezembro de 2011
REPLICATION
          redis.conf:


                          SLAVE    slaveof <masterip> <masterport>


                          SLAVE    masterauth <master-password>


                          MASTER   requirepass <pass>




domingo, 11 de dezembro de 2011
E MAIS...

          DBSIZE

          INFO

          SLAVEOF host port

          BGSAVE

          FLUSHALL

          FLUSHDB

          SAVE




domingo, 11 de dezembro de 2011
CODE...
domingo, 11 de dezembro de 2011
REFERÊNCIAS


              http://redis.io
              http://www.slideshare.net/MaxwellDayvson/redis-e-as-facilidades-de-trabalhar-com-um-banco-de-dados-
              nosql
              http://www.slideshare.net/gleicon/lesprit-de-lescalier
              http://www.paperplanes.de/2010/2/16/a_collection_of_redis_use_cases.html
              http://highscalability.com/blog/2011/7/6/11-common-web-use-cases-solved-in-redis.html




domingo, 11 de dezembro de 2011

Weitere ähnliche Inhalte

Empfohlen

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Introdução ao Redis: Uma base de dados chave-valor em memória

  • 2. “MEMORY IS THE NEW DISK. DISK IS THE NEW TAPE.” Jim Gray domingo, 11 de dezembro de 2011
  • 3. VAMOS FALAR DE REDIS Mas primeiro... domingo, 11 de dezembro de 2011
  • 4. NOSQL Mudança de paradigma SQL? Cada “problema” uma solução mais adequada de persistência. domingo, 11 de dezembro de 2011
  • 5. domingo, 11 de dezembro de 2011
  • 6. domingo, 11 de dezembro de 2011
  • 7. QUANDO USAR? Cache Stock prices Sharding Directory Service Real time data collection Real time communication Analytics domingo, 11 de dezembro de 2011
  • 8. REDIS, QUE DIABOS É ISSO? domingo, 11 de dezembro de 2011
  • 9. CHAVE-VALOR Estrutura de dados domingo, 11 de dezembro de 2011
  • 10. CHAVE VALOR user:1 name Ayrton age 23 user:2 name João phone 555-555 user:1:friends user:2 user:3 user:4 user:5 user:3 name José email xp@a.com user:4 name Mario age 34 user:5 name Mara age 25 user:1:acess 140 user:1:token H13NDSME3MDSSR6MG6 domingo, 11 de dezembro de 2011
  • 11. CLIENTS PARA REDIS: ActionScript Java C Lua C# Node.js C++ Objective-C Clojure Perl Common Lisp PHP Erlang Pure Data Fancy Python Go Ruby Haskell Scala haXe Smaltalk Io Tcl domingo, 11 de dezembro de 2011
  • 12. KEYS Você pesquisa pela chave. Todas as chaves ficam na memória. O(1) Chaves longas, má idéia. Chaves curtas, má idéia também. Tente seguir um padrão. domingo, 11 de dezembro de 2011
  • 13. No terminal... Inicie o server: Inicie o client: Insira um registro: domingo, 11 de dezembro de 2011
  • 14. REDIS DATA TYPES String Lists Hashes Sets Sorted Sets domingo, 11 de dezembro de 2011
  • 15. STRINGS domingo, 11 de dezembro de 2011
  • 16. APPEND key value DECR key DECRBY key decrement GET key GETBIT key offset GETRANGE key start end GETSET key value INCR key INCRBY key increment MGET key [key ...] MSET key value [key value ...] MSETNX key value [key value ...] SET key value SETBIT key offset value SETEX key seconds value SETNX key value SETRANGE key offset value STRLEN key domingo, 11 de dezembro de 2011
  • 17. LISTS domingo, 11 de dezembro de 2011
  • 18. BLPOP key [key ...] timeout BRPOP key [key ...] timeout BRPOPLPUSH source destination timeout LINDEX key index LINSERT key BEFORE|AFTER pivot value LLEN key LPOP key LPUSH key value [value ...] LPUSHX key value LRANGE key start stop LREM key count value LSET key index value LTRIM key start stop RPOP key RPOPLPUSH source destination RPUSH key value [value ...] RPUSHX key value domingo, 11 de dezembro de 2011
  • 19. HASHES domingo, 11 de dezembro de 2011
  • 20. HDEL key field [field ...] HEXISTS key field HGET key field HGETALL key HINCRBY key field increment HKEYS key HLEN key HMGET key field [field ...] HMSET key field value [field value ...] HSET key field value HSETNX key field value HVALS key domingo, 11 de dezembro de 2011
  • 21. SETS domingo, 11 de dezembro de 2011
  • 22. SADD key member [member ...] SCARD key SDIFF key [key ...] SDIFFSTORE destination key [key ...] SINTER key [key ...] SINTERSTORE destination key [key ...] SISMEMBER key member SMEMBERS key SMOVE source destination member SPOP key SRANDMEMBER key SREM key member [member ...] SUNION key [key ...] SUNIONSTORE destination key [key ...] domingo, 11 de dezembro de 2011
  • 23. SORTED SETS domingo, 11 de dezembro de 2011
  • 24. ZADD key score member [score] [member] ZCARD key ZCOUNT key min max ZINCRBY key increment member ZINTERSTORE destination numkeys key [key ...][WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX] ZRANGE key start stop [WITHSCORES] ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count] ZRANK key member ZREM key member [member ...] ZREMRANGEBYRANK key start stop ZREMRANGEBYSCORE key min max ZREVRANGE key start stop [WITHSCORES] ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count] ZREVRANK key member ZSCORE key member ZUNIONSTORE destination numkeys key [key ...][WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX] domingo, 11 de dezembro de 2011
  • 25. SNAPSHOTTING redis.conf: save 900 1 save 300 10 save 60 10000 Nome do arquivo: dbfilename dump.rdb Diretório do dump: dir ./ domingo, 11 de dezembro de 2011
  • 26. REPLICATION redis.conf: SLAVE slaveof <masterip> <masterport> SLAVE masterauth <master-password> MASTER requirepass <pass> domingo, 11 de dezembro de 2011
  • 27. E MAIS... DBSIZE INFO SLAVEOF host port BGSAVE FLUSHALL FLUSHDB SAVE domingo, 11 de dezembro de 2011
  • 28. CODE... domingo, 11 de dezembro de 2011
  • 29. REFERÊNCIAS http://redis.io http://www.slideshare.net/MaxwellDayvson/redis-e-as-facilidades-de-trabalhar-com-um-banco-de-dados- nosql http://www.slideshare.net/gleicon/lesprit-de-lescalier http://www.paperplanes.de/2010/2/16/a_collection_of_redis_use_cases.html http://highscalability.com/blog/2011/7/6/11-common-web-use-cases-solved-in-redis.html domingo, 11 de dezembro de 2011