Beruflich Dokumente
Kultur Dokumente
Nick Quaranto
@qrush nick@quaran.to
i work at
we use
on a few sites
EPIC RECAP TIME
redis is
“an advanced key-
value store”
redis has
smart caching
redis is used for
job queues
redis is used for
powers of 2 8 7 6 5 4 3 2 1
2 2 2 2 2 2 2 2 2 0
binary 1 1 0 1 0 0 1 0 0
octal 6 4 4
stat = File.stat("normal.txt")
printf("%b", stat.mode)
stat = File.stat("normal.txt")
printf("%b", stat.mode)
1000000110100100
stat = File.stat("normal.txt")
printf("%b", stat.mode)
1000000110100100
stat = File.stat("normal.txt")
mode = sprintf("%b", stat.mode)
bits = mode.scan(/\d/)
offset 8 7 6 5 4 3 2 1 0
value 1 1 0 1 0 0 1 0 0
redis key perms:normal.txt
offset 8 7 6 5 4 3 2 1 0
value 1 1 0 1 0 0 1 0 0
require 'redis'
redis = Redis.new
redis.setbit("perms:normal.txt", 2, 1)
redis key perms:normal.txt
offset 8 7 6 5 4 3 2 1 0
value 1 1 0 1 0 0 1 0 0
redis.getbit("perms:normal.txt", 8)
1
set algebra
require 'tweetstream'
require 'redis'
require 'tweetstream'
require 'redis'
redis = Redis.new
user_ids = [15029296, 88984381, 18234085, ...]
daemon = TweetStream::Daemon.new(user, pw)
require 'tweetstream'
require 'redis'
redis = Redis.new
user_ids = [15029296, 88984381, 18234085, ...]
daemon = TweetStream::Daemon.new(user, pw)
daemon.follow(*user_ids) do |status|
handle = status.user.screen_name
end
require 'tweetstream'
require 'redis'
redis = Redis.new
user_ids = [15029296, 88984381, 18234085, ...]
daemon = TweetStream::Daemon.new(user, pw)
daemon.follow(*user_ids) do |status|
handle = status.user.screen_name
end
count
key score
@objo 310
@jtimberman 340
@elight 353
require 'tweetstream'
require 'redis'
redis = Redis.new
user_ids = [15029296, 88984381, 18234085, ...]
daemon = TweetStream::Daemon.new(user, pw)
daemon.follow(*user_ids) do |status|
handle = status.user.screen_name
info am proxy
significantly original if
words:@wycats
algebra JQUERY refresh and
@fxn:
> sinter words:@wycats words:@zedshaw
words:@zedshaw
every RT like suspect made walk does idea almost receipts code use Python
once. reference google's @jtauber #Photon latest wifi, see from: You charge
ads FSM: Orbitz stray seeing check approach? parser ENTER/EXIT
file .@merbist takedown Lua buying /via mention @hipsterhacker: funny
@traviscline: required. proof State http://sheddingbikes.com/posts/
1299555462.html what say if ass. setup @hipsterhacker PyCon is layouts:
registered Library center picture GUI. out, feel @kj4sre PDF. ATT scenarios.
CPU happen http://www.wordnik.com/ Yep, so, but apps, when get short
a say and more It's the RT if
ZeroMQ Alright, underused." My Like that's food. thief faster Amazing. sucks
@drye need shot. worst I'm Changing sucks. controls on tough one Most
work :) I almost what of @tomdale: about proxy now to easier @jamesarosen price yours significantly commits SF
left time so @jphpsf instance, preview @joedamato http://t.co/R8DxsUX problem!
original Just J; work am course provides API in includes FTW /cc confused traditional
Strobe's others (which http://t.co/wgci9aU http://b SC.Button this with Handlebars :)
devs. latest release <<-SQL.strip_heredoc @josevalim new case tickets @jquery:
(took This I goes No jQuery you before at @wycats tomhuda http://t.co/8Pny0N9 JQUERY
button, say the --
words:@wycats
redis.sunionstore("allwords",
"words:@wycats", "words:@zedshaw",
"words:@qrush")
words:@wycats
foo
bar foo bar
baz bug
shed
bar shed boo zar
words:@zedshaw boo zar
words:@qrush
allwords
# unique words
redis = Redis.new
redis.sunionstore("allwords", *words)
puts redis.scard("allwords")
# 9055
count
key score
@objo
100
@jtimberman
200
@elight
300
@qrush
400
@wycats
500
count
key score
@objo
100
@jtimberman
200
redis.zrevrange
@elight
300 "count", 0, 2
@qrush
400
@wycats
500
count
key score
@objo
100
@jtimberman
200 redis.zrevrange
"count", 0, 2
@elight
300 with_scores:
true
@qrush
400
@wycats
500
# top twitters
redis = Redis.new
# {"objo"=>"310",
# "jtimberman"=>"340",
# "elight"=>"353"}
more set math
SINTER
SDIFF
ZUNIONSTORE
ZINTERSTORE
More on http://redis.io/commands
sorting keys
user_ids
42 78 133 90 5
user_ids
42 78 133 90 5
redis.sort("users")
5
42
78
90
133
user_ids
42 78 133 90 5
133
90
78
42
5
user_ids
42 78 133
133
42
78
user_ids
42 78 133
chad
joe
matt
transactions
# create the suits
redis.lpush "suits", "Hearts"
redis.lpush "suits", "Spades"
redis.lpush "suits", "Clubs"
redis.lpush "suits", "Diamonds"
LPUSH ♠
LPUSH ♣
♠♥
LRANGE
♣
LPUSH ♦
MULTI
LPUSH ♥
LPUSH ♠
LPUSH ♣
LPUSH ♦ LRANGE
EXEC ♠♥
♣♦
# create the suits
redis.multi do
redis.lpush "suits", "Hearts"
redis.lpush "suits", "Spades"
redis.lpush "suits", "Clubs"
redis.lpush "suits", "Diamonds"
end
♠♥
♠ LREM ♣
LREM ♠
♠♥
WATCH ♣♦
♠♥
WATCH ♣♦
WATCH
♠♥
WATCH ♣♦
WATCH
♠♥
LRANGE
♣♦ ♠♥
LRANGE
♣♦
♠♥
WATCH ♣♦
WATCH
♠♥
LRANGE
♣♦ ♠♥
LRANGE
♣♦
MULTI
LREM ♠
EXEC
♥
♣♦
♠♥
WATCH ♣♦
WATCH
♠♥
LRANGE
♣♦ ♠♥
LRANGE
♣♦
MULTI
MULTI
LREM ♠
LREM ♠
EXEC
♥
♣♦ EXEC
♠♥
WATCH ♣♦
WATCH
♠♥
LRANGE
♣♦ ♠♥
LRANGE
♣♦
MULTI
MULTI
LREM ♠
EXEC
♥
FAIL!
LREM ♠
♣♦ EXEC
optimistic locking
1. Begin transaction
WATCH key
MULTI
...
EXEC
2. Repeat 1. until successful
# a user picks a suit
redis.watch "suits"
redis.multi do
redis.lrem "suits", 0, my_suit
end
thanks!
http://redis.io
http://rediscookbook.org/
http://github.com/qrush/mwrc