這是一個redis快速參考備忘單,其中列出了 redis 命令的示例
啟動Redis
$ redis-server
連接到 redis(Redis CLI 客戶端)
$ redis-cli
連接到redis(telnet)
$ telnet 127.0.0.1 6379
redis> PING
PONG
redis> SET mykey "Hello world"
OK
redis> GET mykey
"Hello world"
APPEND key value
redis> EXISTS mykey
(integer) 0
redis> APPEND mykey "Hello"
(integer) 5
redis> APPEND mykey " World"
(integer) 11
redis> GET mykey
"Hello World"
將值附加到鍵
BITCOUNT key [start end]
redis> SET mykey "foobar"
"OK"
redis> BITCOUNT mykey
(integer) 26
redis> BITCOUNT mykey 0 0
(integer) 4
redis> BITCOUNT mykey 1 1
(integer) 6
計算字符串中的設(shè)置位
BITFIELD key [GET type offset] [SET type offset value] [INCRBY type offset increment] [OVERFLOW WRAP|SAT|FAIL]
redis> BITFIELD mykey INCRBY i5 100 1 GET u4 0
1) (integer) 1
2) (integer) 0
對字符串執(zhí)行任意位域整數(shù)運算
BITOP operation destkey key [key ...]
redis> SET key1 "foobar"
"OK"
redis> SET key2 "abcdef"
"OK"
redis> BITOP AND dest key1 key2
(integer) 6
redis> GET dest
"`bc`ab"
在字符串之間執(zhí)行按位運算
BITPOS key bit [start] [end]
redis> SET mykey "\xff\xf0\x00"
"OK"
redis> BITPOS mykey 0
(integer) 12
redis> SET mykey "\x00\xff\xf0"
"OK"
redis> BITPOS mykey 1 0
(integer) 8
redis> BITPOS mykey 1 2
(integer) 16
redis> set mykey "\x00\x00\x00"
"OK"
redis> BITPOS mykey 1
(integer) -1
在字符串中查找第一個設(shè)置或清除的位
DECR key
redis> SET mykey "10"
"OK"
redis> DECR mykey
(integer) 9
redis> SET mykey "234293482390480948029348230948"
"OK"
redis> DECR mykey
ERR ERR value is not an integer or out of range
將鍵的整數(shù)值減一
DECRBY key decrement
redis> SET mykey "10"
"OK"
redis> DECRBY mykey 3
(integer) 7
按給定數(shù)字減少鍵的整數(shù)值
GET key
redis> GET nonexisting
(nil)
redis> SET mykey "Hello"
"OK"
redis> GET mykey
"Hello"
獲取一個鍵的值
GETBIT key offset
redis> SETBIT mykey 7 1
(integer) 0
redis> GETBIT mykey 0
(integer) 0
redis> GETBIT mykey 7
(integer) 1
redis> GETBIT mykey 100
(integer) 0
返回存儲在 key 的字符串值中 offset 處的位值
GETRANGE key start end
redis> SET mykey "This is a string"
"OK"
redis> GETRANGE mykey 0 3
"This"
redis> GETRANGE mykey -3 -1
"ing"
redis> GETRANGE mykey 0 -1
"This is a string"
redis> GETRANGE mykey 10 100
"string"
獲取存儲在鍵中的字符串的子字符串
GETSET key value
redis> INCR mycounter
(integer) 1
redis> GETSET mycounter "0"
"1"
redis> GET mycounter
"0"
設(shè)置鍵的字符串值并返回其舊值
INCR key
redis> SET mykey "10"
"OK"
redis> INCR mykey
(integer) 11
redis> GET mykey
"11"
將鍵的整數(shù)值加一
MSETNX key value [key value ...]
redis> MSETNX key1 "Hello" key2 "there"
(integer) 1
redis> MSETNX key2 "new" key3 "world"
(integer) 0
redis> MGET key1 key2 key3
1) "Hello"
2) "there"
3) (nil)
將多個鍵設(shè)置為多個值,僅當(dāng)不存在任何鍵時
INCRBYFLOAT key increment
redis> SET mykey 10.50
"OK"
redis> INCRBYFLOAT mykey 0.1
"10.6"
redis> INCRBYFLOAT mykey -5
"5.6"
redis> SET mykey 5.0e3
"OK"
redis> INCRBYFLOAT mykey 2.0e2
"5200"
將鍵的浮點值增加給定的數(shù)量
MGET key [key ...]
redis> SET key1 "Hello"
"OK"
redis> SET key2 "World"
"OK"
redis> MGET key1 key2 nonexisting
1) "Hello"
2) "World"
3) (nil)
獲取所有給定鍵的值
MSET key value [key value ...]
redis> MSET key1 "Hello" key2 "World"
"OK"
redis> GET key1
"Hello"
redis> GET key2
"World"
將多個鍵設(shè)置為多個值
INCRBY key increment
redis> SET mykey "10"
"OK"
redis> INCRBY mykey 5
(integer) 15
將鍵的整數(shù)值增加給定的數(shù)量
PSETEX key milliseconds value
redis> PSETEX mykey 1000 "Hello"
"OK"
redis> PTTL mykey
(integer) 1000
redis> GET mykey
"Hello"
以毫秒為單位設(shè)置鍵的值和到期時間
SET key value [EX seconds|PX milliseconds|KEEPTTL] [NX|XX] [GET]
redis> SET mykey "Hello"
"OK"
redis> GET mykey
"Hello"
redis> SET anotherkey "will expire in a minute" EX 60
"OK"
設(shè)置一個鍵的字符串值
SETBIT key offset value
redis> SETBIT mykey 7 1
(integer) 0
redis> SETBIT mykey 7 0
(integer) 1
redis> GET mykey
"\u0000"
設(shè)置或清除存儲在鍵的字符串值中偏移處的位
SETEX key seconds value
redis> SETEX mykey 10 "Hello"
"OK"
redis> TTL mykey
(integer) 10
redis> GET mykey
"Hello"
設(shè)置密鑰的值和到期時間
SETNX key value
redis> SETNX mykey "Hello"
(integer) 1
redis> SETNX mykey "World"
(integer) 0
redis> GET mykey
"Hello"
設(shè)置鍵的值,僅當(dāng)鍵不存在時
SETRANGE key offset value
redis> SET key1 "Hello World"
"OK"
redis> SETRANGE key1 6 "Redis"
(integer) 11
redis> GET key1
"Hello Redis"
從指定的偏移量開始覆蓋鍵處的部分字符串
STRLEN key
redis> SET mykey "Hello world"
"OK"
redis> STRLEN mykey
(integer) 11
redis> STRLEN nonexisting
(integer) 0
獲取存儲在鍵中的值的長度
STRALGO LCS algo-specific-argument [algo-specific-argument ...]
redis> STRALGO LCS KEYS key1 key2 IDX
1) "matches"
2) 1) 1) 1) (integer) 4
2) (integer) 7
2) 1) (integer) 5
2) (integer) 8
2) 1) 1) (integer) 2
2) (integer) 3
2) 1) (integer) 0
2) (integer) 1
3) "len"
4) (integer) 6
針對字符串運行算法(當(dāng)前是 LCS)
SADD key member [member ...]
redis> SADD myset "Hello"
(integer) 1
redis> SADD myset "World"
(integer) 1
redis> SADD myset "World"
(integer) 0
redis> SMEMBERS myset
1) "Hello"
2) "World"
將一個或多個成員添加到集合
SCARD key
redis> SADD myset "Hello"
(integer) 1
redis> SADD myset "World"
(integer) 1
redis> SCARD myset
(integer) 2
獲取集合中的成員數(shù)
SDIFF key [key ...]
redis> SADD key1 "a"
(integer) 1
redis> SADD key1 "b"
(integer) 1
redis> SADD key1 "c"
(integer) 1
redis> SADD key2 "c"
(integer) 1
redis> SADD key2 "d"
(integer) 1
redis> SADD key2 "e"
(integer) 1
redis> SDIFF key1 key2
1) "a"
2) "b"
減去多組
SDIFFSTORE destination key [key ...]
redis> SADD key1 "a"
(integer) 1
redis> SADD key1 "b"
(integer) 1
redis> SADD key1 "c"
(integer) 1
redis> SADD key2 "c"
(integer) 1
redis> SADD key2 "d"
(integer) 1
redis> SADD key2 "e"
(integer) 1
redis> SDIFFSTORE key key1 key2
(integer) 2
redis> SMEMBERS key
1) "a"
2) "b"
減去多個集合并將結(jié)果集合存儲在一個鍵中
SINTER key [key ...]
redis> SADD key1 "a"
(integer) 1
redis> SADD key1 "b"
(integer) 1
redis> SADD key1 "c"
(integer) 1
redis> SADD key2 "c"
(integer) 1
redis> SADD key2 "d"
(integer) 1
redis> SADD key2 "e"
(integer) 1
redis> SINTER key1 key2
1) "c"
多組相交
SINTERSTORE destination key [key ...]
redis> SADD key1 "a"
(integer) 1
redis> SADD key1 "b"
(integer) 1
redis> SADD key1 "c"
(integer) 1
redis> SADD key2 "c"
(integer) 1
redis> SADD key2 "d"
(integer) 1
redis> SADD key2 "e"
(integer) 1
redis> SINTERSTORE key key1 key2
(integer) 1
redis> SMEMBERS key
1) "c"
將多個集合相交并將結(jié)果集存儲在一個鍵中
SISMEMBER key member
redis> SADD myset "one"
(integer) 1
redis> SISMEMBER myset "one"
(integer) 1
redis> SISMEMBER myset "two"
(integer) 0
確定給定值是否是集合的成員
SMISMEMBER key member [member ...]
redis> SADD myset "one"
(integer) 1
redis> SADD myset "one"
(integer) 0
redis> SMISMEMBER myset "one" "notamember"
1) (integer) 1
2) (integer) 0
返回與集合的給定元素相關(guān)聯(lián)的成員資格
SMEMBERS key
redis> SADD myset "Hello"
(integer) 1
redis> SADD myset "World"
(integer) 1
redis> SMEMBERS myset
1) "Hello"
2) "World"
獲取集合中的所有成員
SMOVE source destination member
redis> SADD myset "one"
(integer) 1
redis> SADD myset "two"
(integer) 1
redis> SADD myotherset "three"
(integer) 1
redis> SMOVE myset myotherset "two"
(integer) 1
redis> SMEMBERS myset
1) "one"
redis> SMEMBERS myotherset
1) "two"
2) "three"
將成員從一組移動到另一組
SPOP key [count]
redis> SADD myset "one"
(integer) 1
redis> SADD myset "two"
(integer) 1
redis> SADD myset "three"
(integer) 1
redis> SPOP myset
"two"
redis> SMEMBERS myset
1) "one"
2) "three"
redis> SADD myset "four"
(integer) 1
redis> SADD myset "five"
(integer) 1
redis> SPOP myset 3
1) "four"
2) "five"
3) "three"
redis> SMEMBERS myset
1) "one"
從集合中刪除并返回一個或多個隨機成員
SRANDMEMBER key [count]
redis> SADD myset one two three
(integer) 3
redis> SRANDMEMBER myset
"three"
redis> SRANDMEMBER myset 2
1) "two"
2) "three"
redis> SRANDMEMBER myset -5
1) "one"
2) "two"
3) "three"
4) "three"
5) "one"
從集合中獲取一個或多個隨機成員
SREM key member [member ...]
redis> SADD myset "one"
(integer) 1
redis> SADD myset "two"
(integer) 1
redis> SADD myset "three"
(integer) 1
redis> SREM myset "one"
(integer) 1
redis> SREM myset "four"
(integer) 0
redis> SMEMBERS myset
1) "two"
2) "three"
從集合中刪除一個或多個成員
SUNION key [key ...]
redis> SADD key1 "a"
(integer) 1
redis> SADD key1 "b"
(integer) 1
redis> SADD key1 "c"
(integer) 1
redis> SADD key2 "c"
(integer) 1
redis> SADD key2 "d"
(integer) 1
redis> SADD key2 "e"
(integer) 1
redis> SUNION key1 key2
1) "a"
2) "c"
3) "e"
4) "b"
5) "d"
添加多組
SUNIONSTORE destination key [key ...]
redis> SADD key1 "a"
(integer) 1
redis> SADD key1 "b"
(integer) 1
redis> SADD key1 "c"
(integer) 1
redis> SADD key2 "c"
(integer) 1
redis> SADD key2 "d"
(integer) 1
redis> SADD key2 "e"
(integer) 1
redis> SUNIONSTORE key key1 key2
(integer) 5
redis> SMEMBERS key
1) "a"
2) "c"
3) "e"
4) "b"
5) "d"
添加多個集合并將結(jié)果集合存儲在一個鍵中
BLPOP key [key ...] timeout
redis> DEL list1 list2
(integer) 0
redis> RPUSH list1 a b c
(integer) 3
redis> BLPOP list1 list2 0
1) "list1"
2) "a"
刪除并獲取列表中的第一個元素,或阻塞直到一個可用 |
BRPOP key [key ...] timeout
redis> DEL list1 list2
(integer) 0
redis> RPUSH list1 a b c
(integer) 3
redis> BRPOP list1 list2 0
1) "list1"
2) "c"
刪除并獲取列表中的最后一個元素,或者阻塞直到有一個可用 |
LINDEX key index
redis> LPUSH mylist "World"
(integer) 1
redis> LPUSH mylist "Hello"
(integer) 2
redis> LINDEX mylist 0
"Hello"
redis> LINDEX mylist -1
"World"
redis> LINDEX mylist 3
(nil)
通過索引從列表中獲取元素
LINSERT key BEFORE|AFTER pivot element
redis> RPUSH mylist "Hello"
(integer) 1
redis> RPUSH mylist "World"
(integer) 2
redis> LINSERT mylist BEFORE "World" "There"
(integer) 3
redis> LRANGE mylist 0 -1
1) "Hello"
2) "There"
3) "World"
在列表中的另一個元素之前或之后插入一個元素
LLEN key
redis> LPUSH mylist "World"
(integer) 1
redis> LPUSH mylist "Hello"
(integer) 2
redis> LLEN mylist
(integer) 2
獲取列表的長度
LPOP key [count]
redis> RPUSH mylist "one"
(integer) 1
redis> RPUSH mylist "two"
(integer) 2
redis> RPUSH mylist "three"
(integer) 3
redis> LPOP mylist
"one"
redis> LRANGE mylist 0 -1
1) "two"
2) "three"
刪除并獲取列表中的第一個元素
LPOS key element [RANK rank] [COUNT num-matches] [MAXLEN len]
redis> RPUSH mylist a b c d 1 2 3 4 3 3 3
(integer) 11
redis> LPOS mylist 3
(integer) 6
redis> LPOS mylist 3 COUNT 0 RANK 2
1) (integer) 8
2) (integer) 9
3) (integer) 10
返回列表中匹配元素的索引
LPUSH key element [element ...]
redis> LPUSH mylist "world"
(integer) 1
redis> LPUSH mylist "hello"
(integer) 2
redis> LRANGE mylist 0 -1
1) "hello"
2) "world"
將一個或多個元素添加到列表中
LPUSHX key element [element ...]
redis> LPUSH mylist "World"
(integer) 1
redis> LPUSHX mylist "Hello"
(integer) 2
redis> LPUSHX myotherlist "Hello"
(integer) 0
redis> LRANGE mylist 0 -1
1) "Hello"
2) "World"
redis> LRANGE myotherlist 0 -1
(empty list or set)
將元素添加到列表中,僅當(dāng)列表存在時
LRANGE key start stop
redis> RPUSH mylist "one"
(integer) 1
redis> RPUSH mylist "two"
(integer) 2
redis> RPUSH mylist "three"
(integer) 3
redis> LRANGE mylist 0 0
1) "one"
redis> LRANGE mylist -3 2
1) "one"
2) "two"
3) "three"
redis> LRANGE mylist -100 100
1) "one"
2) "two"
3) "three"
redis> LRANGE mylist 5 10
(empty list or set)
從列表中獲取一系列元素
LREM key count element
redis> RPUSH mylist "hello"
(integer) 1
redis> RPUSH mylist "hello"
(integer) 2
redis> RPUSH mylist "foo"
(integer) 3
redis> RPUSH mylist "hello"
(integer) 4
redis> LREM mylist -2 "hello"
(integer) 2
redis> LRANGE mylist 0 -1
1) "hello"
2) "foo"
從列表中刪除元素
LSET key index element
redis> RPUSH mylist "one"
(integer) 1
redis> RPUSH mylist "two"
(integer) 2
redis> RPUSH mylist "three"
(integer) 3
redis> LSET mylist 0 "four"
"OK"
redis> LSET mylist -2 "five"
"OK"
redis> LRANGE mylist 0 -1
1) "four"
2) "five"
3) "three"
通過索引設(shè)置列表中元素的值
LTRIM key start stop
redis> RPUSH mylist "one"
(integer) 1
redis> RPUSH mylist "two"
(integer) 2
redis> RPUSH mylist "three"
(integer) 3
redis> LTRIM mylist 1 -1
"OK"
redis> LRANGE mylist 0 -1
1) "two"
2) "three"
將列表修剪到指定范圍
RPOP key [count]
redis> RPUSH mylist "one"
(integer) 1
redis> RPUSH mylist "two"
(integer) 2
redis> RPUSH mylist "three"
(integer) 3
redis> RPOP mylist
"three"
redis> LRANGE mylist 0 -1
1) "one"
2) "two"
刪除并獲取列表中的最后一個元素
RPOPLPUSH source destination
redis> RPUSH mylist "one"
(integer) 1
redis> RPUSH mylist "two"
(integer) 2
redis> RPUSH mylist "three"
(integer) 3
redis> RPOPLPUSH mylist myotherlist
"three"
redis> LRANGE mylist 0 -1
1) "one"
2) "two"
redis> LRANGE myotherlist 0 -1
1) "three"
刪除列表中的最后一個元素,將其添加到另一個列表中并返回
LMOVE source destination LEFT|RIGHT LEFT|RIGHT
redis> RPUSH mylist "one"
(integer) 1
redis> RPUSH mylist "two"
(integer) 2
redis> RPUSH mylist "three"
(integer) 3
redis> LMOVE mylist myotherlist RIGHT LEFT
"three"
redis> LMOVE mylist myotherlist LEFT RIGHT
"one"
redis> LRANGE mylist 0 -1
1) "two"
redis> LRANGE myotherlist 0 -1
1) "three"
2) "one"
從列表中彈出一個元素,將其推送到另一個列表并返回
RPUSH key element [element ...]
redis> RPUSH mylist "hello"
(integer) 1
redis> RPUSH mylist "world"
(integer) 2
redis> LRANGE mylist 0 -1
1) "hello"
2) "world"
將一個或多個元素附加到列表中
RPUSHX key element [element ...]
redis> RPUSH mylist "Hello"
(integer) 1
redis> RPUSHX mylist "World"
(integer) 2
redis> RPUSHX myotherlist "World"
(integer) 0
redis> LRANGE mylist 0 -1
1) "Hello"
2) "World"
redis> LRANGE myotherlist 0 -1
(empty list or set)
將元素追加到列表中,僅當(dāng)列表存在時
HDEL key field [field ...]
redis> HSET myhash field1 "foo"
(integer) 1
redis> HDEL myhash field1
(integer) 1
redis> HDEL myhash field2
(integer) 0
刪除一個或多個哈希字段
HEXISTS key field
redis> HSET myhash field1 "foo"
(integer) 1
redis> HEXISTS myhash field1
(integer) 1
redis> HEXISTS myhash field2
(integer) 0
確定哈希字段是否存在
HGET key field
redis> HSET myhash field1 "foo"
(integer) 1
redis> HGET myhash field1
"foo"
redis> HGET myhash field2
(nil)
獲取哈希字段的值
HGETALL key
redis> HSET myhash field1 "Hello"
(integer) 1
redis> HSET myhash field2 "World"
(integer) 1
redis> HGETALL myhash
1) "field1"
2) "Hello"
3) "field2"
4) "World"
獲取哈希中的所有字段和值
HINCRBY key field increment
redis> HSET myhash field 5
(integer) 1
redis> HINCRBY myhash field 1
(integer) 6
redis> HINCRBY myhash field -1
(integer) 5
redis> HINCRBY myhash field -10
(integer) -5
將散列字段的整數(shù)值增加給定的數(shù)字
HINCRBYFLOAT key field increment
redis> HSET mykey field 10.50
(integer) 1
redis> HINCRBYFLOAT mykey field 0.1
"10.6"
redis> HINCRBYFLOAT mykey field -5
"5.6"
redis> HSET mykey field 5.0e3
(integer) 0
redis> HINCRBYFLOAT mykey field 2.0e2
"5200"
將哈希字段的浮點值增加給定的數(shù)量
HKEYS key
redis> HSET myhash field1 "Hello"
(integer) 1
redis> HSET myhash field2 "World"
(integer) 1
redis> HKEYS myhash
1) "field1"
2) "field2"
獲取哈希中的所有字段
HLEN key
redis> HSET myhash field1 "Hello"
(integer) 1
redis> HSET myhash field2 "World"
(integer) 1
redis> HLEN myhash
(integer) 2
獲取哈希中的字段數(shù)
HMGET key field [field ...]
redis> HSET myhash field1 "Hello"
(integer) 1
redis> HSET myhash field2 "World"
(integer) 1
redis> HMGET myhash field1 field2 nofield
1) "Hello"
2) "World"
3) (nil)
獲取所有給定哈希字段的值
HMSET key field value [field value ...]
redis> HMSET myhash field1 "Hello" field2 "World"
"OK"
redis> HGET myhash field1
"Hello"
redis> HGET myhash field2
"World"
將多個哈希字段設(shè)置為多個值
HSET key field value [field value ...]
redis> HSET myhash field1 "Hello"
(integer) 1
redis> HGET myhash field1
"Hello"
設(shè)置哈希字段的字符串值
HSETNX key field value
redis> HSETNX myhash field "Hello"
(integer) 1
redis> HSETNX myhash field "World"
(integer) 0
redis> HGET myhash field
"Hello"
設(shè)置哈希字段的值,僅當(dāng)該字段不存在時
HSTRLEN key field
redis> HMSET myhash f1 HelloWorld f2 99 f3 -256
"OK"
redis> HSTRLEN myhash f1
(integer) 10
redis> HSTRLEN myhash f2
(integer) 2
redis> HSTRLEN myhash f3
(integer) 4
獲取哈希字段值的長度
HVALS key
redis> HSET myhash field1 "Hello"
(integer) 1
redis> HSET myhash field2 "World"
(integer) 1
redis> HVALS myhash
1) "Hello"
2) "World"
獲取哈希中的所有值
BZPOPMIN key [key ...] timeout
redis> DEL zset1 zset2
(integer) 0
redis> ZADD zset1 0 a 1 b 2 c
(integer) 3
redis> BZPOPMIN zset1 zset2 0
1) "zset1"
2) "a"
3) "0"
從一個或多個排序集中刪除并返回分?jǐn)?shù)最低的成員,或阻止直到有一個可用
BZPOPMAX key [key ...] timeout
redis> DEL zset1 zset2
(integer) 0
redis> ZADD zset1 0 a 1 b 2 c
(integer) 3
redis> BZPOPMAX zset1 zset2 0
1) "zset1"
2) "c"
3) "2"
從一個或多個排序集中刪除并返回得分最高的成員,或阻止直到有一個可用
ZADD key [NX|XX] [GT|LT] [CH] [INCR] score member [score member ...]
redis> ZADD myzset 1 "one"
(integer) 1
redis> ZADD myzset 1 "uno"
(integer) 1
redis> ZADD myzset 2 "two" 3 "three"
(integer) 2
redis> ZRANGE myzset 0 -1 WITHSCORES
1) "one"
2) "1"
3) "uno"
4) "1"
5) "two"
6) "2"
7) "three"
8) "3"
將一個或多個成員添加到已排序的集合中,如果已經(jīng)存在則更新其分?jǐn)?shù)
ZCARD key
redis> ZADD myzset 1 "one"
(integer) 1
redis> ZADD myzset 2 "two"
(integer) 1
redis> ZCARD myzset
(integer) 2
獲取有序集合中的成員數(shù)
ZSCORE key member
redis> ZADD myzset 1 "one"
(integer) 1
redis> ZSCORE myzset "one"
"1"
獲取與排序集中的給定成員相關(guān)聯(lián)的分?jǐn)?shù)
ZCOUNT key min max
redis> ZADD myzset 1 "one"
(integer) 1
redis> ZADD myzset 2 "two"
(integer) 1
redis> ZADD myzset 3 "three"
(integer) 1
redis> ZCOUNT myzset -inf +inf
(integer) 3
redis> ZCOUNT myzset (1 3
(integer) 2
用給定值內(nèi)的分?jǐn)?shù)計算排序集中的成員
ZDIFF numkeys key [key ...] [WITHSCORES]
redis> ZADD zset1 1 "one"
(integer) 1
redis> ZADD zset1 2 "two"
(integer) 1
redis> ZADD zset1 3 "three"
(integer) 1
redis> ZADD zset2 1 "one"
(integer) 1
redis> ZADD zset2 2 "two"
(integer) 1
redis> ZDIFF 2 zset1 zset2
1) "three"
redis> ZDIFF 2 zset1 zset2 WITHSCORES
1) "three"
2) "3"
減去多個排序集
ZDIFFSTORE destination numkeys key [key ...]
redis> ZADD zset1 1 "one"
(integer) 1
redis> ZADD zset1 2 "two"
(integer) 1
redis> ZADD zset1 3 "three"
(integer) 1
redis> ZADD zset2 1 "one"
(integer) 1
redis> ZADD zset2 2 "two"
(integer) 1
redis> ZDIFFSTORE out 2 zset1 zset2
(integer) 1
redis> ZRANGE out 0 -1 WITHSCORES
1) "three"
2) "3"
減去多個排序集并將結(jié)果排序集存儲在一個新鍵中
ZINCRBY key increment member
redis> ZADD myzset 1 "one"
(integer) 1
redis> ZADD myzset 2 "two"
(integer) 1
redis> ZINCRBY myzset 2 "one"
"3"
redis> ZRANGE myzset 0 -1 WITHSCORES
1) "two"
2) "2"
3) "one"
4) "3"
增加排序集中成員的分?jǐn)?shù)
ZINTER numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX] [WITHSCORES]
redis> ZADD zset1 1 "one"
(integer) 1
redis> ZADD zset1 2 "two"
(integer) 1
redis> ZADD zset2 1 "one"
(integer) 1
redis> ZADD zset2 2 "two"
(integer) 1
redis> ZADD zset2 3 "three"
(integer) 1
redis> ZINTER 2 zset1 zset2
1) "one"
2) "two"
redis> ZINTER 2 zset1 zset2 WITHSCORES
1) "one"
2) "2"
3) "two"
4) "4"
將多個排序集相交
ZINTERSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]
redis> ZADD zset1 1 "one"
(integer) 1
redis> ZADD zset1 2 "two"
(integer) 1
redis> ZADD zset2 1 "one"
(integer) 1
redis> ZADD zset2 2 "two"
(integer) 1
redis> ZADD zset2 3 "three"
(integer) 1
redis> ZINTERSTORE out 2 zset1 zset2 WEIGHTS 2 3
(integer) 2
redis> ZRANGE out 0 -1 WITHSCORES
1) "one"
2) "5"
3) "two"
4) "10"
將多個排序集相交并將結(jié)果排序集存儲在一個新鍵中
ZLEXCOUNT key min max
redis> ZADD myzset 0 a 0 b 0 c 0 d 0 e
(integer) 5
redis> ZADD myzset 0 f 0 g
(integer) 2
redis> ZLEXCOUNT myzset - +
(integer) 7
redis> ZLEXCOUNT myzset [b [f
(integer) 5
計算給定字典范圍之間排序集中的成員數(shù)
ZPOPMAX key [count]
redis> ZADD myzset 1 "one"
(integer) 1
redis> ZADD myzset 2 "two"
(integer) 1
redis> ZADD myzset 3 "three"
(integer) 1
redis> ZPOPMAX myzset
1) "three"
2) "3"
刪除并返回排序集中得分最高的成員
ZPOPMIN key [count]
redis> ZADD myzset 1 "one"
(integer) 1
redis> ZADD myzset 2 "two"
(integer) 1
redis> ZADD myzset 3 "three"
(integer) 1
redis> ZPOPMIN myzset
1) "one"
2) "1"
刪除并返回排序集中得分最低的成員
ZRANGE key start stop [WITHSCORES]
redis> ZADD myzset 1 "one"
(integer) 1
redis> ZADD myzset 2 "two"
(integer) 1
redis> ZADD myzset 3 "three"
(integer) 1
redis> ZRANGE myzset 0 -1
1) "one"
2) "two"
3) "three"
redis> ZRANGE myzset 2 3
1) "three"
redis> ZRANGE myzset -2 -1
1) "two"
2) "three"
按索引返回排序集中的成員范圍
ZRANGEBYLEX key min max [LIMIT offset count]
redis> ZADD myzset 0 a 0 b 0 c 0 d 0 e 0 f 0 g
(integer) 7
redis> ZRANGEBYLEX myzset - [c
1) "a"
2) "b"
3) "c"
redis> ZRANGEBYLEX myzset - (c
1) "a"
2) "b"
redis> ZRANGEBYLEX myzset [aaa (g
1) "b"
2) "c"
3) "d"
4) "e"
5) "f"
按字典順序返回排序集中的成員范圍
ZREVRANGEBYLEX key max min [LIMIT offset count]
redis> ZADD myzset 0 a 0 b 0 c 0 d 0 e 0 f 0 g
(integer) 7
redis> ZREVRANGEBYLEX myzset [c -
1) "c"
2) "b"
3) "a"
redis> ZREVRANGEBYLEX myzset (c -
1) "b"
2) "a"
redis> ZREVRANGEBYLEX myzset (g [aaa
1) "f"
2) "e"
3) "d"
4) "c"
5) "b"
返回排序集中的成員范圍,按字典序范圍,從高到低的字符串排序。
ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]
redis> ZADD myzset 1 "one"
(integer) 1
redis> ZADD myzset 2 "two"
(integer) 1
redis> ZADD myzset 3 "three"
(integer) 1
redis> ZRANGEBYSCORE myzset -inf +inf
1) "one"
2) "two"
3) "three"
redis> ZRANGEBYSCORE myzset 1 2
1) "one"
2) "two"
redis> ZRANGEBYSCORE myzset (1 2
1) "two"
redis> ZRANGEBYSCORE myzset (1 (2
(empty list or set)
按分?jǐn)?shù)返回排序集中的成員范圍
ZRANK key member
redis> ZADD myzset 1 "one"
(integer) 1
redis> ZADD myzset 2 "two"
(integer) 1
redis> ZADD myzset 3 "three"
(integer) 1
redis> ZRANK myzset "three"
(integer) 2
redis> ZRANK myzset "four"
(nil)
確定有序集合中成員的索引
ZREM key member [member ...]
redis> ZADD myzset 1 "one"
(integer) 1
redis> ZADD myzset 2 "two"
(integer) 1
redis> ZADD myzset 3 "three"
(integer) 1
redis> ZREM myzset "two"
(integer) 1
redis> ZRANGE myzset 0 -1 WITHSCORES
1) "one"
2) "1"
3) "three"
4) "3"
從排序集中刪除一個或多個成員
ZREMRANGEBYLEX key min max
redis> ZADD myzset 0 aaaa 0 b 0 c 0 d 0 e
(integer) 5
redis> ZADD myzset 0 foo 0 zap 0 zip 0 ALPHA 0 alpha
(integer) 5
redis> ZRANGE myzset 0 -1
1) "ALPHA"
2) "aaaa"
3) "alpha"
4) "b"
5) "c"
6) "d"
7) "e"
8) "foo"
9) "zap"
10) "zip"
redis> ZREMRANGEBYLEX myzset [alpha [omega
(integer) 6
redis> ZRANGE myzset 0 -1
1) "ALPHA"
2) "aaaa"
3) "zap"
4) "zip"
刪除給定字典范圍之間排序集中的所有成員
ZREMRANGEBYRANK key start stop
redis> ZADD myzset 1 "one"
(integer) 1
redis> ZADD myzset 2 "two"
(integer) 1
redis> ZADD myzset 3 "three"
(integer) 1
redis> ZREMRANGEBYRANK myzset 0 1
(integer) 2
redis> ZRANGE myzset 0 -1 WITHSCORES
1) "three"
2) "3"
刪除給定索引內(nèi)排序集中的所有成員
ZREMRANGEBYSCORE key min max
redis> ZADD myzset 1 "one"
(integer) 1
redis> ZADD myzset 2 "two"
(integer) 1
redis> ZADD myzset 3 "three"
(integer) 1
redis> ZREMRANGEBYSCORE myzset -inf (2
(integer) 1
redis> ZRANGE myzset 0 -1 WITHSCORES
1) "two"
2) "2"
3) "three"
4) "3"
刪除給定分?jǐn)?shù)內(nèi)排序集中的所有成員
ZREVRANGE key start stop [WITHSCORES]
redis> ZADD myzset 1 "one"
(integer) 1
redis> ZADD myzset 2 "two"
(integer) 1
redis> ZADD myzset 3 "three"
(integer) 1
redis> ZREVRANGE myzset 0 -1
1) "three"
2) "two"
3) "one"
redis> ZREVRANGE myzset 2 3
1) "one"
redis> ZREVRANGE myzset -2 -1
1) "two"
2) "one"
按索引返回排序集中的成員范圍,分?jǐn)?shù)從高到低排序
ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]
redis> ZADD myzset 1 "one"
(integer) 1
redis> ZADD myzset 2 "two"
(integer) 1
redis> ZADD myzset 3 "three"
(integer) 1
redis> ZREVRANGEBYSCORE myzset +inf -inf
1) "three"
2) "two"
3) "one"
redis> ZREVRANGEBYSCORE myzset 2 1
1) "two"
2) "one"
redis> ZREVRANGEBYSCORE myzset 2 (1
1) "two"
redis> ZREVRANGEBYSCORE myzset (2 (1
(empty list or set)
按分?jǐn)?shù)返回排序集中的一系列成員,分?jǐn)?shù)從高到低排序
ZREVRANK key member
redis> ZADD myzset 1 "one"
(integer) 1
redis> ZADD myzset 2 "two"
(integer) 1
redis> ZADD myzset 3 "three"
(integer) 1
redis> ZREVRANK myzset "one"
(integer) 2
redis> ZREVRANK myzset "four"
(nil)
確定有序集合中某個成員的索引,分?jǐn)?shù)從高到低排序
ZUNION numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX] [WITHSCORES]
redis> ZADD zset1 1 "one"
(integer) 1
redis> ZADD zset1 2 "two"
(integer) 1
redis> ZADD zset2 1 "one"
(integer) 1
redis> ZADD zset2 2 "two"
(integer) 1
redis> ZADD zset2 3 "three"
(integer) 1
redis> ZUNION 2 zset1 zset2
1) "one"
2) "three"
3) "two"
redis> ZUNION 2 zset1 zset2 WITHSCORES
1) "one"
2) "2"
3) "three"
4) "3"
5) "two"
6) "4"
添加多個排序集
ZMSCORE key member [member ...]
redis> ZADD myzset 1 "one"
(integer) 1
redis> ZADD myzset 2 "two"
(integer) 1
redis> ZMSCORE myzset "one" "two" "nofield"
1) "1"
2) "2"
3) (nil)
獲取與排序集中的給定成員相關(guān)聯(lián)的分?jǐn)?shù)
ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]
redis> ZADD zset1 1 "one"
(integer) 1
redis> ZADD zset1 2 "two"
(integer) 1
redis> ZADD zset2 1 "one"
(integer) 1
redis> ZADD zset2 2 "two"
(integer) 1
redis> ZADD zset2 3 "three"
(integer) 1
redis> ZUNIONSTORE out 2 zset1 zset2 WEIGHTS 2 3
(integer) 3
redis> ZRANGE out 0 -1 WITHSCORES
1) "one"
2) "5"
3) "three"
4) "9"
5) "two"
6) "10"
添加多個排序集并將結(jié)果排序集存儲在新鍵中
GEOADD key longitude latitude member [longitude latitude member ...]
redis> GEOADD Sicily 13.361389 38.115556 "Palermo" 15.087269 37.502669 "Catania"
(integer) 2
redis> GEODIST Sicily Palermo Catania
"166274.1516"
redis> GEORADIUS Sicily 15 37 100 km
1) "Catania"
redis> GEORADIUS Sicily 15 37 200 km
1) "Palermo"
2) "Catania"
在使用排序集表示的地理空間索引中添加一個或多個地理空間項
GEOHASH key member [member ...]
redis> GEOADD Sicily 13.361389 38.115556 "Palermo" 15.087269 37.502669 "Catania"
(integer) 2
redis> GEOHASH Sicily Palermo Catania
1) "sqc8b49rny0"
2) "sqdtr74hyu0"
將地理空間索引的成員作為標(biāo)準(zhǔn) geohash 字符串返回
GEOPOS key member [member ...]
redis> GEOADD Sicily 13.361389 38.115556 "Palermo" 15.087269 37.502669 "Catania"
(integer) 2
redis> GEOPOS Sicily Palermo Catania NonExisting
1) 1) "13.36138933897018433"
2) "38.11555639549629859"
2) 1) "15.08726745843887329"
2) "37.50266842333162032"
3) (nil)
返回地理空間索引成員的經(jīng)度和緯度
GEODIST key member1 member2 [m|km|ft|mi]
redis> GEOADD Sicily 13.361389 38.115556 "Palermo" 15.087269 37.502669 "Catania"
(integer) 2
redis> GEODIST Sicily Palermo Catania
"166274.1516"
redis> GEODIST Sicily Palermo Catania km
"166.2742"
redis> GEODIST Sicily Palermo Catania mi
"103.3182"
redis> GEODIST Sicily Foo Bar
(nil)
返回地理空間索引的兩個成員之間的距離
GEORADIUS key longitude latitude radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count] [ASC|DESC] [STORE key] [STOREDIST key]
redis> GEOADD Sicily 13.361389 38.115556 "Palermo" 15.087269 37.502669 "Catania"
(integer) 2
redis> GEORADIUS Sicily 15 37 200 km WITHDIST
1) 1) "Palermo"
2) "190.4424"
2) 1) "Catania"
2) "56.4413"
redis> GEORADIUS Sicily 15 37 200 km WITHCOORD
1) 1) "Palermo"
2) 1) "13.36138933897018433"
2) "38.11555639549629859"
2) 1) "Catania"
2) 1) "15.08726745843887329"
2) "37.50266842333162032"
redis> GEORADIUS Sicily 15 37 200 km WITHDIST WITHCOORD
1) 1) "Palermo"
2) "190.4424"
3) 1) "13.36138933897018433"
2) "38.11555639549629859"
2) 1) "Catania"
2) "56.4413"
3) 1) "15.08726745843887329"
2) "37.50266842333162032"
查詢表示地理空間索引的排序集,以獲取與某個點的給定最大距離匹配的成員
GEORADIUSBYMEMBER key member radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count] [ASC|DESC] [STORE key] [STOREDIST key]
redis> GEOADD Sicily 13.583333 37.316667 "Agrigento"
(integer) 1
redis> GEOADD Sicily 13.361389 38.115556 "Palermo" 15.087269 37.502669 "Catania"
(integer) 2
redis> GEORADIUSBYMEMBER Sicily Agrigento 100 km
1) "Agrigento"
2) "Palermo"
查詢表示地理空間索引的排序集以獲取與成員的給定最大距離匹配的成員
GEOSEARCH key [FROMMEMBER member] [FROMLONLAT longitude latitude] [BYRADIUS radius m|km|ft|mi] [BYBOX width height m|km|ft|mi] [ASC|DESC] [COUNT count] [WITHCOORD] [WITHDIST] [WITHHASH]
redis> GEOADD Sicily 13.361389 38.115556 "Palermo" 15.087269 37.502669 "Catania"
(integer) 2
redis> GEOADD Sicily 12.758489 38.788135 "edge1" 17.241510 38.788135 "edge2"
(integer) 2
redis> GEOSEARCH Sicily FROMLONLAT 15 37 BYRADIUS 200 km ASC
1) "Catania"
2) "Palermo"
redis> GEOSEARCH Sicily FROMLONLAT 15 37 BYBOX 400 400 km ASC
1) "Catania"
2) "Palermo"
3) "edge2"
4) "edge1"
查詢表示地理空間索引的排序集以獲取框或圓區(qū)域內(nèi)的成員。
GEOSEARCHSTORE | 查詢表示地理空間索引的排序集以獲取框或圓區(qū)域內(nèi)的成員,并將結(jié)果存儲在另一個鍵中。 |
PFADD key element [element ...]
redis> PFADD hll a b c d e f g
(integer) 1
redis> PFCOUNT hll
(integer) 7
將指定的元素添加到指定的 HyperLogLog。
PFCOUNT key [key ...]
redis> PFADD hll foo bar zap
(integer) 1
redis> PFADD hll zap zap zap
(integer) 0
redis> PFADD hll foo bar
(integer) 0
redis> PFCOUNT hll
(integer) 3
redis> PFADD some-other-hll 1 2 3
(integer) 1
redis> PFCOUNT hll some-other-hll
(integer) 6
返回 HyperLogLog 在 key(s) 處觀察到的集合的近似基數(shù)。
PFMERGE destkey sourcekey [sourcekey ...]
redis> PFADD hll1 foo bar zap a
(integer) 1
redis> PFADD hll2 a b c foo
(integer) 1
redis> PFMERGE hll3 hll1 hll2
"OK"
redis> PFCOUNT hll3
(integer) 6
將 N 個不同的 HyperLogLog 合并為一個。
COMMAND
redis> COMMAND
1) 1) "georadius_ro"
2) (integer) -6
3) 1) "readonly"
2) "movablekeys"
4) (integer) 1
5) (integer) 1
6) (integer) 1
7) 1) "@read"
2) "@geo"
3) "@slow"
2) 1) "zpopmin"
2) (integer) -2
3) 1) "write"
2) "fast"
........
獲取 Redis 命令詳細(xì)信息數(shù)組
ACL LOAD | 從配置的 ACL 文件重新加載 ACL |
ACL SAVE | 將當(dāng)前 ACL 規(guī)則保存在配置的 ACL 文件中 |
ACI LIST | 以 ACL 配置文件格式列出當(dāng)前的 ACL 規(guī)則 |
ACL USERS | 列出所有配置的ACL規(guī)則的用戶名 |
ACL GETUSER | 獲取特定 ACL 用戶的規(guī)則 |
ACL SETUSER | 修改或創(chuàng)建特定 ACL 用戶的規(guī)則 |
ACL DELUSER | 刪除指定的 ACL 用戶和關(guān)聯(lián)規(guī)則 |
ACL CAT | 列出 ACL 類別或類別內(nèi)的命令 |
ACL GENPASS | 生成偽隨機安全密碼以供 ACL 用戶使用 |
ACL WHOAMI | 返回與當(dāng)前連接關(guān)聯(lián)的用戶名 |
ACL LOG | 列出由于 ACL 到位而被拒絕的最新事件 |
ACL HELP | 顯示有關(guān)不同子命令的有用文本 |
BGREWRITEAOF | 異步重寫 append-only 文件 |
BGSAVE | 將數(shù)據(jù)集異步保存到磁盤 |
CONFIG GET | 獲取配置參數(shù)的值 |
CONFIG REWRITE | 使用內(nèi)存配置重寫配置文件 |
CONFIG SET | 將配置參數(shù)設(shè)置為給定值 |
CONFIG RESETSTAT | 重置 INFO 返回的統(tǒng)計信息 |
DBSIZE | 返回所選數(shù)據(jù)庫中的鍵數(shù) |
DEBUG OBJECT | 獲取有關(guān)密鑰的調(diào)試信息 |
DEBUG SEGFAULT | 使服務(wù)器崩潰 |
FLUSHALL | 從所有數(shù)據(jù)庫中刪除所有鍵 |
FLUSHDB | 從當(dāng)前數(shù)據(jù)庫中刪除所有密鑰 |
LOLWUT | 展示一些計算機藝術(shù)和Redis版本 |
LASTSAVE | 獲取上次成功保存到磁盤的 UNIX 時間戳 |
MEMORY DOCTOR | 輸出內(nèi)存問題報告 |
MEMORY HELP | 顯示有關(guān)不同子命令的有用文本 |
MEMORY MALLOC-STATS | 顯示分配器內(nèi)部統(tǒng)計信息 |
MEMORY PURGE | 要求分配器釋放內(nèi)存 |
MEMORY STATS | 顯示內(nèi)存使用詳情 |
MEMORY USAGE | 估計一個鍵的內(nèi)存使用情況 |
MODULE LIST | 列出服務(wù)器加載的所有模塊 |
MODULE LOAD | 加載模塊 |
MODULE UNLOAD | 卸載模塊 |
MONITOR | 實時監(jiān)聽服務(wù)器收到的所有請求 |
SAVE | 將數(shù)據(jù)集同步保存到磁盤 |
SHUTDOWN | 將數(shù)據(jù)集同步保存到磁盤然后關(guān)閉服務(wù)器 |
SLAVEOF | 使服務(wù)器成為另一個實例的副本,或?qū)⑵涮嵘秊橹鞣?wù)器。從 Redis 5 開始已棄用。請改用 REPLICAOF。 |
REPLICAOF | 使服務(wù)器成為另一個實例的副本,或?qū)⑵涮嵘秊橹鞣?wù)器。 |
SLOWLOG | 管理Redis慢查詢?nèi)罩?/font> |
SWAPDB | 交換兩個Redis數(shù)據(jù)庫 |
SYNC | 用于復(fù)制的內(nèi)部命令 |
PSYNC | 用于復(fù)制的內(nèi)部命令 |
LATENCY DOCTOR | 返回人類可讀的延遲分析報告。 |
LATENCY GRAPH | 返回事件的延遲圖。 |
LATENCY HISTORY | 返回事件的時間戳延遲樣本。 |
LATENCY LATEST | 返回所有事件的最新延遲樣本。 |
LATENCY RESET | 重置一個或多個事件的延遲數(shù)據(jù)。 |
LATENCY HELP | 顯示有關(guān)不同子命令的有用文本。 |
COMMAND COUNT
redis> COMMAND COUNT
(integer) 217
獲取Redis命令總數(shù)
COMMAND GETKEYS
redis> COMMAND GETKEYS MSET a b c d e f
1) "a"
2) "c"
3) "e"
redis> COMMAND GETKEYS EVAL "not consulted" 3 key1 key2 key3 arg1 arg2 arg3 argN
1) "key1"
2) "key2"
3) "key3"
redis> COMMAND GETKEYS SORT mylist ALPHA STORE outlist
1) "mylist"
2) "outlist"
在給定完整的 Redis 命令的情況下提取鍵
COMMAND INFO command-name [command-name ...]
redis> COMMAND INFO get set eval
1) 1) "get"
2) (integer) 2
3) 1) "readonly"
2) "fast"
4) (integer) 1
5) (integer) 1
6) (integer) 1
7) 1) "@read"
2) "@string"
3) "@fast"
2) 1) "set"
2) (integer) -3
3) 1) "write"
2) "denyoom"
4) (integer) 1
5) (integer) 1
6) (integer) 1
7) 1) "@write"
2) "@string"
3) "@slow"
3) 1) "eval"
2) (integer) -3
3) 1) "noscript"
2) "movablekeys"
4) (integer) 0
5) (integer) 0
6) (integer) 0
7) 1) "@slow"
2) "@scripting"
獲取特定 Redis 命令詳細(xì)信息的數(shù)組
INFO [section]
redis> INFO
# Server
redis_version:6.1.240
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:a26db646ea64a07c
redis_mode:standalone
os:Linux 5.4.0-1017-aws x86_64
......
獲取有關(guān)服務(wù)器的信息和統(tǒng)計信息
ROLE
redis> ROLE
1) "master"
2) (integer) 0
3) (empty list or set)
返回實例在復(fù)制上下文中的角色
TIME
redis> TIME
1) "1609040690"
2) "558952"
redis> TIME
1) "1609040690"
2) "559206"
返回當(dāng)前服務(wù)器時間
DEL key [key ...]
redis> SET key1 "Hello"
"OK"
redis> SET key2 "World"
"OK"
redis> DEL key1 key2 key3
(integer) 2
刪除一個鍵
DUMP key
redis> SET mykey 10
"OK"
redis> DUMP mykey
"\u0000\xC0\n\t\u0000\xBEm\u0006\x89Z(\u0000\n"
返回存儲在指定鍵中的值的序列化版本。
EXISTS key [key ...]
redis> SET key1 "Hello"
"OK"
redis> EXISTS key1
(integer) 1
redis> EXISTS nosuchkey
(integer) 0
redis> SET key2 "World"
"OK"
redis> EXISTS key1 key2 nosuchkey
(integer) 2
判斷key是否存在
EXPIRE key seconds
redis> SET mykey "Hello"
"OK"
redis> EXPIRE mykey 10
(integer) 1
redis> TTL mykey
(integer) 10
redis> SET mykey "Hello World"
"OK"
redis> TTL mykey
(integer) -1
以秒為單位設(shè)置鍵的存活時間
EXPIREAT key timestamp
redis> SET mykey "Hello"
"OK"
redis> EXISTS mykey
(integer) 1
redis> EXPIREAT mykey 1293840000
(integer) 1
redis> EXISTS mykey
(integer) 0
將密鑰的到期時間設(shè)置為 UNIX 時間戳
KEYS pattern
redis> MSET firstname Jack lastname Stuntman age 35
"OK"
redis> KEYS *name*
1) "firstname"
2) "lastname"
redis> KEYS a??
1) "age"
redis> KEYS *
1) "firstname"
2) "age"
3) "lastname"
查找與給定模式匹配的所有鍵
PERSIST key
redis> SET mykey "Hello"
"OK"
redis> EXPIRE mykey 10
(integer) 1
redis> TTL mykey
(integer) 10
redis> PERSIST mykey
(integer) 1
redis> TTL mykey
(integer) -1
從密鑰中刪除過期時間
PEXPIRE key milliseconds
redis> SET mykey "Hello"
"OK"
redis> PEXPIRE mykey 1500
(integer) 1
redis> TTL mykey
(integer) 1
redis> PTTL mykey
(integer) 1499
以毫秒為單位設(shè)置鍵的生存時間
PEXPIREAT key milliseconds-timestamp
redis> SET mykey "Hello"
"OK"
redis> PEXPIREAT mykey 1555555555005
(integer) 1
redis> TTL mykey
(integer) -2
redis> PTTL mykey
(integer) -2
將密鑰的到期時間設(shè)置為以毫秒為單位指定的 UNIX 時間戳
PTTL key
redis> SET mykey "Hello"
"OK"
redis> EXPIRE mykey 1
(integer) 1
redis> PTTL mykey
(integer) 1000
以毫秒為單位獲取密鑰的生存時間
RENAME key newkey
redis> SET mykey "Hello"
"OK"
redis> RENAME mykey myotherkey
"OK"
redis> GET myotherkey
"Hello"
重命名密鑰
RENAMENX key newkey
redis> SET mykey "Hello"
"OK"
redis> SET myotherkey "World"
"OK"
redis> RENAMENX mykey myotherkey
(integer) 0
redis> GET myotherkey
"World"
重命名密鑰,僅當(dāng)新密鑰不存在時
TOUCH key [key ...]
redis> SET key1 "Hello"
"OK"
redis> SET key2 "World"
"OK"
redis> TOUCH key1 key2
(integer) 2
更改密鑰的最后訪問時間。返回指定的現(xiàn)有鍵的數(shù)量。
TTL key
redis> SET mykey "Hello"
"OK"
redis> EXPIRE mykey 10
(integer) 1
redis> TTL mykey
(integer) 10
為一把鑰匙贏得時間
TYPE key
redis> SET key1 "value"
"OK"
redis> LPUSH key2 "value"
(integer) 1
redis> SADD key3 "value"
(integer) 1
redis> TYPE key1
"string"
redis> TYPE key2
"list"
redis> TYPE key3
"set"
確定存儲在 key 的類型
UNLINK key [key ...]
redis> SET key1 "Hello"
"OK"
redis> SET key2 "World"
"OK"
redis> UNLINK key1 key2 key3
(integer) 2
在另一個線程中異步刪除一個鍵。否則它就像 DEL 一樣,但非阻塞。
AUTH | 向服務(wù)器進(jìn)行身份驗證 |
CLIENT CACHING | 指示服務(wù)器在下一個請求中跟蹤或不跟蹤密鑰 |
CLIENT KII | 終止客戶端的連接 |
CLIENT LIST | 獲取客戶端連接列表 |
CLIENT GETNAME | 獲取當(dāng)前連接名稱 |
CLIENT GETREDIR | 獲取跟蹤通知重定向客戶端 ID(如果有) |
CLIENT PAUSE | 停止處理來自客戶端的命令一段時間 |
CLIENT REPLY | 指示服務(wù)器是否回復(fù)命令 |
CLIENT SETNAME | 設(shè)置當(dāng)前連接名稱 |
CLIENT TRACKING | 啟用或禁用服務(wù)器輔助客戶端緩存支持 |
CLIENT UNBLOCK | 從不同的連接取消阻止在阻止命令中阻止的客戶端 |
HELLO | 切換Redis協(xié)議 |
QUIT | 關(guān)閉連接 |
RESET | 重置連接 |
SELECT | 更改當(dāng)前連接的選定數(shù)據(jù)庫 |
CLIENT ID
redis> CLIENT ID
ERR Unknown or disabled command 'CLIENT'
返回當(dāng)前連接的客戶端 ID
CLIENT INFO
redis> CLIENT INFO
"id=55542 addr=127.0.0.1:58710 laddr=127.0.0.1:6379 fd=8 name= age=114920 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=40928 argv-mem=10 obl=0 oll=0 omem=0 tot-mem=61466 events=r cmd=client user=default redir=-1\n"
返回有關(guān)當(dāng)前客戶端連接的信息。
ECHO message
redis> ECHO "Hello World!"
"Hello World!"
回顯給定的字符串
PING [message]
redis> PING
"PONG"
redis> PING "hello world"
"hello world"
ping 服務(wù)器
XINFO | 獲取有關(guān)流和消費者組的信息 |
XDEL | 從流中刪除指定的條目。返回實際刪除的項目數(shù),如果某些 ID 不存在,則可能與傳遞的 ID 數(shù)不同。 |
XREAD | 返回多個流中從未見過的元素,其 ID 大于調(diào)用者為每個流報告的 ID。可以擋。 |
XGROUP | 創(chuàng)建、銷毀和管理消費者群體。 |
XREADGROUP | 使用消費者組從流中返回新條目,或訪問給定消費者的待處理條目的歷史記錄。可以擋。 |
XCLAIM | 更改(或獲?。┫M者組中消息的所有權(quán),就像將消息傳遞給指定的消費者一樣。 |
XPENDING | 從流消費者組掛起條目列表中返回信息和條目,即獲取但從未確認(rèn)的消息。 |
XADD key [MAXLEN [=|~] length] [NOMKSTREAM] *|ID field value [field value ...]
redis> XADD mystream * name Sara surname OConnor
"1609040574632-0"
redis> XADD mystream * field1 value1 field2 value2 field3 value3
"1609040574632-1"
redis> XLEN mystream
(integer) 2
redis> XRANGE mystream - +
1) 1) "1609040574632-0"
2) 1) "name"
2) "Sara"
3) "surname"
4) "OConnor"
2) 1) "1609040574632-1"
2) 1) "field1"
2) "value1"
3) "field2"
4) "value2"
5) "field3"
6) "value3"
將新條目附加到流
XTRIM key MAXLEN [=|~] length
redis> XADD mystream * field1 A field2 B field3 C field4 D
"1609040575750-0"
redis> XTRIM mystream MAXLEN 2
(integer) 0
redis> XRANGE mystream - +
1) 1) "1609040575750-0"
2) 1) "field1"
2) "A"
3) "field2"
4) "B"
5) "field3"
6) "C"
7) "field4"
8) "D"
將流修剪為(大約如果 '~' 被傳遞)特定大小
XRANGE key start end [COUNT count]
redis> XADD writers * name Virginia surname Woolf
"1609040578002-0"
redis> XADD writers * name Jane surname Austen
"1609040578002-1"
redis> XADD writers * name Toni surname Morrison
"1609040578003-0"
redis> XADD writers * name Agatha surname Christie
"1609040578003-1"
redis> XADD writers * name Ngozi surname Adichie
"1609040578003-2"
redis> XLEN writers
(integer) 5
redis> XRANGE writers - + COUNT 2
1) 1) "1609040578002-0"
2) 1) "name"
2) "Virginia"
3) "surname"
4) "Woolf"
2) 1) "1609040578002-1"
2) 1) "name"
2) "Jane"
3) "surname"
4) "Austen"
返回流中的一系列元素,其 ID 與指定的 ID 間隔匹配
XREVRANGE key end start [COUNT count]
redis> XADD writers * name Virginia surname Woolf
"1609040579130-0"
redis> XADD writers * name Jane surname Austen
"1609040579130-1"
redis> XADD writers * name Toni surname Morrison
"1609040579130-2"
redis> XADD writers * name Agatha surname Christie
"1609040579131-0"
redis> XADD writers * name Ngozi surname Adichie
"1609040579131-1"
redis> XLEN writers
(integer) 5
redis> XREVRANGE writers + - COUNT 1
1) 1) "1609040579131-1"
2) 1) "name"
2) "Ngozi"
3) "surname"
4) "Adichie"
與 XRANGE 相比,以相反的順序(從較大到較小的 ID)返回流中的元素范圍,其中 ID 與指定的 ID 間隔匹配
XLEN key
redis> XADD mystream * item 1
"1609040580250-0"
redis> XADD mystream * item 2
"1609040580250-1"
redis> XADD mystream * item 3
"1609040580251-0"
redis> XLEN mystream
(integer) 3
返回流中的條目數(shù)
XACK key group ID [ID ...]
redis> XACK mystream mygroup 1526569495631-0
ERR Unknown or disabled command 'XACK'
將待處理消息標(biāo)記為正確處理,有效地將其從消費者組的待處理條目列表中刪除。該命令的返回值是成功確認(rèn)的消息數(shù),即我們在 PEL 中實際能夠解析的 ID。
CLUSTER ADDSLOTS | 為接收節(jié)點分配新的哈希槽 |
CLUSTER BUMPEPOCH | 推進(jìn)集群配置時代 |
CLUSTER COUNT-FALILURE-REPORTS | 返回給定節(jié)點活動的故障報告數(shù)量 |
CLUSTER COUNTKEYSINS | 返回指定哈希槽中本地鍵的數(shù)量 |
CLUSTER DLSLOTS | 在接收節(jié)點中將哈希槽設(shè)置為未綁定 |
CLUSTER FAILOVER | 強制副本對其主服務(wù)器執(zhí)行手動故障轉(zhuǎn)移。 |
CLUSTER FLUSHSLOTS | 刪除一個節(jié)點自己的slots信息 |
CLUSTER FORGET | 從節(jié)點表中刪除節(jié)點 |
CLUSTER GETKEYSINSLOT | 返回指定哈希槽中的本地鍵名 |
CLUSTER INFO | 提供有關(guān) Redis 集群節(jié)點狀態(tài)的信息 |
CLUSTER KEYSLOT | 返回指定鍵的哈希槽 |
CLUSTER MEET | 強制一個節(jié)點集群與另一個節(jié)點握手 |
CLUSTER MYID | 返回節(jié)點 ID |
CLUSTER NODES | 獲取節(jié)點的集群配置 |
CLUSTER REPLICATE | 將節(jié)點重新配置為指定主節(jié)點的副本 |
CLUSTER RESET | 重置 Redis 集群節(jié)點 |
CLUSTER SAVECONFIG | 強制節(jié)點在磁盤上保存集群狀態(tài) |
CLUSTER SET-CONFIG-EPOCH | 在新節(jié)點中設(shè)置配置紀(jì)元 |
CLUSTER SETSLOT | 將哈希槽綁定到特定節(jié)點 |
CLUSTER SLAVES | 列出指定主節(jié)點的副本節(jié)點 |
CLUSTER REPLICAS | 列出指定主節(jié)點的副本節(jié)點 |
CLUSTER SLOTS | 獲取集群槽到節(jié)點映射的數(shù)組 |
READONLY | 啟用對集群副本節(jié)點連接的讀取查詢 |
READWRITE | 禁用對集群副本節(jié)點連接的讀取查詢 |
EVAL | 執(zhí)行一個 Lua 腳本服務(wù)器端 |
EVALSHA | 執(zhí)行一個 Lua 腳本服務(wù)器端 |
SCRIPT DEBUG | 為執(zhí)行的腳本設(shè)置調(diào)試模式。 |
SCRIPT EXISTS | 檢查腳本緩存中是否存在腳本。 |
SCRIPT FLUSH | 從腳本緩存中刪除所有腳本。 |
SCRIPT KILL | 殺死當(dāng)前正在執(zhí)行的腳本。 |
SCRIPT LOAD | 將指定的 Lua 腳本加載到腳本緩存中。 |
PSUBSCRIBE | 偵聽發(fā)布到與給定模式匹配的頻道的消息 |
PUBSUB | 檢查 Pub/Sub 子系統(tǒng)的狀態(tài) |
PUBLISH | 向頻道發(fā)布消息 |
PUNSUBSCRIBE | 停止偵聽發(fā)布到與給定模式匹配的頻道的消息 |
SUBSCRIBE | 偵聽發(fā)布到給定頻道的消息 |
UNSUBSCRIBE | 停止偵聽發(fā)布到給定頻道的消息 |
更多建議: