linux redis 常用命令

// 客户端连接
redis-cli -h 172.16.1.1 -p 6001


//2 连接远程redis
//格式:redis-cli --raw -h IP -p 端口 -a 密码 -n 库索引
redis-cli --raw -h 172.16.1.108  -p 6001 -a password -n 0

// 读取数据写入到txt
//格式:redis-cli -h IP -a 密码 --raw -n 库索引 hget Key 小key >文件名
redis-cli -h 172.16.0.1 -a password --raw -n 5  hget BagEntity r51050XZM >r51050XZMbag.txt

//获取hash key的所有数据
hvals ServerEntity

//获取hash key 的单条
hmget ServerEntity '171003'

// 存入hash 值
hset ServerEntity 171003 '{"@type":"com.jorsun.game.login.api.server.entity.ServerEntity","activeRewardMap":{"@type":"java.util.concurrent.ConcurrentHashMap"},"addAttackExpRate":5.0,"addEctExpRate":1.0,"addMaxExpRate":5.0,"addProtectingExpRate":5.0,"addRunningExpRate":5.0,"addVirtueExpRate":1.0,"addXinExpRate":5.0,"appStoreExamine":false,"autoChangeServerHost":false,"callUrl":"http://xxxx","canUseGiftCode":true,"checkAddSpeed":false,"checkCon":false,"checkTime":120,"checkVersion":false,"dbId":"231001","dropRate":1.0,"gameServerIp":"xxxxxxx","gameServerPort":8000,"heFuFlag":false,"kickSimulator":false,"kickSimulatorInterval":10,"loadByFile":true,"loginWhiteOpen":false,"maxMsgNum":5000,"mergeId":"0","mergeSource":false,"needTimeCard":false,"needVip":false,"openAutoHit":true,"openCreateRole":true,"openHitBack":false,"openVerifyCheck":false,"rechargeRebate":false,"recordMsg":false,"serverName":"智慧一区","showRecharge":true,"spendRebate":false,"startTime":"2023-10-30T19:00:00","status":0,"test":false,"xcxUrl":"xxxxxxxx"}'

--删除指定key对象
HDEL  ServerEntity 1001

-- 清库
flushdb
--选中第0个库
select 1
--查询所有key
kesy *
-- 查询hash 对象有多少key
hlen key_name


通过文件更新redis 的值,编写 xxx.sh 文件 ,然后执行 sh xxx.sh

REDIS_HOST="172.0.0.1" # Redis服务器的IP地址或主机名
REDIS_PORT=6000       # Redis服务器的端口号
PASSWORD="woshimima"  #密码
DBINDEX=2          #第几个库
FILE="/data/db/r121008AB.txt"   # 要读取的文件路径,文件内容不需要加引号
KEY="TaskEntity"            # Redis中要更新的键名称
USER="r121008AB"            # 用户
content=$(cat $FILE)    # 读取文件内容
redis-cli -h $REDIS_HOST -p $REDIS_PORT -a $PASSWORD -n $DBINDEX HSET $KEY $USER "$content"    # 将内容更新到Redis中

 

posted @ 2024-01-02 17:56  秋香姑娘请你不要紧张  阅读(127)  评论(0编辑  收藏  举报