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 16:19] – [gui] 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 8: | Line 74: | ||
namespace: | namespace: | ||
< | < | ||
- | HSET gianoauth:realms:users: | + | INCR gianoauth:realm:next_user_id => 1 |
- | HSET gianoauth:realms:users:scipio | + | HSET gianoauth:realm:user:1 id 1 username " |
- | HSET gianoauth: | + | |
</ | </ | ||
add an INDEX with **sets**: collections of strings that are unordered and cannot contain duplicates | add an INDEX with **sets**: collections of strings that are unordered and cannot contain duplicates | ||
< | < | ||
- | SADD gianoauth:realms:all-users gianoauth: | + | SADD gianoauth:realm:all-users gianoauth: |
+ | </ | ||
+ | |||
+ | visits | ||
+ | < | ||
+ | HINCRBY gianoauth: | ||
</ | </ | ||
Line 27: | Line 97: | ||
</ | </ | ||
+ | **sorted set**: like a set a sorted set only allows members without repeats, but also allows you to specify a score | ||
+ | < | ||
+ | ZADD gianoauth: | ||
+ | </ | ||
===== gui ===== | ===== gui ===== | ||