Redis數(shù)據(jù)結(jié)構(gòu)與操作
1. 數(shù)據(jù)類型及操作
Redis所有單個操作都是原子操作渤昌,多個操作支持事務(wù)仗阅。
1.1 String
SET key value
GET key
MSET key value [key value ...] // 設(shè)置多個key魂仍、value
MGET key [key ...]
SETNX key value // 只有在key不存在時嗡害,才設(shè)置
SETEX key seconds value // 設(shè)置key奴拦,同時設(shè)置生存時間
INCR key
DECR key
INCRBY key increment
DECRBY key decrement
1.2 Hash
HSET key field value
HGET key field
HMGET key field [field ...]
HGETALL key
HDEL key filed [field ...]
HEXISTS key field
HINCRBY key field increment
HKEYS key // 返回哈希表key中的所有域
HLEN key // 返回哈希表key中域的數(shù)量
HVALS key
HMSET key field value [field value ...]
3.3 List
LPUSH key value [value ...]
LPUSHX key value
RPUSH key value [value ...]
RPUSHX key value
LPOP key
RPOP key
LRANGE key start stop // -1表示列表最后一個元素,-2表示列表倒數(shù)第二個元素
LREM key count value
LSET key index value
LINDEX key index
LINSERT key BEFORE|AFTER pivot value
LLEN key
LTRIM key start stop
RPOPLPUSH source destination
BLPOP key timeout // 如果列表沒有元素會阻塞列表直到等待超時或發(fā)現(xiàn)可彈出元素為止垃僚。
BRPOP key timeout // 如果列表沒有元素會阻塞列表直到等待超時或發(fā)現(xiàn)可彈出元素為止集绰。
BRPOPLPUSH source destination timeout // 阻塞
3.4 Set
SADD key member [member ...]
SCARD key
SDIFF key [key ...] // 差集
SDIFFSTORE destination key [key ...]
SINTER key [key ...] // 交集
SINTER destination key [key ...]
SISMEMBER key member
SMEMBERS key
SMOVE source destination member
SPOP key [count]
SRANDMEMBER key [count]
SREM key member [member ...]
SUNION key [key ...]
SUNIONSTORE destination key [key ...]
3.5 SortedSort
ZADD key score member [[score member]...]
ZCARD key
ZCOUNT key min max
ZRANGE key start stop [WITHSCORES]
ZREVRANGE key start stop [WITHSCORES]
ZRANK key member
ZREVRANK key member
ZREM key member [member ...]
ZREMRANGEBYRANK key start stop
ZREMRANGEBYSCORE key min max
3.6 Key
DEL key [key ...]
EXISTS key
EXPIRE key seconds
EXPIREAT key timestamp
KEYS pattern
MIGRATE host port key destination-db timeout [COPY][REPLACE]
MOVE key db
PERSIST key
RANDOMKEY
RENAME key newkey
TTL key
PTTL key
TYPE key
3.7 系統(tǒng)相關(guān)命令
BGREWRITEAOF
BGSAVE
CLIENT KILL host:port
CLIENT LIST
CONFIG GET parameter
CONFIG RESETSTAT
CONFIG REWRITE
CONFIG SET parameter value
SELECT index
DBSIZE
DEBUG OBJECT key
FLUSHALL
FLUSHDB
INFO [section]
LASTSAVE
MONITOR
SHUTDOWN [SAVE|NOSAVE]
3.8 事務(wù)
WATCH
UNWATCH
MULTI
EXEC
DISCARD