Redis命令使用示例(一)

1 ACL CAT

检查所有可用类别。

> ACL CAT
 1) "keyspace"
 2) "read"
 3) "write"
 4) "set"
 5) "sortedset"
 6) "list"
 7) "hash"
 8) "string"
 9) "bitmap"
10) "hyperloglog"
11) "geo"
12) "stream"
13) "pubsub"
14) "admin"
15) "fast"
16) "slow"
17) "blocking"
18) "dangerous"
19) "connection"
20) "transaction"
21) "scripting"

检查哪些命令是给定类别的一部分。

> ACL CAT dangerous
 1) "flushdb"
 2) "acl"
 3) "slowlog"
 4) "debug"
 5) "role"
 6) "keys"
 7) "pfselftest"
 8) "client"
 9) "bgrewriteaof"
10) "replicaof"
11) "monitor"
12) "restore-asking"
13) "latency"
14) "replconf"
15) "pfdebug"
16) "bgsave"
17) "sync"
18) "config"
19) "flushall"
20) "cluster"
21) "info"
22) "lastsave"
23) "slaveof"
24) "swapdb"
25) "module"
26) "restore"
27) "migrate"
28) "save"
29) "shutdown"
30) "psync"
31) "sort"

2 ACL DELUSER

删除所有指定的ACL用户,并终止与这些用户进行身份验证的所有连接。

> ACL DELUSER antirez
1

3 ACL DRYRUN

可用于测试给定用户的权限,而不必启用该用户或导致运行该命令的副作用。

> ACL SETUSER VIRGINIA +SET ~*
"OK"
> ACL DRYRUN VIRGINIA SET foo bar
"OK"
> ACL DRYRUN VIRGINIA GET foo
"User VIRGINIA has no permissions to run the 'get' command"

4 ACL GENPASS

 生成安全的用户密码。

> ACL GENPASS
"dd721260bfe1b3d9601e7fbab36de6d04e2e67b0ef1c53de59d45950db0dd3cc"

> ACL GENPASS 32
"355ef3dd"

> ACL GENPASS 5
"90"

5 ACL GETUSER

获取指定 ACL 用户的详细权限信息。

> ACL SETUSER sample on nopass +GET allkeys &* (+SET ~key2)
"OK"
> ACL GETUSER sample
1) "flags"
2) 1) "on"
   2) "allkeys"
   3) "nopass"
3) "passwords"
4) (empty array)
5) "commands"
6) "+@all"
7) "keys"
8) "~*"
9) "channels"
10) "&*"
11) "selectors"
12) 1) 1) "commands"
       6) "+SET"
       7) "keys"
       8) "~key2"
       9) "channels"
       10) "&*"

6 ACL LIST

显示当前注册的所有用户的详细信息。

> ACL LIST
1) "user antirez on #9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 ~objects:* &* +@all -@admin -@dangerous"
2) "user default on nopass ~* &* +@all"

7 ACL LOAD

从配置的 ACL 文件中重新加载 ACL 规则。

> ACL LOAD
+OK

> ACL LOAD
-ERR /tmp/foo:1: Unknown command or category name in ACL...

8 ACL LOG

处理和查看与 ACL 相关的日志。

> AUTH someuser wrongpassword
(error) WRONGPASS invalid username-password pair
> ACL LOG 1
1)  1) "count"
    2) (integer) 1
    3) "reason"
    4) "auth"
    5) "context"
    6) "toplevel"
    7) "object"
    8) "AUTH"
    9) "username"
   10) "someuser"
   11) "age-seconds"
   12) "8.038"
   13) "client-info"
   14) "id=3 addr=127.0.0.1:57275 laddr=127.0.0.1:6379 fd=8 name= age=16 idle=0 flags=N db=0 sub=0 psub=0 ssub=0 multi=-1 qbuf=48 qbuf-free=16842 argv-mem=25 multi-mem=0 rbs=1024 rbp=0 obl=0 oll=0 omem=0 tot-mem=18737 events=r cmd=auth user=default redir=-1 resp=2"
   15) "entry-id"
   16) (integer) 0
   17) "timestamp-created"
   18) (integer) 1675361492408
   19) "timestamp-last-updated"
   20) (integer) 1675361492408

9 ACL SAVE

将当前的 ACL配置保存到 ACL 文件中。

> ACL SAVE
+OK

> ACL SAVE
-ERR There was an error trying to save the ACLs. Please check the server logs for more information

10 ACL SETUSER

如果用户已经存在,除了已经设置的规则之外,还简单地应用所提供的ACL规则。

ACL SETUSER virginia on allkeys +set

使用另一个ACL SETUSER调用来修改用户规则。

ACL SETUSER virginia +get

设置了两组权限,一组是在用户上定义的,另一组是用选择器定义的。

ACL SETUSER virginia on +GET allkeys (+SET ~app1*)

特殊规则重置作为第一个规则,以刷新所有其他现有规则。

ACL SETUSER antirez reset [... other rules ...]

 重置用户后,其ACL规则将恢复为默认值:不活动,无密码,不能执行任何命令,也不能访问任何密钥或通道

> ACL SETUSER antirez reset
+OK
> ACL LIST
1) "user antirez off -@all"

11 ACL USERS

显示Redis ACL系统中当前配置的所有用户的用户名列表。

> ACL USERS
1) "anna"
2) "antirez"
3) "default"

12 ACL WHOAMI

返回用于验证当前连接的用户名。

> ACL WHOAMI
"default"

13 BGREWRITEAOF

异步执行 AOF文件的重写操作。

BGREWRITEAOF

14 BGSAV

在后台保存数据库。

BGSAVE [SCHEDULE]

15 COMMAND COUNT

返回此Redis服务器中总命令数的整数回复。

redis> COMMAND COUNT
(integer) 241
redis> 

16 COMMAND DOCS

返回有关命令的文档信息。

redis> COMMAND DOCS SET
1) "set"
2) 1) "summary"
   2) "Sets the string value of a key, ignoring its type. The key is created if it doesn't exist."
   3) "since"
   4) "1.0.0"
   5) "group"
   6) "string"
   7) "complexity"
   8) "O(1)"
   9) "history"
   10) 1) 1) "2.6.12"
          2) "Added the `EX`, `PX`, `NX` and `XX` options."
       2) 1) "6.0.0"
          2) "Added the `KEEPTTL` option."
       3) 1) "6.2.0"
          2) "Added the `GET`, `EXAT` and `PXAT` option."
       4) 1) "7.0.0"
          2) "Allowed the `NX` and `GET` options to be used together."
   11) "arguments"
   12) 1) 1) "name"
          2) "key"
          3) "type"
          4) "key"
          5) "display_text"
          6) "key"
          7) "key_spec_index"
          8) (integer) 0
       2) 1) "name"
          2) "value"
          3) "type"
          4) "string"
          5) "display_text"
          6) "value"
       3) 1) "name"
          2) "condition"
          3) "type"
          4) "oneof"
          5) "since"
          6) "2.6.12"
          7) "flags"
          8) 1) "optional"
          9) "arguments"
          10) 1) 1) "name"
                 2) "nx"
                 3) "type"
                 4) "pure-token"
                 5) "display_text"
                 6) "nx"
                 7) "token"
                 8) "NX"
              2) 1) "name"
                 2) "xx"
                 3) "type"
                 4) "pure-token"
                 5) "display_text"
                 6) "xx"
                 7) "token"
                 8) "XX"
       4) 1) "name"
          2) "get"
          3) "type"
          4) "pure-token"
          5) "display_text"
          6) "get"
          7) "token"
          8) "GET"
          9) "since"
          10) "6.2.0"
          11) "flags"
          12) 1) "optional"
       5) 1) "name"
          2) "expiration"
          3) "type"
          4) "oneof"
          5) "flags"
          6) 1) "optional"
          7) "arguments"
          8) 1) 1) "name"
                2) "seconds"
                3) "type"
                4) "integer"
                5) "display_text"
                6) "seconds"
                7) "token"
                8) "EX"
                9) "since"
                10) "2.6.12"
             2) 1) "name"
                2) "milliseconds"
                3) "type"
                4) "integer"
                5) "display_text"
                6) "milliseconds"
                7) "token"
                8) "PX"
                9) "since"
                10) "2.6.12"
             3) 1) "name"
                2) "unix-time-seconds"
                3) "type"
                4) "unix-time"
                5) "display_text"
                6) "unix-time-seconds"
                7) "token"
                8) "EXAT"
                9) "since"
                10) "6.2.0"
             4) 1) "name"
                2) "unix-time-milliseconds"
                3) "type"
                4) "unix-time"
                5) "display_text"
                6) "unix-time-milliseconds"
                7) "token"
                8) "PXAT"
                9) "since"
                10) "6.2.0"
             5) 1) "name"
                2) "keepttl"
                3) "type"
                4) "pure-token"
                5) "display_text"
                6) "keepttl"
                7) "token"
                8) "KEEPTTL"
                9) "since"
                10) "6.0.0"
redis> 

17 COMMAND GETKEYS

返回完整Redis命令中的键的数组回复。

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> 

18 COMMAND GETKEYSANDFLAGS

返回完整Redis命令中键的数组回复及其使用标志。

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 GETKEYSANDFLAGS LMOVE mylist1 mylist2 left left
1) 1) "mylist1"
   2) 1) "RW"
      2) "access"
      3) "delete"
2) 1) "mylist2"
   2) 1) "RW"
      2) "insert"
redis> 

 19 LATENCY LATEST

 用于获取最新的延迟信息。

127.0.0.1:6379> latency latest
1) 1) "command"
   2) (integer) 1405067976
   3) (integer) 251
   4) (integer) 1001

20 MEMORY USAGE

 用于估算给定 key 的内存使用情况。

> SET foo bar
OK
> MEMORY USAGE foo
(integer) 56
> SET foo2 mybar
OK
> MEMORY USAGE foo2
(integer) 64
> SET foo3 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
OK
> MEMORY USAGE foo3
(integer) 160

21 MONITOR

用于实时监视Redis数据库操作的命令。

$ redis-cli monitor
1339518083.107412 [0 127.0.0.1:60866] "keys" "*"
1339518087.877697 [0 127.0.0.1:60866] "dbsize"
1339518090.420270 [0 127.0.0.1:60866] "set" "x" "6"
1339518096.506257 [0 127.0.0.1:60866] "get" "x"
1339518099.363765 [0 127.0.0.1:60866] "eval" "return redis.call('set','x','7')" "0"
1339518100.363799 [0 lua] "set" "x" "7"
1339518100.544926 [0 127.0.0.1:60866] "del" "x"

22 REPLICAOF

用于设置或取消主从复制的命令。 

> REPLICAOF NO ONE
"OK"

> REPLICAOF 127.0.0.1 6799
"OK"

23 ROLE

在主实例中调用ROLE时的输出示例:

1) "master"
2) (integer) 3129659
3) 1) 1) "127.0.0.1"
      2) "9001"
      3) "3129242"
   2) 1) "127.0.0.1"
      2) "9002"
      3) "3129543"

在副本实例中调用ROLE时的输出示例:

1) "slave"
2) "127.0.0.1"
3) (integer) 9000
4) "connected"
5) (integer) 3167038

Sentinel输出示例:

1) "sentinel"
2) 1) "resque-master"
   2) "html-fragments-master"
   3) "stats-master"
   4) "metadata-master"

相关推荐

  1. Redis命令使用示例

    2024-06-08 18:46:03       7 阅读
  2. Redis Scan指令解析与使用示例

    2024-06-08 18:46:03       13 阅读
  3. Redis使用实战经验(

    2024-06-08 18:46:03       18 阅读
  4. redis sorted Set命令基本使用

    2024-06-08 18:46:03       9 阅读
  5. 实战Redis常见命令使用

    2024-06-08 18:46:03       8 阅读
  6. NPM介绍和常用命令使用(带示例

    2024-06-08 18:46:03       29 阅读
  7. 常用Linux命令的具体使用示例

    2024-06-08 18:46:03       6 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-08 18:46:03       8 阅读
  2. 【Python教程】压缩PDF文件大小

    2024-06-08 18:46:03       9 阅读
  3. 通过文章id递归查询所有评论(xml)

    2024-06-08 18:46:03       10 阅读

热门阅读

  1. Ansible——user模块

    2024-06-08 18:46:03       7 阅读
  2. SD-WAN加速跨国服务器访问

    2024-06-08 18:46:03       6 阅读
  3. Spring Boot中实现规则引擎源码教程

    2024-06-08 18:46:03       7 阅读
  4. android:text 总为大写字母的原因

    2024-06-08 18:46:03       7 阅读
  5. input只允许输入数字

    2024-06-08 18:46:03       6 阅读
  6. 数据结构汇总学习(ing)

    2024-06-08 18:46:03       6 阅读
  7. 注解 - @RequestBody

    2024-06-08 18:46:03       6 阅读
  8. 阿里云一键登录号码认证服务

    2024-06-08 18:46:03       6 阅读
  9. pytorch里面封装好的函数,如果要修改怎么办

    2024-06-08 18:46:03       8 阅读
  10. C语言——第五章习题

    2024-06-08 18:46:03       6 阅读
  11. 动手学深度学习——tensor

    2024-06-08 18:46:03       6 阅读