Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
tips:db:redis [2017/11/06 14:24] – created scipio | tips:db:redis [2017/11/07 13:44] (current) – [redis] scipio | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== redis ====== | ====== redis ====== | ||
+ | * [[https:// | ||
+ | * [[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** | ||
+ | |||
+ | namespace: | ||
+ | < | ||
+ | INCR gianoauth: | ||
+ | HSET gianoauth: | ||
+ | </ | ||
+ | |||
+ | add an INDEX with **sets**: collections of strings that are unordered and cannot contain duplicates | ||
+ | < | ||
+ | SADD gianoauth: | ||
+ | </ | ||
+ | |||
+ | visits | ||
+ | < | ||
+ | HINCRBY gianoauth: | ||
+ | </ | ||
+ | |||
+ | use multi exec to surround HSET and SADD | ||
+ | < | ||
+ | MULTI | ||
+ | HSET ... | ||
+ | HSET ... | ||
+ | SADD ... | ||
+ | EXEC | ||
+ | </ | ||
+ | |||
+ | **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 ===== | ||