Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
tips:db:redis [2017/11/06 19:39] – [concepts] scipio | tips:db:redis [2017/11/07 13:44] (current) – [redis] scipio | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== redis ====== | ====== redis ====== | ||
- | ===== concepts ===== | + | |
- | | + | * [[https:// |
+ | |||
+ | ===== string ===== | ||
+ | |||
+ | |||
+ | type **string**: store a value [integer, string, ...] belong a key [string] | ||
+ | < | ||
+ | SET connections 10 | ||
+ | INCR connections => 11 | ||
+ | INCR connections => 12 | ||
+ | DEL connections | ||
+ | INCR connections => 1 | ||
+ | </ | ||
+ | |||
+ | expiring key | ||
+ | < | ||
+ | SET resource: | ||
+ | EXPIRE resource: | ||
+ | </ | ||
+ | |||
+ | ===== list ===== | ||
+ | |||
+ | A list have an order | ||
+ | |||
+ | RPUSH puts the new value at the end of the list. LPUSH puts the new value at the start of the list. LLEN, LPOP, RPOP | ||
+ | < | ||
+ | RPUSH friends " | ||
+ | RPUSH friends " | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | LRANGE friends 0 -1 => 1) " | ||
+ | LRANGE friends 0 1 => 1) " | ||
+ | LRANGE friends 1 2 => 1) " | ||
+ | </ | ||
+ | |||
+ | ===== set ===== | ||
+ | |||
+ | A set does not have an order but each element may only appear once. | ||
+ | |||
+ | < | ||
+ | SADD superpowers " | ||
+ | SADD superpowers "x-ray vision" | ||
+ | SADD superpowers " | ||
+ | SREM superpowers " | ||
+ | |||
+ | SISMEMBER superpowers " | ||
+ | SISMEMBER superpowers " | ||
+ | </ | ||
+ | |||
+ | ===== sorted set ===== | ||
+ | |||
+ | A sorted set is similar to a regular set, but now each value has an associated score. This score is used to sort the elements in the set. | ||
+ | < | ||
+ | ZADD hackers 1940 "Alan Kay" | ||
+ | ZADD hackers 1969 "Linus Torvalds" | ||
+ | ZADD hackers 1906 "Grace Hopper" | ||
+ | ZADD hackers 1953 " | ||
+ | |||
+ | ZRANGE hackers 2 4 | ||
+ | 1) " | ||
+ | 2) "Linus Torvalds" | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== hash ===== | ||
type **hash** for **tables and rows** | type **hash** for **tables and rows** | ||
Line 9: | Line 75: | ||
< | < | ||
INCR gianoauth: | INCR gianoauth: | ||
- | HSET gianoauth: | + | HSET gianoauth: |
</ | </ | ||
Line 15: | Line 81: | ||
< | < | ||
SADD gianoauth: | SADD gianoauth: | ||
+ | </ | ||
+ | |||
+ | visits | ||
+ | < | ||
+ | HINCRBY gianoauth: | ||
</ | </ | ||