Redis——常用命令

 

1、keys命令

redis-cli -h 127.0.0.1 -p 30000 keys "*"

redis-cli -h 127.0.0.1 -p 30000 -n 0 keys "*" 

redis-cli -h 127.0.0.1 -p 30000 -n 1 keys "*" 

redis-cli -h 127.0.0.1 -p 30000 -n 1 hgetall recommend_list

 

redis批量删除: 

redis-cli -h 192.168.1.51 -p 30000  keys "*1051" | xargs redis-cli -h 192.168.1.51 -p 30000  del

redis-cli  -h 192.168.1.52 -p 6379 -n 0 keys "*_1253*"

 

redis-cli -c -h192.168.1.11 EVAL "local keys = redis.call('keys', ARGV[1]) for i, key in ipairs(keys) do redis.call('del', key) end return keys" 0 "a999_*"

 

2、查看docker中的redis日志

docker logs --tail 10 redis6379

 

发现文件权限问题

docker logs --tail 10 redis6379
1:M 27 May 2021 10:03:51.174 # Background saving error
1:M 27 May 2021 10:03:57.086 * 1 changes in 3600 seconds. Saving...
1:M 27 May 2021 10:03:57.086 * Background saving started by pid 1102
1102:C 27 May 2021 10:03:57.087 # Failed opening the RDB file dump.rdb 
(in server root dir /etc) for saving: Permission denied

解决办法

docker exec -it redis6379  chmod -R 777 /etc

docker exec -it redis6379 redis-cli save

 

docker 方式启动单节点redis

docker run -d —name redis_latest \
              -p 6379:6379 \
              -v /home/soft/docker/redis/latest:/data \
              redis \
              —maxmemory 100m

 

 

3、list操作命令

普通队列,右push, 左pop

  34 redis-cli -h 10.60.91.9 -p 6379 -n 2 rpush cy_s10016 "update or insert something ... 001"
  35 redis-cli -h 10.60.91.9 -p 6379 -n 2 rpush cy_s10016 "update or insert something ... 002"
  36 redis-cli -h 10.60.91.9 -p 6379 -n 2 rpush cy_s10016 "update or insert something ... 003"
  37 redis-cli -h 10.60.91.9 -p 6379 -n 2 rpush cy_s10016 "update or insert something ... 004"
  38 redis-cli -h 10.60.91.9 -p 6379 -n 2 rpush cy_s10016 "update or insert something ... 005"
  44 redis-cli -h 10.60.91.9 -p 6379 -n 2 lrange cy_s10016 0 -1
  45 redis-cli -h 10.60.91.9 -p 6379 -n 2 lpop  cy_s10016
  46 redis-cli -h 10.60.91.9 -p 6379 -n 2 lpop  cy_s10016
  47 redis-cli -h 10.60.91.9 -p 6379 -n 2 lpop  cy_s10016

 

阻塞式pop,   左pop, 指定超时时间

  21 redis-cli -h 10.60.91.9 -p 6379 -n 2  blpop cy_s10016 3     
  22 redis-cli -h 10.60.91.9 -p 6379 -n 2  blpop cy_s10016 30    
  23 redis-cli -h 10.60.91.9 -p 6379 -n 2  blpop cy_s10016 30    
  24 redis-cli -h 10.60.91.9 -p 6379 -n 2  blpop cy_s10016 30

 

 4、zset 操作命令

 redis-cli -h  110.160.191.29 -p 6379 -c zrange "ga-ld:scene:1" 0 -1  withscores

 

 

 

 

posted @ 2020-10-09 16:22  会飞的斧头  阅读(115)  评论(0编辑  收藏  举报