SlideShare a Scribd company logo
Redis
Installing
Basics
Data structures
Pseudo Multi Key Queries
References and Indexes
Round Trips and Pipelining
Transactions
Keys Anti pattern, Use SCAN
Expire, Pub-Sub
Monitor, Sort
Administration
A few commands
Big O
Reference
iNSTALLING
• Download redis-2.8.7.tar.gz, untar
• $ make $ make test $ cd src
• $ redis-server #server accepts connections on port6379
• $ redis-cli
• $$ info
• $ redis-benchmark
basics
• In-memory persistent key-value store 5 data structures
• $select 1 # many databases
• $ set users:leto '{"name": "leto", "planet": "dune", "likes": ["spice"]}’ #
Every data struct has key eg users:leto
• $ get users:leto # Values are arbitrary byte arrays that Redis doesn’t
care about
Data Structures
• Strings $strlen $getrange $append
• Hashes $hset users:goku powerlevel 9000
• Lists $ lpush newusers goku
• Sets $sadd friends:leto ghanima paul chani jessica
• Sortd Sets $ zadd friends:duncan 70 ghanima 95 paul 95 chani 75
jessica 1 vladimir
Pseudo Multi Key Queries
• $set users:9001 '{"id": 9001, "email": "leto@dune.gov", ...}’
• $hset users:lookup:email leto@dune.gov 9001
• $get users:9001
• $id = redis.hget('users:lookup:email' , 'leto@dune.gov' ) # ruby
• $user = redis.get("users:#{id}" ) # ruby
References and Indexes
• $sadd friends:leto ghanima paul chani jessica
• $sadd friends_of:chani leto paul
• # having to manually deal with references in Redis is
unfortunate.
Round Trips and Pipelining
• #Redis also supports pipelining. Normally when a
client sends a request to Redis it waits for the reply
before sending the next request. With pipelining you
can send a number of requests without waiting for
their responses.
Transactions
• $multi
• $hincrby groups:1percent balance -9000000000
• $hincrby groups:99percent balance 9000000000
• $exec # Or use command discard
• $ redis.watch('powerlevel' ) #ruby
• $ current = redis.get('powerlevel' ) #ruby
• $ redis.multi() #ruby
• $ redis.set('powerlevel' , current + 1) #ruby
• $ redis.exec() #ruby
Keys Anti pattern, Use
SCAN
• $ keys bug:1233:*
• #command takes a pattern and finds all the matching keys
• #Should never be used in production code. Linear scan through all the
keys.
• Better:
• $hset bugs:1233 1 '{"id":1, "account": 1233, "subject": "..."}’
• $hset bugs:1233 2 '{"id":2, "account": 1233, "subject": "..."}’
• $ scan 0 match bugs:* count 20 $ hscan $sscan $zscan
Expire, Pub-Sub
• $expire pages:about 30
• $ ttl pages:about
• $ persist pages:about
• $ setex pages:about 30 '<h1>about us</h1>....’
• $ subscribe warnings $unsubscribe $punsubscribe
• $ publish warnings "it's over 9000!” $psubscribe warnings:*)
• $blpop $brpop
Monitor, Sort
• $ monitor
• $ config set slowlog-log-slower-than 0
• $ slowlog $ slowlog len
• $ sort users:leto:guesses
• $ sort friends:ghanima limit 0 3 desc alpha
• $ sort watch:leto by severity:* desc
• $ sort watch:leto by bug:*->priority get bug:*->details
• $ sort watch:leto by bug:*->priority get bug:*->details store
watch_by_priority:leto
Administration
• $ config get *log* # http://download.redis.io/redis-stable/redis.conf
• $ requirepass $ auth password
• $ rename-command FLUSHALL
1041285018a942a4922cbf76623b741e
• $ slaveof # Replication
A few commands
• Auth, echo, ping, quit, select
• Del, dump, exists, expire, expireat, keys, migrate, move, object, persi
st, pexpire, pexpireat, pttl, randomkey, rename, renamenx, restore, so
rt, ttl, type, scan
• Append, bitcount, bitop, bitops, decr, decrby, get, getbit, getrange, get
set, inc, incrby, incrbyfloat, mget, mset, msetnx, psetex, set, setbit, set
ex, setnx, setrange, strlen
Big O
• O(1) sismember
• O(log(N) zadd ltrim
• O(log(N)+M) zremrangebyscore
• O(N+M*log(M)) sort
• O(Nˆ2) and O(CˆN) no commands
reference
• http://github.com/karlseguin/the-little-redis-book

More Related Content

PPTX
So cal0365productivitygroup feb2019
KEY
DBIx::Skinnyと仲間たち
PDF
Redis for the Everyday Developer
PDF
Not Really PHP by the book
PDF
How to work with legacy code PHPers Rzeszow #2
PDF
スマートフォン勉強会@関東 #11 LT 5分で語る SQLite暗号化
PDF
DNSSEC FIRST
PDF
Solr @ Etsy - Apache Lucene Eurocon
So cal0365productivitygroup feb2019
DBIx::Skinnyと仲間たち
Redis for the Everyday Developer
Not Really PHP by the book
How to work with legacy code PHPers Rzeszow #2
スマートフォン勉強会@関東 #11 LT 5分で語る SQLite暗号化
DNSSEC FIRST
Solr @ Etsy - Apache Lucene Eurocon

What's hot (20)

TXT
My shell
PDF
HappyKardashian.com for #FVCP
PDF
PuppetCamp SEA 1 - Version Control with Puppet
PDF
YAPC::Asia 2010 Twitter解析サービス
PDF
PPT
Php Mysql
PDF
PHP Experience 2016 - [Workshop] Elastic Search: Turbinando sua aplicação PHP
PDF
Blog Hacks 2011
PDF
Beeline Firebase talk - Firebase event Jun 2017
PPTX
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
PDF
Mojolicious: what works and what doesn't
PPT
Perl调用微博API实现自动查询应答
PDF
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
PDF
Drupal, meet Assetic
PDF
Mojolicious
PDF
Defcon 22-blake-self-cisc0ninja-dont-ddos-me-bro
KEY
jQuery: Tips, tricks and hints for better development and Performance
PDF
Defcon 22-graham-mc millan-tentler-masscaning-the-internet
PDF
Extracting ruby gem
PPTX
19. CodeIgniter imagini in mysql
My shell
HappyKardashian.com for #FVCP
PuppetCamp SEA 1 - Version Control with Puppet
YAPC::Asia 2010 Twitter解析サービス
Php Mysql
PHP Experience 2016 - [Workshop] Elastic Search: Turbinando sua aplicação PHP
Blog Hacks 2011
Beeline Firebase talk - Firebase event Jun 2017
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious: what works and what doesn't
Perl调用微博API实现自动查询应答
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Drupal, meet Assetic
Mojolicious
Defcon 22-blake-self-cisc0ninja-dont-ddos-me-bro
jQuery: Tips, tricks and hints for better development and Performance
Defcon 22-graham-mc millan-tentler-masscaning-the-internet
Extracting ruby gem
19. CodeIgniter imagini in mysql
Ad

Viewers also liked (14)

PPTX
PPTX
מצגת שלג Crm שלמה
PPT
Html5 CSS3
PPTX
ヤノマミ
PPTX
PPTX
ヤノマミ
PDF
Using Video on a Budget
PPTX
東京オリンピック
PPT
Social Media by LightBox Collaborative
PDF
Thema 4 les 3
PDF
Focusing your Strategies with Donors
PPTX
Go away halloween
PPT
Bab 2 koordinasi badan
מצגת שלג Crm שלמה
Html5 CSS3
ヤノマミ
ヤノマミ
Using Video on a Budget
東京オリンピック
Social Media by LightBox Collaborative
Thema 4 les 3
Focusing your Strategies with Donors
Go away halloween
Bab 2 koordinasi badan
Ad

Similar to Redis (20)

PDF
Redis SoCraTes 2014
PDF
Serializing Ruby Objects in Redis
PDF
Redis — The AK-47 of Post-relational Databases
PDF
Introduction to Redis
PDF
Fun with Ruby and Redis
KEY
PPT
Redis And python at pycon_2011
PDF
An Introduction to Redis for Developers.pdf
PDF
Paris Redis Meetup Introduction
PDF
#SydPHP - The Magic of Redis
PDF
How you can benefit from using Redis. Javier Ramirez, teowaki, at Codemotion ...
PDF
An Introduction to Redis for .NET Developers.pdf
ODP
An Introduction to REDIS NoSQL database
KEY
Indexing thousands of writes per second with redis
PPT
Introduction to redis
PDF
quickguide-einnovator-9-redis
PDF
Redispresentation apac2012
PDF
Redis Installation Configuration And Implementation
PDF
Introduction to redis - version 2
PPTX
Redis SoCraTes 2014
Serializing Ruby Objects in Redis
Redis — The AK-47 of Post-relational Databases
Introduction to Redis
Fun with Ruby and Redis
Redis And python at pycon_2011
An Introduction to Redis for Developers.pdf
Paris Redis Meetup Introduction
#SydPHP - The Magic of Redis
How you can benefit from using Redis. Javier Ramirez, teowaki, at Codemotion ...
An Introduction to Redis for .NET Developers.pdf
An Introduction to REDIS NoSQL database
Indexing thousands of writes per second with redis
Introduction to redis
quickguide-einnovator-9-redis
Redispresentation apac2012
Redis Installation Configuration And Implementation
Introduction to redis - version 2

More from Puneet Kumar (7)

PPTX
Quick Scala
ODP
Robotics using EV3 Introduction
PPTX
Chess1
PPTX
Android accessibility
PPTX
Nagios
PPTX
System adm
PPTX
Bitcoin
Quick Scala
Robotics using EV3 Introduction
Chess1
Android accessibility
Nagios
System adm
Bitcoin

Redis

  • 1. Redis Installing Basics Data structures Pseudo Multi Key Queries References and Indexes Round Trips and Pipelining Transactions Keys Anti pattern, Use SCAN Expire, Pub-Sub Monitor, Sort Administration A few commands Big O Reference
  • 2. iNSTALLING • Download redis-2.8.7.tar.gz, untar • $ make $ make test $ cd src • $ redis-server #server accepts connections on port6379 • $ redis-cli • $$ info • $ redis-benchmark
  • 3. basics • In-memory persistent key-value store 5 data structures • $select 1 # many databases • $ set users:leto '{"name": "leto", "planet": "dune", "likes": ["spice"]}’ # Every data struct has key eg users:leto • $ get users:leto # Values are arbitrary byte arrays that Redis doesn’t care about
  • 4. Data Structures • Strings $strlen $getrange $append • Hashes $hset users:goku powerlevel 9000 • Lists $ lpush newusers goku • Sets $sadd friends:leto ghanima paul chani jessica • Sortd Sets $ zadd friends:duncan 70 ghanima 95 paul 95 chani 75 jessica 1 vladimir
  • 5. Pseudo Multi Key Queries • $set users:9001 '{"id": 9001, "email": "leto@dune.gov", ...}’ • $hset users:lookup:email leto@dune.gov 9001 • $get users:9001 • $id = redis.hget('users:lookup:email' , 'leto@dune.gov' ) # ruby • $user = redis.get("users:#{id}" ) # ruby
  • 6. References and Indexes • $sadd friends:leto ghanima paul chani jessica • $sadd friends_of:chani leto paul • # having to manually deal with references in Redis is unfortunate.
  • 7. Round Trips and Pipelining • #Redis also supports pipelining. Normally when a client sends a request to Redis it waits for the reply before sending the next request. With pipelining you can send a number of requests without waiting for their responses.
  • 8. Transactions • $multi • $hincrby groups:1percent balance -9000000000 • $hincrby groups:99percent balance 9000000000 • $exec # Or use command discard • $ redis.watch('powerlevel' ) #ruby • $ current = redis.get('powerlevel' ) #ruby • $ redis.multi() #ruby • $ redis.set('powerlevel' , current + 1) #ruby • $ redis.exec() #ruby
  • 9. Keys Anti pattern, Use SCAN • $ keys bug:1233:* • #command takes a pattern and finds all the matching keys • #Should never be used in production code. Linear scan through all the keys. • Better: • $hset bugs:1233 1 '{"id":1, "account": 1233, "subject": "..."}’ • $hset bugs:1233 2 '{"id":2, "account": 1233, "subject": "..."}’ • $ scan 0 match bugs:* count 20 $ hscan $sscan $zscan
  • 10. Expire, Pub-Sub • $expire pages:about 30 • $ ttl pages:about • $ persist pages:about • $ setex pages:about 30 '<h1>about us</h1>....’ • $ subscribe warnings $unsubscribe $punsubscribe • $ publish warnings "it's over 9000!” $psubscribe warnings:*) • $blpop $brpop
  • 11. Monitor, Sort • $ monitor • $ config set slowlog-log-slower-than 0 • $ slowlog $ slowlog len • $ sort users:leto:guesses • $ sort friends:ghanima limit 0 3 desc alpha • $ sort watch:leto by severity:* desc • $ sort watch:leto by bug:*->priority get bug:*->details • $ sort watch:leto by bug:*->priority get bug:*->details store watch_by_priority:leto
  • 12. Administration • $ config get *log* # http://download.redis.io/redis-stable/redis.conf • $ requirepass $ auth password • $ rename-command FLUSHALL 1041285018a942a4922cbf76623b741e • $ slaveof # Replication
  • 13. A few commands • Auth, echo, ping, quit, select • Del, dump, exists, expire, expireat, keys, migrate, move, object, persi st, pexpire, pexpireat, pttl, randomkey, rename, renamenx, restore, so rt, ttl, type, scan • Append, bitcount, bitop, bitops, decr, decrby, get, getbit, getrange, get set, inc, incrby, incrbyfloat, mget, mset, msetnx, psetex, set, setbit, set ex, setnx, setrange, strlen
  • 14. Big O • O(1) sismember • O(log(N) zadd ltrim • O(log(N)+M) zremrangebyscore • O(N+M*log(M)) sort • O(Nˆ2) and O(CˆN) no commands

Editor's Notes

  • #2: Puneet Kumar
  • #5: Strings $incr $incrby $setbit $getbitHashes hgetusers:gokupowerlevel $ hmsetusers:goku race saiyan age 737 $ hgetallusers:goku $ hkeysusers:goku $ hdelusers:goku age Lists $ltrimnewusers 0 49 Sets $sismemberfriends:letojessica $sinter friends:leto friends:duncan $sinterstorefriends:leto_duncanfriends:leto friends:duncanSorted Sets $zcount friends:duncan 90 100 $zrevrank friends:duncan chani