ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Redis? ?Cheat? ?Sheet?
Objects? ?in? ?Redis?
¡ñ must? ?have? ?a? ?key?
¡ñ keys? ?are? ?colon? ?separated?
¡ñ value? ?can? ?be? ?hash,? ?set,? ?list,? ?sortedset,? ?string?
¡ñ can? ?have? ?an? ?expiry?
? ?
Hashes:?
¡ñ Use? ?to? ?store? ?"objects"? ?from? ?object? ?oriented? ?programming?
"blogs:234":? ?{
? ?? ?? ?? ?? ?? ?? ?? ?? ?"id":? ?234,
? ?? ?? ?? ?? ?? ?? ?? ?? ?"title":? ?"Introduction? ?to? ?Redis",
? ?? ?? ?? ?? ?? ?? ?? ?? ?"views":? ?1024
? ?? ?? ?? ?? ?? ?}
¡ñ hmset? ?blogs:234? ?id? ?234? ?title? ?"Introduction? ?to? ?Redis"? ?views? ?1024?
¡ñ hgetall? ?blogs:234?
¡ñ hincrby? ?blogs:234? ?views? ?1?
?
Sets:?
¡ñ Only? ?unique? ?items.? ?No? ?duplicates?
¡ñ Elements? ?are? ?not? ?ordered?
¡ñ Can? ?check? ?if? ?element? ?exists? ?very? ?quickly?
¡ñ Use? ?case:? ?Count? ?unique? ?items?
¡ñ Use? ?case:? ?Check? ?if? ?item? ?exists?
¡ñ Use? ?case:? ?Perform? ?logical? ?UNION? ?/? ?INTERSECTION? ?operations?
¡ñ Two? ?ways? ?to? ?represent? ?same? ?information,? ?choose? ?based? ?on? ?use?
case? ?set? ?of? ?integers? ?consumes? ?less? ?memory,? ?is? ?very? ?efficient?
"blogs:234:tags"? ?==>? ?set("aws",? ?"redis",? ?"cache")
v/s
"tags:aws:blogs"? ?==>? ?set(234,? ?532,? ?332)
Lists:?
¡ñ Duplicates? ?allowed.??
¡ñ Very? ?well? ?defined? ?order? ?of? ?elements?
¡ñ Expensive? ?to? ?check? ?if? ?element? ?already? ?exists? ?in? ?list?
?? ?2017? ?HashedIn? ?Technologies? ?Pvt.? ?Ltd.?
¡ñ Operations? ?near? ?head? ?/? ?tail? ?very? ?fast.?
¡ñ Operations? ?near? ?centre? ?elements? ?slower?
¡ñ Can? ?use? ?as? ?a? ?queue? ?or? ?a? ?stack?
¡ñ Operations? ?can? ?block? ?if? ?no? ?elements? ?are? ?available,? ?useful?
¡ñ Easy? ?to? ?restrict? ?length? ?using? ?ltrim? ?command?
¡ñ Use? ?case:? ?Recent? ?items,? ?recent? ?logs?
¡ñ Use? ?case:? ?Queue? ?to? ?maintain? ?tasks?
?
Sorted? ?Sets?
¡ñ Like? ?a? ?set,? ?only? ?allows? ?unique? ?items?
¡ñ Every? ?element? ?can? ?have? ?a? ?numeric? ?score?
¡ñ Score? ?can? ?represent? ?anything? ?-? ?sales,? ?count? ?of? ?orders,? ?points? ?in?
a? ?game? ?etc.?
¡ñ Elements? ?are? ?always? ?maintained? ?in? ?order? ?of? ?score??
¡ñ If? ?score? ?of? ?two? ?elements? ?are? ?same,? ?elements? ?are? ?sorted? ?in?
lexicographical? ?order? ?-? ?the? ?way? ?you? ?see? ?in? ?oxford's? ?dictionary?
¡ñ Use? ?case:? ?Leader? ?boards? ?-? ?Top? ?10? ?players,? ?Products? ?with? ?least?
sales,??
¡ñ Use? ?case:? ?Autocomplete? ?API??
Strings:?
¡ñ Strings? ?are? ?binary,? ?and? ?can? ?store? ?integers,? ?floats,? ?text?
¡ñ You? ?can? ?treat? ?the? ?string? ?as? ?a? ?very? ?large? ?bitmap?
¡ñ You? ?can? ?split? ?the? ?string? ?into? ?smaller? ?fields,? ?and? ?then? ?set/get?
each? ?field? ?using? ?the? ?bitfield? ?command?
?
?? ?2017? ?HashedIn? ?Technologies? ?Pvt.? ?Ltd.?

More Related Content

Redis Cheat Sheet

  • 1. Redis? ?Cheat? ?Sheet? Objects? ?in? ?Redis? ¡ñ must? ?have? ?a? ?key? ¡ñ keys? ?are? ?colon? ?separated? ¡ñ value? ?can? ?be? ?hash,? ?set,? ?list,? ?sortedset,? ?string? ¡ñ can? ?have? ?an? ?expiry? ? ? Hashes:? ¡ñ Use? ?to? ?store? ?"objects"? ?from? ?object? ?oriented? ?programming? "blogs:234":? ?{ ? ?? ?? ?? ?? ?? ?? ?? ?? ?"id":? ?234, ? ?? ?? ?? ?? ?? ?? ?? ?? ?"title":? ?"Introduction? ?to? ?Redis", ? ?? ?? ?? ?? ?? ?? ?? ?? ?"views":? ?1024 ? ?? ?? ?? ?? ?? ?} ¡ñ hmset? ?blogs:234? ?id? ?234? ?title? ?"Introduction? ?to? ?Redis"? ?views? ?1024? ¡ñ hgetall? ?blogs:234? ¡ñ hincrby? ?blogs:234? ?views? ?1? ? Sets:? ¡ñ Only? ?unique? ?items.? ?No? ?duplicates? ¡ñ Elements? ?are? ?not? ?ordered? ¡ñ Can? ?check? ?if? ?element? ?exists? ?very? ?quickly? ¡ñ Use? ?case:? ?Count? ?unique? ?items? ¡ñ Use? ?case:? ?Check? ?if? ?item? ?exists? ¡ñ Use? ?case:? ?Perform? ?logical? ?UNION? ?/? ?INTERSECTION? ?operations? ¡ñ Two? ?ways? ?to? ?represent? ?same? ?information,? ?choose? ?based? ?on? ?use? case? ?set? ?of? ?integers? ?consumes? ?less? ?memory,? ?is? ?very? ?efficient? "blogs:234:tags"? ?==>? ?set("aws",? ?"redis",? ?"cache") v/s "tags:aws:blogs"? ?==>? ?set(234,? ?532,? ?332) Lists:? ¡ñ Duplicates? ?allowed.?? ¡ñ Very? ?well? ?defined? ?order? ?of? ?elements? ¡ñ Expensive? ?to? ?check? ?if? ?element? ?already? ?exists? ?in? ?list? ?? ?2017? ?HashedIn? ?Technologies? ?Pvt.? ?Ltd.?
  • 2. ¡ñ Operations? ?near? ?head? ?/? ?tail? ?very? ?fast.? ¡ñ Operations? ?near? ?centre? ?elements? ?slower? ¡ñ Can? ?use? ?as? ?a? ?queue? ?or? ?a? ?stack? ¡ñ Operations? ?can? ?block? ?if? ?no? ?elements? ?are? ?available,? ?useful? ¡ñ Easy? ?to? ?restrict? ?length? ?using? ?ltrim? ?command? ¡ñ Use? ?case:? ?Recent? ?items,? ?recent? ?logs? ¡ñ Use? ?case:? ?Queue? ?to? ?maintain? ?tasks? ? Sorted? ?Sets? ¡ñ Like? ?a? ?set,? ?only? ?allows? ?unique? ?items? ¡ñ Every? ?element? ?can? ?have? ?a? ?numeric? ?score? ¡ñ Score? ?can? ?represent? ?anything? ?-? ?sales,? ?count? ?of? ?orders,? ?points? ?in? a? ?game? ?etc.? ¡ñ Elements? ?are? ?always? ?maintained? ?in? ?order? ?of? ?score?? ¡ñ If? ?score? ?of? ?two? ?elements? ?are? ?same,? ?elements? ?are? ?sorted? ?in? lexicographical? ?order? ?-? ?the? ?way? ?you? ?see? ?in? ?oxford's? ?dictionary? ¡ñ Use? ?case:? ?Leader? ?boards? ?-? ?Top? ?10? ?players,? ?Products? ?with? ?least? sales,?? ¡ñ Use? ?case:? ?Autocomplete? ?API?? Strings:? ¡ñ Strings? ?are? ?binary,? ?and? ?can? ?store? ?integers,? ?floats,? ?text? ¡ñ You? ?can? ?treat? ?the? ?string? ?as? ?a? ?very? ?large? ?bitmap? ¡ñ You? ?can? ?split? ?the? ?string? ?into? ?smaller? ?fields,? ?and? ?then? ?set/get? each? ?field? ?using? ?the? ?bitfield? ?command? ? ?? ?2017? ?HashedIn? ?Technologies? ?Pvt.? ?Ltd.?