Redis Notes
- C
- Corss-Platform
- NoSQL
Install
Usage
$ redis-cli
Data Types
- Strings, Lists, Sets, Sorted Sets, Hashes
- case-sensitive
clear
: clear consoleping
: test redis workFLUSHALL
: 清空ECHO '123'
Strings
SET foo 100
GET foo
SET bar 'hi'
GET bar
INCR foo
: +1DECR foo
: -1EXISTS foo
: 是否存在EXISTS foooo
SET server:name hihi
GET server:name
SET server:port 8000
GET server:port
EXPIRE bar 50
: 50秒後過期TTL bar
: 看剩幾秒
SETEX bar 30 "hi"
: 過期前設值TTL bar
: 看剩幾秒PERSIST bar
: 永久存在
MSET
: 設定很多值APPEND
: 串接加上RENAME
: 改名
Lists (L)
LPUSH people "abby1"
LPUSH people "abby2"
RPUSH people "abby3"
RPUSH people "abby4"
LRANGE people 0 -1
: print allLRANGE people 0 1
: index 0, 1
LPOP people
RPOP peolple
LINSERT people BEFORE "abby2" "abbyX"
Sets (S)
SADD cars "Ford"
SADD cars "Honda"
SADD cars "BWM"
SISMEMBER cars "Ford"
SMEMBERS cars
SMOVE cars mycars "Ford"
SREM
: remove
Sorted Sets (Z)
ZADD users 1988 'abby'
ZADD users 1288 'ybba'
ZRANGE users 0 -1
: print all
ZRANK user 'abby'
: 回傳排名
Hashes (H)
HSET user:abby name "Abby"
HSET user:abby email "abby@com"
HGET user:abby
HGET user:abby email
HGETALL user:abby
Data Persistence
Snapshottingsave 60 1000
Applications
- 短網址系統
- 統計系統
- 秒殺搶購系統