redis日常基础

1、redis临时查看是否持久化
[mwopr@CNSZ22PL2875 ~]$ /app/redis/bin/redis-cli -h 10.xxx.62.40 -p 8080 -a yzjy9kerhsku4by1
10.xxx.62.40:8080> CONFIG GET save (查看持久化,无储存信息)
1) "save"
2) ""

2、慢日志查询
slow log是记录在内存中的,所以即使你记录所有的命令(将slowlog-log-slower-than设为0),对性能的影响也很小。
slowlog get: 列出所有slow log
slowlog get N:列出最近N条slow log
[mwopr@CNSZ17PL4424 conf]$ ../bin/redis-cli -h 10.xxx.78.188 -p 8080 -a dqen5bvqc1qdtrvv
10.xxx.63.84:8080> SLOWLOG get
1) 1) (integer) 14
2) (integer) 1309448221
3) (integer) 15
4) 1) "ping"
2) 1) (integer) 3
2) (integer) 1587506280
3) (integer) 44555
4) 1) "SMEMBERS"
2) "spring:session:expirations:1587506280000"
每个条目由4个字段构成:
1)用于表示该条slow log的唯一id
2)以unix时间戳表示的日志记录时间
3)命令执行时间,单位:微秒
4) 执行的具体命令
只有当reids重启后,id编号才会被重置。

3、redis哨兵连接数满
重启机制:查看连接数,查看进程,杀死,删除pid,启动服务。
[mwopr@sz03~]$ netstat -an |grep 100.xxx.53.56:8001 |wc -l
10001
[mwopr@sz03bla0417zzzz ~]$ netstat -lnpt |grep 100.xxx.53.56:8001
tcp 0 0 100.xxx.53.56:8001 0.0.0.0:* LISTEN 466497/redis-server
[mwopr@sz03bla0417zzzz ~]$ kill -9 466497
[mwopr@sz0z ~]$ rm /app/redis/run/ELOG_WPM_CORE_CNSZ20_PST_REDIS_CACHE_CALC_SEN_01.pid
[mwopr@sz0z ~]$ /app/redis/scripts/ELOG_WPM_CORE_CNSZ20_PST_REDIS_CACHE_CALC_SEN_01.sh start

4、在线配置内存,并写入配置文件
对应关系:24G——25769803776 32G——34359738368
修改为24G: ./redis-cli-h 100.xx.56.170 -p 8080 -a admin.123 config set maxmemory 25769803776
保存: ./redis-cli-h 100.66.56.170 -p 8080 -a admin.123 config rewrite

5、批量停止redis实例
[mwopr@CNSZ20PL0507 ~]$ cd /app/redis/scripts
[mwopr@CNSZ20PL0507 scripts]$ for i in `ls /app/redis/scripts`;do ./$i stop;sleep 2 ;done 注意sleep时间,不然停止有问题

6、redis键通知开启
在默认情况下,键空间的事件通知功能是禁用的(notify-keyspace-events “”),因为这个功能会消耗一些CPU性能,虽然几乎感觉不到性能消耗。
\hline E & 键事件通知,所有通知以 `__keyevent@<db>__` 为前缀 \\
\hline g & DEL 、 EXPIRE 、 RENAME 等类型无关的通用命令的通知 \\
\hline e & 驱逐(evict)事件:每当有键因为 maxmemory 政策而被删除时发送 \\
输入的参数中至少要有一个 K 或者 E , 否则的话, 不管其余的参数是什么, 都不会有任何通知被分发。
echo "CONFIG GET notify-keyspace-events" | /app/redis5/bin/redis-cli -h 100.xx.154.52 -p 8080 -a ZGevJ6kqFs5dtbpu3ZVTT7fh 查看参数
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
1) "notify-keyspace-events"
2) "
echo "CONFIG FSSET notify-keyspace-events Egx" | /app/redis5/bin/redis-cli -h 100.xx.154.52 -p 8080 -a ZGevJ6kqFs5dtbpu3ZVTT7fh 配置参数
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
OK
echo "CONFIG GET notify-keyspace-events" | /app/redis5/bin/redis-cli -h 100.xx.154.52 -p 8080 -a ZGevJ6kqFs5dtbpu3ZVTT7fh
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
1) "notify-keyspace-events"
2) "gxE"
[mwopr@sz01bla0074host ~]$ echo "CONFIG FSREWRITE" | /app/redis5/bin/redis-cli -h 100.xx.154.52 -p 8080 -a ZGevJ6kqFs5dtbpu3ZVTT7fh
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
OK
[mwopr@sz01bla0074host ~]$ grep notify-keyspace-events /app/redis5/conf/INC_BCP_CORE_CNSZ22_REDIS5_Af43Y52z_01.conf
notify-keyspace-events "gxE"

7、redis哨兵主从操作
/app/redis5/bin/redis-cli -h 100.xx.154.52 -p 8001 info sentinel 哨兵信息
/app/redis5/bin/redis-cli -h 100.x0.154.52 -p 8080 -a ZGevJ6kqFs5dtbpu3ZVTT7fh info Replication主从信息

8、redis清理数据
查看所有key值:keys *
删除指定索引的值:del key
清空整个 Redis 服务器的数据:flushall
清空当前库中的所有 key:flushdb
查看当前数据库的 key 的数量:DBSIZE

9、redis数据抓包分析:
[mwopr@cn3 ~]$ /app/redis/bin/redis-cli -h 10.xx.122.135 -p 8080 -a d6pqucsjczv1bzrj monitor >/tmp/0215_bei.txt
[mwopr@cn3 ~]$ cat /tmp/0215_bei.txt |awk '{print $4}' |sort -nk1|uniq -c |more
/app/redis/bin/redis-cli -h 10.xx.223.69 -p 8080 -a HBMOt4azLK --stat
查看redis数据增长状态
[appdeploy@cnsz4398:/home/appdeploy]$/app/redis/bin/redis-cli -h 10.116.223.69 -p 8080 -a HBMOt4azLK --stat

10、redis cluster清理数据
为避免重复停、启redis单实例,删除rdb文件。通过使用

11、修改redis密码,哨兵密码
config set masterauth PassW0@@rdb#
config set requirepass PassW0@@rdb#
config rewrite

posted @ 2021-04-12 14:13  wang_wei123  阅读(191)  评论(0编辑  收藏  举报