通过
ps -ef|grep redis
找到redis的程序目录
在这个目录下面有个redis-cli客户端
使用./redis-cli进入
远程登入redis
redis-cli -h 127.0.0.1 -p 6379
设置密码
config set requirepass 123456
如果有密码的话
第二步
auth ****
带密码登录方式
redis-cli -h 127.0.0.1 -p 6379 -a abc123
进入redis之后
#查看当前信息
info
查看当前连接数
Info clients
#当前连接
client list
查看当前最大允许连接数
CONFIG GET maxclients
修改最大连接数
config set maxclients=10000
如果此时修改不成功 则需要修改配置文件
可以通过sudo su - 进入root权限
配置文件
/etc/systemd/system/redis.service
文件,加上
LimitNOFILE
参数
/etc/systemd/system/redis.service [Service] ... User=redis Group=redis # should be fine as long as you add it under [Service] block LimitNOFILE=65536
重新加载redis
sudo systemctl daemon-reload sudo systemctl restart redis.service
127.0.0.1:6379> CONFIG set maxclients 10000 OK 127.0.0.1:6379> CONFIG get maxclients 1) "maxclients"2) "10000"
写key k1
set k1 1
获得key k1
get k1
删除key
del k1
查看所有key
keys *
#获得当前参数值
config get timeout
#修改值 注意这个超时时间不能设置的太长,比如28800 就不行
CONFIG set timeout 3600;
#远程访问redis报错
DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.
出现如上 这个错误
需要进入 服务器 然后通过 redis-cli -h 172.17.40.150 -p 6379 进入机器
CONFIG SET protected-mode no
这样改了 之后 就能远程连接了。。
redis修改密码
找到redis.conf配置文件。。一般在程序目录上一层
修改 requirepass
例如 requirepass 123456
redis ip访问控制
修改参数 bind
例如 bind 192.168.16.17
#redis 设置生存日期(这里设置6个小时 21600秒)
#详细文档
https://blog.51cto.com/qiangsh/1978459
生成脚本redis_key.sh 内容如下
redis-cli -a ******** -h url地址 -p 6379 -n 14 expire $1 21600
执行命令 对特定key进行 设置
redis-cli -a ***** -h url地址 -p 6379 -n 14 KEYS kttd* |/usr/bin/xargs -I {} ./redis_key.sh {}
#hash操作
查看hash值
查看hash值里面具体的字段值
hget jpk:chehang168 chehang168-appstore
查看整个hash值
hgetall jpk:chehang168
删除hash值中某个字段
hdel myhash field1
#查找在线redis 大key 每隔0.1秒sleep
./redis-cli --bigkeys -i 0.1
redis 退出命令
quit
redis备份命令
1.需要进入redis
2.执行save命令
在 redis 安装目录中自动创建dump.rdb文件
恢复命令
如果需要恢复数据,只需将备份文件 (dump.rdb) 移动到 redis 安装目录并启动服务即可
查看安装目录进入redis 执行命令 config get dir
阿里云平台 禁止高位命令
|
|
| 链接说明:https://partners-intl.aliyun.com/help/zh/redis/user-guide/disable-high-risk-commands |
|
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30127122/viewspace-2668217/ ,如需转载,请注明出处,否则将追究法律责任。