Redis(三)-常用命令

2020-11-26  本文已影响0人  进击的蚂蚁zzzliu

概述

本节列举下redis安装之后可执行文件命令,以及redis-cli连接之后help命令的使用以及常用命令的总结

1. 可执行文件命令

redis安装后,在src和/usr/local/bin下有几个以redis开头的可执行文件,称为redis shell,这些shell可以执行很多命令

zzzliu@ubuntu:~$ redis-server --help
Usage: ./redis-server [/path/to/redis.conf] [options]
       ./redis-server - (read config from stdin)
       ./redis-server -v or --version
       ./redis-server -h or --help
       ./redis-server --test-memory <megabytes>

Examples:
       ./redis-server (run the server with default conf)
       ./redis-server /etc/redis/6379.conf
       ./redis-server --port 7777
       ./redis-server --port 7777 --replicaof 127.0.0.1 8888
       ./redis-server /etc/myredis.conf --loglevel verbose

Sentinel mode:
       ./redis-server /etc/sentinel.conf --sentinel

2. 可执行文件常用命令

zzzliu@ubuntu:~$ redis-cli --stat
------- data ------ --------------------- load -------------------- - child -
keys       mem      clients blocked requests            connections          
5          562.84K  1       0       82 (+0)             10          
5          562.84K  1       0       83 (+1)             10          
5          562.84K  1       0       84 (+1)             10          
5          562.84K  1       0       85 (+1)             10          
5          562.84K  1       0       86 (+1)             10 
zzzliu@ubuntu:~$ redis-cli --bigkeys

# Scanning the entire keyspace to find biggest keys as well as
# average sizes per key type.  You can use -i 0.1 to sleep 0.1 sec
# per 100 SCAN commands (not usually needed).

[00.00%] Biggest hash   found so far 'user' with 2 fields
[00.00%] Biggest string found so far 'key1' with 3 bytes
[00.00%] Biggest list   found so far 'list1' with 2 items

-------- summary -------

Sampled 5 keys in the keyspace!
Total key length in bytes is 27 (avg len 5.40)

Biggest   list found 'list1' has 2 items
Biggest   hash found 'user' has 2 fields
Biggest string found 'key1' has 3 bytes

1 lists with 2 items (20.00% of keys, avg size 2.00)
1 hashs with 2 fields (20.00% of keys, avg size 2.00)
3 strings with 5 bytes (60.00% of keys, avg size 1.67)
0 streams with 0 entries (00.00% of keys, avg size 0.00)
0 sets with 0 members (00.00% of keys, avg size 0.00)
0 zsets with 0 members (00.00% of keys, avg size 0.00)
//扫描符合给定模式的key,--pattern
zzzliu@ubuntu:~$ redis-cli --scan --pattern '*.stock'
a.stock
b.stock
//配合wc统计特定种类的key个数
zzzliu@ubuntu:~$ redis-cli --scan --pattern '*.stock' | wc -l
2

3. help使用

redis相关命令非常多,很难记住每一个命令,因此help命令就非常重要。help命令有三种用法,下面分别列举:

  1. help <tab>: help后面参数提示补全;输入help + 空格以后按<tab>键可以自动提示补全,也可以先输入前几个字母按照前缀补全;
  2. help <command>: 查看具体命令的用法; 输入help + 空格 + 命令查看具体用法;具体命令可以查看命令的用法描述,命令从那个版本开始,命令属于哪个组等信息
127.0.0.1:6379> help KEYS

  KEYS pattern
  summary: Find all keys matching the given pattern
  since: 1.0.0
  group: generic
  1. help @<group>: 查看命令组的帮助;Redis命令是分组的,例如:Lists/Strings/Cluster等等,可以通过@ + 组名,查看一组命令;
    命令组
127.0.0.1:6379> help @string

  APPEND key value
  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

  ...

4. 常用命令

127.0.0.1:6379> MONITOR
OK
1606372382.244300 [0 127.0.0.1:49412] "COMMAND"
1606372422.887772 [0 127.0.0.1:49412] "HSET" "hash1" "name" "zzzliu"

-------over-------

上一篇 下一篇

猜你喜欢

热点阅读