redis安裝與啟動
[root@C7mini ~]#yum install redis
[root@C7mini ~]#rpm -ql redis
/etc/logrotate.d/redis
/etc/redis-sentinel.conf
/etc/redis.conf
/etc/systemd/system/redis-sentinel.service.d
/etc/systemd/system/redis-sentinel.service.d/limit.conf
/etc/systemd/system/redis.service.d
/etc/systemd/system/redis.service.d/limit.conf
/usr/bin/redis-benchmark
/usr/bin/redis-check-aof
/usr/bin/redis-check-rdb
/usr/bin/redis-cli
/usr/bin/redis-sentinel
/usr/bin/redis-server
/usr/bin/redis-shutdown
/usr/lib/systemd/system/redis-sentinel.service
/usr/lib/systemd/system/redis.service
/usr/lib/tmpfiles.d/redis.conf
/usr/share/doc/redis-3.2.3
/usr/share/doc/redis-3.2.3/00-RELEASENOTES
/usr/share/doc/redis-3.2.3/BUGS
/usr/share/doc/redis-3.2.3/CONTRIBUTING
/usr/share/doc/redis-3.2.3/MANIFESTO
/usr/share/doc/redis-3.2.3/README.md
/usr/share/licenses/redis-3.2.3
/usr/share/licenses/redis-3.2.3/COPYING
/var/lib/redis
/var/log/redis
/var/run/redis
[root@C7mini ~]#systemctl start redis
[root@C7mini ~]#ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.1:6379 *:*
[root@C7mini ~]#ps aux
redis 1694 0.1 0.5 142908 5784 ? Ssl 13:12 0:05 /usr/bin/redis-server 127.0
客戶端工具Redis-cli
[root@C7mini ~]#redis-cli -h
redis-cli 3.2.3
Usage: redis-cli [OPTIONS] [cmd [arg [arg ...]]]
-h <hostname> Server hostname (default: 127.0.0.1). ----------------------------- 指明連接主機甘磨,默認(rèn)是本機
-p <port> Server port (default: 6379). -------------------------------------- 默認(rèn)端口 6379
-s <socket> Server socket (overrides hostname and port). ---------------------- socket本地連接
-a <password> Password to use when connecting to the server. -------------------- 認(rèn)證廓鞠,沒有多級授權(quán),沒有用戶
-r <repeat> Execute specified command N times.
-i <interval> When -r is used, waits <interval> seconds per command.
It is possible to specify sub-second times like -i 0.1.
-n <db> Database number.
-x Read last argument from STDIN.
-d <delimiter> Multi-bulk delimiter in for raw formatting (default: \n).
-c Enable cluster mode (follow -ASK and -MOVED redirections).
--raw Use raw formatting for replies (default when STDOUT is
not a tty).
--no-raw Force formatted output even when STDOUT is not a tty.
--csv Output in CSV format.
--stat Print rolling stats about server: mem, clients, ...
--latency Enter a special mode continuously sampling latency.
--latency-history Like --latency but tracking latency changes over time.
Default time interval is 15 sec. Change it using -i.
--latency-dist Shows latency as a spectrum, requires xterm 256 colors.
Default time interval is 1 sec. Change it using -i.
--lru-test <keys> Simulate a cache workload with an 80-20 distribution.
--slave Simulate a slave showing commands received from the master.
--rdb <filename> Transfer an RDB dump from remote server to local file.
--pipe Transfer raw Redis protocol from stdin to server.
--pipe-timeout <n> In --pipe mode, abort with error if after sending all data.
no reply is received within <n> seconds.
Default timeout: 30. Use 0 to wait forever.
--bigkeys Sample Redis keys looking for big keys.
--scan List all keys using the SCAN command.
--pattern <pat> Useful with --scan to specify a SCAN pattern.
--intrinsic-latency <sec> Run a test to measure intrinsic system latency.
The test will run for the specified amount of seconds.
--eval <file> Send an EVAL command using the Lua script at <file>.
--ldb Used with --eval enable the Redis Lua debugger.
--ldb-sync-mode Like --ldb but uses the synchronous Lua debugger, in
this mode the server is blocked and script changes are
are not rolled back from the server memory.
--help Output this help and exit.
--version Output version and exit.
Examples:
cat /etc/passwd | redis-cli -x set mypasswd
redis-cli get mypasswd
redis-cli -r 100 lpush mylist x
redis-cli -r 100 -i 1 info | grep used_memory_human:
redis-cli --eval myscript.lua key1 key2 , arg1 arg2 arg3
redis-cli --scan --pattern '*:12345*'
(Note: when using --eval the comma separates KEYS[] from ARGV[] items)
When no command is given, redis-cli starts in interactive mode.
Type "help" in interactive mode for information on available commands
and settings.
連接redis
[root@C7mini ~]#redis-cli
127.0.0.1:6379>
redis的數(shù)據(jù)表使用數(shù)字為表號浇借,默認(rèn)表為16個事秀,默認(rèn)表號0到15彤断,可以使用SELECT查詢野舶,每個庫自身是個索引,表號也是索引號
[root@C7mini ~]#redis-cli
127.0.0.1:6379> SELECT 0
OK
127.0.0.1:6379> SELECT 1
OK
127.0.0.1:6379[1]> SELECT 15
OK
127.0.0.1:6379[15]> SELECT 16
(error) ERR invalid DB index
127.0.0.1:6379[15]>
redis所有的數(shù)據(jù)都是鍵值對
redis的幫助查詢使用help加Tab鍵瓦糟,Tab鍵切換不同的命令組筒愚。
generic:通用命令,對所有的類都支持
string:對字符串操作
list:列表
set:集合
sorted_set:有序集合
hash:字段
pubsub:發(fā)布訂閱隊列
transactions:事務(wù)
connection:連接
server:服務(wù)器
scripting:腳本
hyperloglog:
cluster:集群
geo:
APPEND:索引
string字符集
127.0.0.1:6379[15]> help @string
APPEND key value --------------------------------------------------------------------------- 在原有值進(jìn)行追加
summary: Append a value to a key
since: 2.0.0
BITCOUNT key [start end]
summary: Count set bits in a string
since: 2.6.0
BITFIELD key [GET type offset] [SET type offset value] [INCRBY type offset increment] [OVERFLOW WRAP|SAT|FAIL]
summary: Perform arbitrary bitfield integer operations on strings
since: 3.2.0
BITOP operation destkey key [key ...]
summary: Perform bitwise operations between strings
since: 2.6.0
BITPOS key bit [start] [end]
summary: Find first bit set or clear in a string
since: 2.8.7
DECR key --------------------------------------------------------------------------------- 減少
summary: Decrement the integer value of a key by one
since: 1.0.0
DECRBY key decrement --------------------------------------------------------------------- 減少多個
summary: Decrement the integer value of a key by the given number
since: 1.0.0
GET key ---------------------------------------------------------------------------------- 獲取一個鍵值對
summary: Get the value of a key
since: 1.0.0
GETBIT key offset
summary: Returns the bit value at offset in the string value stored at key
since: 2.2.0
GETRANGE key start end
summary: Get a substring of the string stored at a key
since: 2.4.0
GETSET key value
summary: Set the string value of a key and return its old value
since: 1.0.0
INCR key -------------------------------------------------------------------------------- 增加
summary: Increment the integer value of a key by one
since: 1.0.0
INCRBY key increment -------------------------------------------------------------------- 增加多個
summary: Increment the integer value of a key by the given amount
since: 1.0.0
INCRBYFLOAT key increment
summary: Increment the float value of a key by the given amount
since: 2.6.0
MGET key [key ...] ----------------------------------------------------------------- 獲取多個鍵值對
summary: Get the values of all the given keys
since: 1.0.0
MSET key value [key value ...] ----------------------------------------------------- 一次創(chuàng)建多個鍵值對
summary: Set multiple keys to multiple values
since: 1.0.1
MSETNX key value [key value ...]
summary: Set multiple keys to multiple values, only if none of the keys exist
since: 1.0.1
PSETEX key milliseconds value
summary: Set the value and expiration in milliseconds of a key
since: 2.6.0
SET key value [EX seconds] [PX milliseconds] [NX|XX] ------------------------------ 創(chuàng)建一個鍵值對
summary: Set the string value of a key
since: 1.0.0
SETBIT key offset value
summary: Sets or clears the bit at offset in the string value stored at key
since: 2.2.0
SETEX key seconds value ----------------------------------------------------------- 定義過期時間
summary: Set the value and expiration of a key
since: 2.0.0
SETNX key value ------------------------------------------------------------------- 新建
summary: Set the value of a key, only if the key does not exist
since: 1.0.0
SETRANGE key offset value --------------------------------------------------------- 修改一組的key值
summary: Overwrite part of a string at key starting at the specified offset
since: 2.2.0
STRLEN key ----------------------------------------------------------------------- 判定一個鍵的字符串的長度
summary: Get the length of the value stored in a key
since: 2.2.0
示例
127.0.0.1:6379[15]> SET mykey 'hello redis' 創(chuàng)建一個鍵值對mykey菩浙,內(nèi)容為hello redis
OK
127.0.0.1:6379[15]> GET mykey 獲取mykey查看
"hello redis"
127.0.0.1:6379[15]> APPEND mykey ',www.redis.io' 在mykey附加www.redis.io
(integer) 24
127.0.0.1:6379[15]> GET mykey 查看mykey
"hello redis,www.redis.io"
127.0.0.1:6379[15]> STRLEN mykey 查看mykey的字符長度
(integer) 24
127.0.0.1:6379[15]> SETNX mykey 'hi redis' 新建一個mykey
(integer) 0
127.0.0.1:6379[15]> GET mykey 新建不成功巢掺,未能覆蓋mykey
"hello redis,www.redis.io"
127.0.0.1:6379[15]> SET count 0 創(chuàng)建一個鍵值對count,定義內(nèi)容為0
OK
127.0.0.1:6379[15]> INCR count 對count自增加劲蜻,加1
(integer) 1
127.0.0.1:6379[15]> INCR count
(integer) 2
127.0.0.1:6379[15]> INCR count
(integer) 3
127.0.0.1:6379[15]> INCRBY count 2 設(shè)定增加大小為2
(integer) 5
127.0.0.1:6379[15]> INCRBY count 2
(integer) 7
127.0.0.1:6379[15]> DECR count 對count自減少陆淀,減1
(integer) 6
127.0.0.1:6379[15]> DECR count
(integer) 5
127.0.0.1:6379[15]> DECRBY count 3 設(shè)定減少大小為3
(integer) 2
127.0.0.1:6379[15]> DEL mykey 刪除mykey
(integer) 1
127.0.0.1:6379[15]> GET mykey 查看刪除情況
(nil)
list列表,列表即數(shù)組先嬉,L開頭left轧苫,R開頭right,L表示從左側(cè)入站疫蔓,R表示從右側(cè)入站
127.0.0.1:6379[15]> help @list
BLPOP key [key ...] timeout -------------------------------------------------- 移除拿到列表的第一個數(shù)據(jù)含懊,沒有元素就阻塞,等待元素插入衅胀。當(dāng)隊列使用才有用
summary: Remove and get the first element in a list, or block until one is available
since: 2.0.0
BRPOP key [key ...] timeout
summary: Remove and get the last element in a list, or block until one is available
since: 2.0.0
BRPOPLPUSH source destination timeout --------------------------------------- 從一個列表的最右側(cè)去一個數(shù)據(jù)放在另一個列表的最左側(cè)岔乔,隊列有用
summary: Pop a value from a list, push it to another list and return it; or block until one is available
since: 2.2.0
LINDEX key index ----------------------------------------------------------- 按索引取數(shù)據(jù)
summary: Get an element from a list by its index
since: 1.0.0
LINSERT key BEFORE|AFTER pivot value---------------------------------------- 指定位置插入
summary: Insert an element before or after another element in a list
since: 2.2.0
LLEN key ------------------------------------------------------------------- 取出整個列表的長度(元素個數(shù))
summary: Get the length of a list
since: 1.0.0
LPOP key ------------------------------------------------------------------- 從左側(cè)出站,彈站
summary: Remove and get the first element in a list
since: 1.0.0
LPUSH key value [value ...] ------------------------------------------------ 從左側(cè)入站滚躯,壓站雏门,自動創(chuàng)建列表
summary: Prepend one or multiple values to a list
since: 1.0.0
LPUSHX key value ----------------------------------------------------------- 只有列表存在時入站
summary: Prepend a value to a list, only if the list exists
since: 2.2.0
LRANGE key start stop ----------------------------------------------------- 獲取指定范圍內(nèi)的所有元素
summary: Get a range of elements from a list
since: 1.0.0
LREM key count value ------------------------------------------------------- 刪除一個元素
summary: Remove elements from a list
since: 1.0.0
LSET key index value ------------------------------------------------------- 設(shè)定指定索引的元素的值
summary: Set the value of an element in a list by its index
since: 1.0.0
LTRIM key start stop ------------------------------------------------------- 修改指定范圍的所有元素
summary: Trim a list to the specified range
since: 1.0.0
RPOP key
summary: Remove and get the last element in a list
since: 1.0.0
RPOPLPUSH source destination
summary: Remove the last element in a list, prepend it to another list and return it
since: 1.2.0
RPUSH key value [value ...]
summary: Append one or multiple values to a list
since: 1.0.0
RPUSHX key value
summary: Append a value to a list, only if the list exists
since: 2.2.0
示例
127.0.0.1:6379[15]> LPUSH weekdays Sat ----------------------- 創(chuàng)建一個列表,定義第一個字符為Sat
(integer) 1
127.0.0.1:6379[15]> LPUSH weekdays Fri ----------------------- 從左邊定義新的字符為Fri
(integer) 2
127.0.0.1:6379[15]> LPUSH weekdays Thu ----------------------- 從左邊定義新的字符為Thu
(integer) 3
127.0.0.1:6379[15]> LINDEX weekdays 0 ------------------------ 查看左邊第一個字符
"Thu"
127.0.0.1:6379[15]> LINDEX weekdays 2 ------------------------ 查看左邊第三個字符
"Sat"
127.0.0.1:6379[15]> LPUSHX weekdays Tue ---------------------- 從左邊定義新的字符Tue掸掏,沒有表的情況下不創(chuàng)建
(integer) 4
127.0.0.1:6379[15]> LINSERT weekdays BEFORE Thu Wed ---------- 在字符Thu之前插入字符Wed
(integer) 5
127.0.0.1:6379[15]> LRANGE weekdays 0 4 ---------------------- 查看表
1) "Tue"
2) "Wed"
3) "Thu"
4) "Fri"
5) "Sat"
127.0.0.1:6379[15]> LPOP weekdays --------------------------- 從左邊開始彈出第一個字符
"Tue"
127.0.0.1:6379[15]> LRANGE weekdays 0 4 --------------------- 查看表
1) "Wed"
2) "Thu"
3) "Fri"
4) "Sat"
127.0.0.1:6379[15]> RPOP weekdays -------------------------- 從右邊開始彈出第一個字符
"Sat"
127.0.0.1:6379[15]> LRANGE weekdays 0 4 -------------------- 查看表
1) "Wed"
2) "Thu"
3) "Fri"
127.0.0.1:6379[15]> LLEN weekdays ------------------------- 查看表的字符長度
(integer) 3
hash字段茁影,很多命令是由H開頭
127.0.0.1:6379[15]> help @hash
HDEL key field [field ...] -------------------------------------------------- 刪除某個鍵中的子鍵
summary: Delete one or more hash fields
since: 2.0.0
HEXISTS key field ----------------------------------------------------------- 判斷某個鍵中子鍵是否存在
summary: Determine if a hash field exists
since: 2.0.0
HGET key field
summary: Get the value of a hash field
since: 2.0.0
HGETALL key ----------------------------------------------------------------- 獲取所有的鍵值對
summary: Get all the fields and values in a hash
since: 2.0.0
HINCRBY key field increment
summary: Increment the integer value of a hash field by the given number
since: 2.0.0
HINCRBYFLOAT key field increment
summary: Increment the float value of a hash field by the given amount
since: 2.6.0
HKEYS key ------------------------------------------------------------------ 獲取一個鍵中的所有子key
summary: Get all the fields in a hash
since: 2.0.0
HLEN key ------------------------------------------------------------------- 查看表中元素的個數(shù)
summary: Get the number of fields in a hash
since: 2.0.0
HMGET key field [field ...]
summary: Get the values of all the given hash fields
since: 2.0.0
HMSET key field value [field value ...] -------------------------------------- 設(shè)定或修改多個鍵值對
summary: Set multiple hash fields to multiple values
since: 2.0.0
HSCAN key cursor [MATCH pattern] [COUNT count]
summary: Incrementally iterate hash fields and associated values
since: 2.8.0
HSET key field value ------------------------------------------------------- 設(shè)定或改鍵值對
summary: Set the string value of a hash field
since: 2.0.0
HSETNX key field value
summary: Set the value of a hash field, only if the field does not exist
since: 2.0.0
HSTRLEN key field
summary: Get the length of the value of a hash field
since: 3.2.0
HVALS key ------------------------------------------------------------------- 獲取所有的值
summary: Get all the values in a hash
since: 2.0.0
127.0.0.1:6379[15]> HMSET member name jerry age 17 gender female -------- 創(chuàng)建鍵值對
OK
127.0.0.1:6379[15]> HKEYS member ---------------------------------------- 查詢所有鍵
1) "name"
2) "age"
3) "gender"
127.0.0.1:6379[15]> HVALS member ---------------------------------------- 查詢所有值
1) "jerry"
2) "17"
3) "female"
127.0.0.1:6379[15]> HSTRLEN member name -------------------------------- 查看member表的name的字符長度
(integer) 5
127.0.0.1:6379[15]> HGETALL member
1) "name"
2) "jerry"
3) "age"
4) "17"
5) "gender"
6) "female"
127.0.0.1:6379[15]> HDEL member gender ------------------------------- 刪除鍵值對gender
(integer) 1
127.0.0.1:6379[15]> HGETALL member ----------------------------------- 查看所有鍵值對
1) "name"
2) "jerry"
3) "age"
4) "17"
set集合
127.0.0.1:6379[15]> help @set
SADD key member [member ...] -------------------------------------- 向一個集合內(nèi)添加一個成員或者多個成員
summary: Add one or more members to a set
since: 1.0.0
SCARD key --------------------------------------------------------- 得到一個集合內(nèi)的所有元素的個數(shù)
summary: Get the number of members in a set
since: 1.0.0
SDIFF key [key ...] ---------------------------------------------------- 計算兩個集合的差集
summary: Subtract multiple sets
since: 1.0.0
SDIFFSTORE destination key [key ...] ---------------------------------- 計算兩個集合的差集并存檔
summary: Subtract multiple sets and store the resulting set in a key
since: 1.0.0
SINTER key [key ...] --------------------------------------------------- 計算兩個集合的交集
summary: Intersect multiple sets
since: 1.0.0
SINTERSTORE destination key [key ...] ---------------------------------- 計算兩個集合的交集并存檔
summary: Intersect multiple sets and store the resulting set in a key
since: 1.0.0
SISMEMBER key member --------------------------------------------------- 判斷是否是集合的成員
summary: Determine if a given value is a member of a set
since: 1.0.0
SMEMBERS key ----------------------------------------------------------- 獲取一個集合的所有元素
summary: Get all the members in a set
since: 1.0.0
SMOVE source destination member
summary: Move a member from one set to another
since: 1.0.0
SPOP key [count] ------------------------------------------------------ 從集合中隨機刪除一個元素
summary: Remove and return one or multiple random members from a set
since: 1.0.0
SRANDMEMBER key [count] ----------------------------------------------- 從集合中隨機刪除一個元素
summary: Get one or multiple random members from a set
since: 1.0.0
SREM key member [member ...] ------------------------------------------ 指明刪除某個元素
summary: Remove one or more members from a set
since: 1.0.0
SSCAN key cursor [MATCH pattern] [COUNT count]
summary: Incrementally iterate Set elements
since: 2.8.0
SUNION key [key ...] -------------------------------------------------- 計算兩個集合的并集
summary: Add multiple sets
since: 1.0.0
SUNIONSTORE destination key [key ...] --------------------------------- 計算兩個集合的并集并存檔
summary: Add multiple sets and store the resulting set in a key
since: 1.0.0
示例
127.0.0.1:6379[15]> SADD animals elephant wolf tiger monkey fox dog cat ---- 創(chuàng)建一個集合animals
(integer) 7
127.0.0.1:6379[15]> SADD jiaqin dog pig chicken duck fish ------------------ 創(chuàng)建一個集合jiaqin
(integer) 5
127.0.0.1:6379[15]> SMEMBERS animals --------------------------------------- 查看集合animals
1) "wolf"
2) "tiger"
3) "monkey"
4) "dog"
5) "elephant"
6) "fox"
7) "cat"
127.0.0.1:6379[15]> SMEMBERS jiaqin --------------------------------------- 查看集合jiaqin
1) "duck"
2) "dog"
3) "chicken"
4) "pig"
5) "fish"
127.0.0.1:6379[15]> SCARD animals ----------------------------------------- 查看集合animals內(nèi)的元素的數(shù)量
(integer) 7
127.0.0.1:6379[15]> SPOP animals ------------------------------------------ 集合animals隨機刪除一個元素
"cat"
127.0.0.1:6379[15]> SREM jiaqin fish -------------------------------------- 集合jiaqin指定刪除fish
(integer) 1
127.0.0.1:6379[15]> SMEMBERS jiaqin --------------------------------------- 查看集合jiaqin
1) "chicken"
2) "pig"
3) "duck"
4) "dog"
127.0.0.1:6379[15]> SINTER animals jiaqin --------------------------------- 查看animals和jiaqin的交集
1) "dog"
127.0.0.1:6379[15]> SDIFF animals jiaqin ---------------------------------- 查看animals和jiaqin的差集,與集合的先后有關(guān)
1) "elephant"
2) "wolf"
3) "monkey"
4) "tiger"
5) "fox"
127.0.0.1:6379[15]> SDIFF jiaqin animals
1) "duck"
2) "chicken"
3) "pig"
127.0.0.1:6379[15]> SUNION animals jiaqin -------------------------------- 查看animals和jiaqin的并集
1) "duck"
2) "wolf"
3) "tiger"
4) "monkey"
5) "fox"
6) "dog"
7) "elephant"
8) "pig"
9) "chicken"
sorted_set有序集合
127.0.0.1:6379[15]> help @sorted_set
ZADD key [NX|XX] [CH] [INCR] score member [score member ...]
summary: Add one or more members to a sorted set, or update its score if it already exists
since: 1.2.0
ZCARD key
summary: Get the number of members in a sorted set
since: 1.2.0
ZCOUNT key min max
summary: Count the members in a sorted set with scores within the given values
since: 2.0.0
ZINCRBY key increment member
summary: Increment the score of a member in a sorted set
since: 1.2.0
ZINTERSTORE destination numkeys key [key ...] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX]
summary: Intersect multiple sorted sets and store the resulting sorted set in a new key
since: 2.0.0
ZLEXCOUNT key min max
summary: Count the number of members in a sorted set between a given lexicographical range
since: 2.8.9
ZRANGE key start stop [WITHSCORES]
summary: Return a range of members in a sorted set, by index
since: 1.2.0
ZRANGEBYLEX key min max [LIMIT offset count]
summary: Return a range of members in a sorted set, by lexicographical range
since: 2.8.9
ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]
summary: Return a range of members in a sorted set, by score
since: 1.0.5
ZRANK key member
summary: Determine the index of a member in a sorted set
since: 2.0.0
ZREM key member [member ...]
summary: Remove one or more members from a sorted set
since: 1.2.0
ZREMRANGEBYLEX key min max
summary: Remove all members in a sorted set between the given lexicographical range
since: 2.8.9
ZREMRANGEBYRANK key start stop
summary: Remove all members in a sorted set within the given indexes
since: 2.0.0
ZREMRANGEBYSCORE key min max
summary: Remove all members in a sorted set within the given scores
since: 1.2.0
ZREVRANGE key start stop [WITHSCORES]
summary: Return a range of members in a sorted set, by index, with scores ordered from high to low
since: 1.2.0
ZREVRANGEBYLEX key max min [LIMIT offset count]
summary: Return a range of members in a sorted set, by lexicographical range, ordered from higher to lower strings.
since: 2.8.9
ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]
summary: Return a range of members in a sorted set, by score, with scores ordered from high to low
since: 2.2.0
ZREVRANK key member
summary: Determine the index of a member in a sorted set, with scores ordered from high to low
since: 2.0.0
ZSCAN key cursor [MATCH pattern] [COUNT count]
summary: Incrementally iterate sorted sets elements and associated scores
since: 2.8.0
ZSCORE key member
summary: Get the score associated with the given member in a sorted set
since: 1.2.0
ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX]
summary: Add multiple sorted sets and store the resulting sorted set in a new key
since: 2.0.0
示例
127.0.0.1:6379[15]> ZADD employees 1 tom 3 jerry 9 abama 7 trump 4 bush ---- 創(chuàng)建一個有序數(shù)組表
(integer) 5
127.0.0.1:6379[15]> ZSCORE employees trump --------------------------------- 查看trump的值
"7"
127.0.0.1:6379[15]> ZRANK employees trump ---------------------------------- 查看trump的suoyin
(integer) 3
127.0.0.1:6379[15]> ZRANK employees bush ----------------------------------- 查看bush的suoyin
(integer) 2
127.0.0.1:6379[15]> ZRANGE employees 1 3 ----------------------------------- 查看索引為1到3的名單
1) "jerry"
2) "bush"
3) "trump"
127.0.0.1:6379[15]> ZRANGEBYSCORE employees 3 10 --------------------------- 按照得分3到10的順序排列
1) "jerry"
2) "bush"
3) "trump"
4) "abama"
pubsub發(fā)布訂閱隊列丧凤,一個隊列相當(dāng)于一個頻道募闲,有人不斷在往里面發(fā)送數(shù)據(jù),有人不斷從外面取得數(shù)據(jù)愿待,一個人訂閱了一個頻道浩螺,訂閱者就能接受到頻道的更新信息。
127.0.0.1:6379[15]> help @pubsub
PSUBSCRIBE pattern [pattern ...] ----------------------------------------------- 基于模式定閱
summary: Listen for messages published to channels matching the given patterns
since: 2.0.0
PUBLISH channel message ------------------------------------------------------- 向一個頻道放入一則消息
summary: Post a message to a channel
since: 2.0.0
PUBSUB subcommand [argument [argument ...]]---------------------------------- 獲取指定發(fā)布隊列的信息
summary: Inspect the state of the Pub/Sub subsystem
since: 2.8.0
PUNSUBSCRIBE [pattern [pattern ...]] ---------------------------------------- 基于模式取消定閱
summary: Stop listening for messages posted to channels matching the given patterns
since: 2.0.0
SUBSCRIBE channel [channel ...] --------------------------------------------- 定閱頻道
summary: Listen for messages published to the given channels
since: 2.0.0
UNSUBSCRIBE [channel [channel ...]] ----------------------------------------- 取消定閱
summary: Stop listening for messages posted to the given channels
since: 2.0.0
示例
本機ssh 1:發(fā)布
127.0.0.1:6379[15]> PUBLISH ops 'kernel is come'
(integer) 1
127.0.0.1:6379[15]> PUBLISH ops 'kernel is new'
(integer) 1
[root@C7mini ~]#redis-cli
本機ssh 2:定閱呼盆、接收
127.0.0.1:6379> SUBSCRIBE ops dev
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "ops"
3) (integer) 1
1) "subscribe"
2) "dev"
3) (integer) 2
1) "message"
2) "ops"
3) "kernel is come"
1) "message"
2) "ops"
3) "kernel is new"