Redis常用数据类型Stream之生产者端与常用命令-----Redis

发布时间:2024年01月18日

[root@localhost ~]# redis-cli -a abc123 --raw
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> lpush list1 1 2 3 4 5
14
127.0.0.1:6379> lrange list1
ERR wrong number of arguments for 'lrange' command

127.0.0.1:6379> lrange list1 0 -1
5
4
3
2
1
9
java
mysql
7
6
5
4
3
2
127.0.0.1:6379> rpop list1 4
2
3
4
5
127.0.0.1:6379> rpop list1 4
6
7
mysql
java
127.0.0.1:6379> rpop list1 4
9
1
2
3
127.0.0.1:6379> rpop list1 4
4
5
127.0.0.1:6379> rpop list1 4

127.0.0.1:6379> xadd mystream * id 11 cname z3
1705477460958-0
127.0.0.1:6379> xadd mystream * id 12 cname lisi
1705477477965-0
127.0.0.1:6379> xadd mystream * k1 v1 k2 v2 k3 v3
1705477496112-0
127.0.0.1:6379> xadd mystream k1 v1 k2 v2 k3 v3
ERR Invalid stream ID specified as stream command argument

127.0.0.1:6379> type mystream
stream
127.0.0.1:6379> xrange mystream
ERR wrong number of arguments for 'xrange' command

127.0.0.1:6379> xrange mystream - +
1705477460958-0
id
11
cname
z3
1705477477965-0
id
12
cname
lisi
1705477496112-0
k1
v1
k2
v2
k3
v3
127.0.0.1:6379> quit
[root@localhost ~]# redis-cli -a abc123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> xrange mystream - +
1) 1) "1705477460958-0"
   2) 1) "id"
      2) "11"
      3) "cname"
      4) "z3"
2) 1) "1705477477965-0"
   2) 1) "id"
      2) "12"
      3) "cname"
      4) "lisi"
3) 1) "1705477496112-0"
   2) 1) "k1"
      2) "v1"
      3) "k2"
      4) "v2"
      5) "k3"
      6) "v3"
127.0.0.1:6379> xrange mystream - + count 1
1) 1) "1705477460958-0"
   2) 1) "id"
      2) "11"
      3) "cname"
      4) "z3"
127.0.0.1:6379> xrevrange mystream + 1
1) 1) "1705477496112-0"
   2) 1) "k1"
      2) "v1"
      3) "k2"
      4) "v2"
      5) "k3"
      6) "v3"
2) 1) "1705477477965-0"
   2) 1) "id"
      2) "12"
      3) "cname"
      4) "lisi"
3) 1) "1705477460958-0"
   2) 1) "id"
      2) "11"
      3) "cname"
      4) "z3"
127.0.0.1:6379> 
[root@localhost ~]# redis-cli -a abc123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> xdel mystream 1705477496112-0
(integer) 1
127.0.0.1:6379> xrange mystream 0 -1
(error) ERR Invalid stream ID specified as stream command argument
127.0.0.1:6379> xrange mystream - +
1) 1) "1705477460958-0"
   2) 1) "id"
      2) "11"
      3) "cname"
      4) "z3"
2) 1) "1705477477965-0"
   2) 1) "id"
      2) "12"
      3) "cname"
      4) "lisi"
127.0.0.1:6379> xlen mystream
(integer) 2
127.0.0.1:6379> xadd mystream * k1 v1
"1705478593777-0"
127.0.0.1:6379> xadd mystream * k2 v2
"1705478599589-0"
127.0.0.1:6379> xrange mystream - +
1) 1) "1705477460958-0"
   2) 1) "id"
      2) "11"
      3) "cname"
      4) "z3"
2) 1) "1705477477965-0"
   2) 1) "id"
      2) "12"
      3) "cname"
      4) "lisi"
3) 1) "1705478593777-0"
   2) 1) "k1"
      2) "v1"
4) 1) "1705478599589-0"
   2) 1) "k2"
      2) "v2"
127.0.0.1:6379> xtrim mystream maxlen 2
(integer) 2
127.0.0.1:6379> xrange mystream - +
1) 1) "1705478593777-0"
   2) 1) "k1"
      2) "v1"
2) 1) "1705478599589-0"
   2) 1) "k2"
      2) "v2"
127.0.0.1:6379> xrange mystream - +
1) 1) "1705478593777-0"
   2) 1) "k1"
      2) "v1"
2) 1) "1705478599589-0"
   2) 1) "k2"
      2) "v2"
127.0.0.1:6379> xtrim mystream minid 1705478599589-0
(integer) 1
127.0.0.1:6379> xrange mystream - +
1) 1) "1705478599589-0"
   2) 1) "k2"
      2) "v2"
127.0.0.1:6379> xadd mystream * k3 v3
"1705478787003-0"
127.0.0.1:6379> xadd mystream * k4 v4
"1705478800070-0"
127.0.0.1:6379> xadd mystream * k5 v5
"1705478811040-0"
127.0.0.1:6379> xadd mystream * k6 v6
"1705478849163-0"
127.0.0.1:6379> xadd mystream * k7 v7
"1705478862668-0"
127.0.0.1:6379> xrange mystream - +
1) 1) "1705478599589-0"
   2) 1) "k2"
      2) "v2"
2) 1) "1705478787003-0"
   2) 1) "k3"
      2) "v3"
3) 1) "1705478800070-0"
   2) 1) "k4"
      2) "v4"
4) 1) "1705478811040-0"
   2) 1) "k5"
      2) "v5"
5) 1) "1705478849163-0"
   2) 1) "k6"
      2) "v6"
6) 1) "1705478862668-0"
   2) 1) "k7"
      2) "v7"
127.0.0.1:6379> xread count 2 streams mystream $
(nil)
127.0.0.1:6379> xread count 2 streams mystream 0-0
1) 1) "mystream"
   2) 1) 1) "1705478599589-0"
         2) 1) "k2"
            2) "v2"
      2) 1) "1705478787003-0"
         2) 1) "k3"
            2) "v3"
127.0.0.1:6379> xread count 10 streams mystream 0-0
1) 1) "mystream"
   2) 1) 1) "1705478599589-0"
         2) 1) "k2"
            2) "v2"
      2) 1) "1705478787003-0"
         2) 1) "k3"
            2) "v3"
      3) 1) "1705478800070-0"
         2) 1) "k4"
            2) "v4"
      4) 1) "1705478811040-0"
         2) 1) "k5"
            2) "v5"
      5) 1) "1705478849163-0"
         2) 1) "k6"
            2) "v6"
      6) 1) "1705478862668-0"
         2) 1) "k7"
            2) "v7"
127.0.0.1:6379> xread streams mystream 0-0
1) 1) "mystream"
   2) 1) 1) "1705478599589-0"
         2) 1) "k2"
            2) "v2"
      2) 1) "1705478787003-0"
         2) 1) "k3"
            2) "v3"
      3) 1) "1705478800070-0"
         2) 1) "k4"
            2) "v4"
      4) 1) "1705478811040-0"
         2) 1) "k5"
            2) "v5"
      5) 1) "1705478849163-0"
         2) 1) "k6"
            2) "v6"
      6) 1) "1705478862668-0"
         2) 1) "k7"
            2) "v7"
127.0.0.1:6379> xread streams mystream 0-0
1) 1) "mystream"
   2) 1) 1) "1705478599589-0"
         2) 1) "k2"
            2) "v2"
      2) 1) "1705478787003-0"
         2) 1) "k3"
            2) "v3"
      3) 1) "1705478800070-0"
         2) 1) "k4"
            2) "v4"
      4) 1) "1705478811040-0"
         2) 1) "k5"
            2) "v5"
      5) 1) "1705478849163-0"
         2) 1) "k6"
            2) "v6"
      6) 1) "1705478862668-0"
         2) 1) "k7"
            2) "v7"
127.0.0.1:6379> xread count 1 block 0 streams mystream $
1) 1) "mystream"
   2) 1) 1) "1705480028369-0"
         2) 1) "k8"
            2) "v8"
(68.70s)

[root@localhost ~]# redis-cli -a abc123 --raw
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> lpush list1 1 2 3 4 5
14
127.0.0.1:6379> lrange list1
ERR wrong number of arguments for 'lrange' command

127.0.0.1:6379> lrange list1 0 -1
5
4
3
2
1
9
java
mysql
7
6
5
4
3
2
127.0.0.1:6379> rpop list1 4
2
3
4
5
127.0.0.1:6379> rpop list1 4
6
7
mysql
java
127.0.0.1:6379> rpop list1 4
9
1
2
3
127.0.0.1:6379> rpop list1 4
4
5
127.0.0.1:6379> rpop list1 4

127.0.0.1:6379> xadd mystream * id 11 cname z3
1705477460958-0
127.0.0.1:6379> xadd mystream * id 12 cname lisi
1705477477965-0
127.0.0.1:6379> xadd mystream * k1 v1 k2 v2 k3 v3
1705477496112-0
127.0.0.1:6379> xadd mystream k1 v1 k2 v2 k3 v3
ERR Invalid stream ID specified as stream command argument

127.0.0.1:6379> type mystream
stream
127.0.0.1:6379> xrange mystream
ERR wrong number of arguments for 'xrange' command

127.0.0.1:6379> xrange mystream - +
1705477460958-0
id
11
cname
z3
1705477477965-0
id
12
cname
lisi
1705477496112-0
k1
v1
k2
v2
k3
v3
127.0.0.1:6379> quit
[root@localhost ~]# redis-cli -a abc123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> xrange mystream - +
1) 1) "1705477460958-0"
? ?2) 1) "id"
? ? ? 2) "11"
? ? ? 3) "cname"
? ? ? 4) "z3"
2) 1) "1705477477965-0"
? ?2) 1) "id"
? ? ? 2) "12"
? ? ? 3) "cname"
? ? ? 4) "lisi"
3) 1) "1705477496112-0"
? ?2) 1) "k1"
? ? ? 2) "v1"
? ? ? 3) "k2"
? ? ? 4) "v2"
? ? ? 5) "k3"
? ? ? 6) "v3"
127.0.0.1:6379> xrange mystream - + count 1
1) 1) "1705477460958-0"
? ?2) 1) "id"
? ? ? 2) "11"
? ? ? 3) "cname"
? ? ? 4) "z3"
127.0.0.1:6379> xrevrange mystream + 1
1) 1) "1705477496112-0"
? ?2) 1) "k1"
? ? ? 2) "v1"
? ? ? 3) "k2"
? ? ? 4) "v2"
? ? ? 5) "k3"
? ? ? 6) "v3"
2) 1) "1705477477965-0"
? ?2) 1) "id"
? ? ? 2) "12"
? ? ? 3) "cname"
? ? ? 4) "lisi"
3) 1) "1705477460958-0"
? ?2) 1) "id"
? ? ? 2) "11"
? ? ? 3) "cname"
? ? ? 4) "z3"
127.0.0.1:6379>?
[root@localhost ~]# redis-cli -a abc123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> xdel mystream 1705477496112-0
(integer) 1
127.0.0.1:6379> xrange mystream 0 -1
(error) ERR Invalid stream ID specified as stream command argument
127.0.0.1:6379> xrange mystream - +
1) 1) "1705477460958-0"
? ?2) 1) "id"
? ? ? 2) "11"
? ? ? 3) "cname"
? ? ? 4) "z3"
2) 1) "1705477477965-0"
? ?2) 1) "id"
? ? ? 2) "12"
? ? ? 3) "cname"
? ? ? 4) "lisi"
127.0.0.1:6379> xlen mystream
(integer) 2
127.0.0.1:6379> xadd mystream * k1 v1
"1705478593777-0"
127.0.0.1:6379> xadd mystream * k2 v2
"1705478599589-0"
127.0.0.1:6379> xrange mystream - +
1) 1) "1705477460958-0"
? ?2) 1) "id"
? ? ? 2) "11"
? ? ? 3) "cname"
? ? ? 4) "z3"
2) 1) "1705477477965-0"
? ?2) 1) "id"
? ? ? 2) "12"
? ? ? 3) "cname"
? ? ? 4) "lisi"
3) 1) "1705478593777-0"
? ?2) 1) "k1"
? ? ? 2) "v1"
4) 1) "1705478599589-0"
? ?2) 1) "k2"
? ? ? 2) "v2"
127.0.0.1:6379> xtrim mystream maxlen 2
(integer) 2
127.0.0.1:6379> xrange mystream - +
1) 1) "1705478593777-0"
? ?2) 1) "k1"
? ? ? 2) "v1"
2) 1) "1705478599589-0"
? ?2) 1) "k2"
? ? ? 2) "v2"
127.0.0.1:6379> xrange mystream - +
1) 1) "1705478593777-0"
? ?2) 1) "k1"
? ? ? 2) "v1"
2) 1) "1705478599589-0"
? ?2) 1) "k2"
? ? ? 2) "v2"
127.0.0.1:6379> xtrim mystream minid 1705478599589-0
(integer) 1
127.0.0.1:6379> xrange mystream - +
1) 1) "1705478599589-0"
? ?2) 1) "k2"
? ? ? 2) "v2"
127.0.0.1:6379> xadd mystream * k3 v3
"1705478787003-0"
127.0.0.1:6379> xadd mystream * k4 v4
"1705478800070-0"
127.0.0.1:6379> xadd mystream * k5 v5
"1705478811040-0"
127.0.0.1:6379> xadd mystream * k6 v6
"1705478849163-0"
127.0.0.1:6379> xadd mystream * k7 v7
"1705478862668-0"
127.0.0.1:6379> xrange mystream - +
1) 1) "1705478599589-0"
? ?2) 1) "k2"
? ? ? 2) "v2"
2) 1) "1705478787003-0"
? ?2) 1) "k3"
? ? ? 2) "v3"
3) 1) "1705478800070-0"
? ?2) 1) "k4"
? ? ? 2) "v4"
4) 1) "1705478811040-0"
? ?2) 1) "k5"
? ? ? 2) "v5"
5) 1) "1705478849163-0"
? ?2) 1) "k6"
? ? ? 2) "v6"
6) 1) "1705478862668-0"
? ?2) 1) "k7"
? ? ? 2) "v7"
127.0.0.1:6379> xread count 2 streams mystream $
(nil)
127.0.0.1:6379> xread count 2 streams mystream 0-0
1) 1) "mystream"
? ?2) 1) 1) "1705478599589-0"
? ? ? ? ?2) 1) "k2"
? ? ? ? ? ? 2) "v2"
? ? ? 2) 1) "1705478787003-0"
? ? ? ? ?2) 1) "k3"
? ? ? ? ? ? 2) "v3"
127.0.0.1:6379> xread count 10 streams mystream 0-0
1) 1) "mystream"
? ?2) 1) 1) "1705478599589-0"
? ? ? ? ?2) 1) "k2"
? ? ? ? ? ? 2) "v2"
? ? ? 2) 1) "1705478787003-0"
? ? ? ? ?2) 1) "k3"
? ? ? ? ? ? 2) "v3"
? ? ? 3) 1) "1705478800070-0"
? ? ? ? ?2) 1) "k4"
? ? ? ? ? ? 2) "v4"
? ? ? 4) 1) "1705478811040-0"
? ? ? ? ?2) 1) "k5"
? ? ? ? ? ? 2) "v5"
? ? ? 5) 1) "1705478849163-0"
? ? ? ? ?2) 1) "k6"
? ? ? ? ? ? 2) "v6"
? ? ? 6) 1) "1705478862668-0"
? ? ? ? ?2) 1) "k7"
? ? ? ? ? ? 2) "v7"
127.0.0.1:6379> xread streams mystream 0-0
1) 1) "mystream"
? ?2) 1) 1) "1705478599589-0"
? ? ? ? ?2) 1) "k2"
? ? ? ? ? ? 2) "v2"
? ? ? 2) 1) "1705478787003-0"
? ? ? ? ?2) 1) "k3"
? ? ? ? ? ? 2) "v3"
? ? ? 3) 1) "1705478800070-0"
? ? ? ? ?2) 1) "k4"
? ? ? ? ? ? 2) "v4"
? ? ? 4) 1) "1705478811040-0"
? ? ? ? ?2) 1) "k5"
? ? ? ? ? ? 2) "v5"
? ? ? 5) 1) "1705478849163-0"
? ? ? ? ?2) 1) "k6"
? ? ? ? ? ? 2) "v6"
? ? ? 6) 1) "1705478862668-0"
? ? ? ? ?2) 1) "k7"
? ? ? ? ? ? 2) "v7"
127.0.0.1:6379> xread streams mystream 0-0
1) 1) "mystream"
? ?2) 1) 1) "1705478599589-0"
? ? ? ? ?2) 1) "k2"
? ? ? ? ? ? 2) "v2"
? ? ? 2) 1) "1705478787003-0"
? ? ? ? ?2) 1) "k3"
? ? ? ? ? ? 2) "v3"
? ? ? 3) 1) "1705478800070-0"
? ? ? ? ?2) 1) "k4"
? ? ? ? ? ? 2) "v4"
? ? ? 4) 1) "1705478811040-0"
? ? ? ? ?2) 1) "k5"
? ? ? ? ? ? 2) "v5"
? ? ? 5) 1) "1705478849163-0"
? ? ? ? ?2) 1) "k6"
? ? ? ? ? ? 2) "v6"
? ? ? 6) 1) "1705478862668-0"
? ? ? ? ?2) 1) "k7"
? ? ? ? ? ? 2) "v7"
127.0.0.1:6379> xread count 1 block 0 streams mystream $
1) 1) "mystream"
? ?2) 1) 1) "1705480028369-0"
? ? ? ? ?2) 1) "k8"
? ? ? ? ? ? 2) "v8"
(68.70s)
?

[root@localhost ~]# redis-cli -a abc123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> xadd mystream * k8 v8
"1705480028369-0"

?[root@localhost ~]# redis-cli -a abc123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> xadd mystream * k8 v8
"1705480028369-0"

文章来源:https://blog.csdn.net/2201_75960169/article/details/135654080
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。