Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Redis - Key-value store enhanced
Search
Guilherme da Silva Mello
April 20, 2012
Programming
1
150
Redis - Key-value store enhanced
Introduction to some redis data types and manipulation
Guilherme da Silva Mello
April 20, 2012
Tweet
Share
More Decks by Guilherme da Silva Mello
See All by Guilherme da Silva Mello
Desenvolvimento Ágil de Aplicações WEB
guimello
0
54
Other Decks in Programming
See All in Programming
プログラミングどうやる? ~テスト駆動開発から学ぶ達人の型~
a_okui
0
190
高度なUI/UXこそHotwireで作ろう Kaigi on Rails 2025
naofumi
4
3.5k
Catch Up: Go Style Guide Update
andpad
0
180
プロダクト開発をAI 1stに変革する〜SaaS is dead時代で生き残るために〜 / AI 1st Product Development
kobakei
0
490
CSC305 Lecture 02
javiergs
PRO
1
260
CSC305 Lecture 03
javiergs
PRO
0
230
どの様にAIエージェントと 協業すべきだったのか?
takefumiyoshii
2
610
プログラマのための作曲入門
cheebow
0
540
私はどうやって技術力を上げたのか
yusukebe
43
17k
AI Coding Meetup #3 - 導入セッション / ai-coding-meetup-3
izumin5210
0
590
Web Components で実現する Hotwire とフロントエンドフレームワークの橋渡し / Bridging with Web Components
da1chi
3
1.9k
実践AIチャットボットUI実装入門
syumai
7
2.5k
Featured
See All Featured
Why Our Code Smells
bkeepers
PRO
339
57k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Automating Front-end Workflow
addyosmani
1371
200k
Gamification - CAS2011
davidbonilla
81
5.5k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
36
2.5k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
54
3k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
252
21k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.1k
Scaling GitHub
holman
463
140k
Transcript
Redis key-value store enhanced
Storing and retrieving > SET what:is:love? "baby ..." > GET
what:is:love? => "baby ..."
Deleting keys > DEL article:1 => 1 | 0
SET-if-not-exists > SETNX video:63:title "The Doors" => 1 | 0
Increment > SET online:users 0 > INCR online:users => 1
> INCR online:users => 2 > GET online:users => 2 > DEL online:users > INCR online:users => 1
Expiring - TTL > SET balance:sheet "<p>$1</p>" > EXPIRE balance:sheet
60 > TTL balance:sheet => 59 > TTL ruby => -1
Lists (Ordered) > RPUSH headlines 86 > RPUSH headlines 77
> LPUSH headlines 458 > LRANGE headlines 0 -1 => ["458", "86", "77"] > LRANGE headlines 1 2 => ["86", "77"]
Lists (cont.) > LLEN headlines => 3 > LPOP headlines
=> "458" > RPOP headlines => "77"
Sets > SADD social:networks twitter > SADD social:networks facebook >
SADD social:networks google+ > SCARD social:networks => 3
Sets (cont.) > SREM social:networks twitter => 1 > SCARD
social:networks => 2 > SISMEMBER social:networks twitter => 0 > SISMEMBER social:networks google+ => 1
Sets (cont.) > SMEMBERS social-networks => ["google+", "facebook"] > SRANDMEMBER
social-networks => ["facebook"]
Sets (cont.) > SADD cool-sites facebook > SINTER social-networks cool-sites
=> ["facebook"]
Sorted Sets (by score) > ZADD languages 10 Ruby >
ZADD languages 9.5 Java > ZADD languages 4 C# > ZRANGE languages 0 -1 => ["C#", "Java", "Ruby"]
Sorted Sets (cont.) > ZREVRANGE languages 0 -1 => ["Ruby",
"Java", "C#"] > ZRANGEBYSCORE languages 5 inf => ["Java", "Ruby"] > ZREVRANGEBYSCORE languages inf 5 WITHSCORES LIMIT 0 10 => ["Ruby", "10", "Java", "9.5"]
Sorted Sets (cont.) > ZSCORE languages Ruby => 10 >
ZCOUNT languages 3 5 => 1 > ZREMRANGEBYRANK languages 0 1 => 2 > ZRANGE languages 0 -1 WITHSCORES => ["Ruby", "10"]
Hashes > HMSET user:45 email
[email protected]
name Guilherme age 27
> HGETALL user:45 => ["email", "
[email protected]
", "name", "Guilherme", "age", "27"]
Hashes (cont.) > HSET user:45 name Mello > HGET user:45
name => Mello
Hashes (cont.) > HLEN user:45 => 3 > HDEL user:45
name > HEXISTS user:45 name => 0 > HKEYS user:45 => ["email", "age"]
> RPUSH numbers 50 > RPUSH numbers 43 > LPUSH
numbers 67 > LRANGE numbers 0 -1 => ["67", "50", "43"] > SORT numbers => ["43", "50", "67"] Sorting
Sorting (cont.) > LPUSH things car > RPUSH things ball
> RPUSH things pen > LRANGE things 0 -1 => ["car", "ball", "pen"] > SORT things ALPHA DESC => ["pen", "car", "ball"]
Sort by external keys > LPUSH account:ids 2 > RPUSH
account:ids 3 > RPUSH account:ids 1 > SET account:2:logins 50 > SET account:3:logins 23 > SET account:1:logins 12
> LRANGE account:ids 0 -1 => ["2", "3", "1"] >
SORT account:ids BY account:*: logins => ["1", "3", "2"] Sort by external keys (cont.)
Retrieving external keys > SET account:1 "dhh" > SET account:2
"tenderlove" > SET account:3 "matz"
Retrieving external keys (cont.) > SORT account:ids BY account:*:logins GET
account:* => ["dhh", "matz", "tenderlove"] > SORT account:ids BY account:*:logins GET account:* GET # => ["dhh", "1", "matz", "3", "tenderlove", "2"]
Storing the result list > SORT account:ids BY account:*:logins GET
account:* GET # STORE account:list > LRANGE account:list 0 -1 => ["dhh", "1", "matz", "3", "tenderlove", "2"]
Sorting and retrieving with hashes > HMSET account:1:profile logins 12
> HMSET account:2:profile logins 50 > HMSET account:3:profile logins 23 > HMSET account:1:hash name dhh > HMSET account:2:hash name tenderlove > HMSET account:3:hash name matz
Sorting and retrieving with hashes (cont.) > SORT account:ids BY
account:*:profile->logins GET account:*:hash->name => ["dhh", "matz", "tenderlove"]
Check out more on http://redis.io or http://lmgtfy.com/?q=redis Thanks!