Redis操作合集

redis-dump导出

安装依赖

1
sudo apt install ruby rubygems ruby-dev

移除gem自带源(美国服务器下载慢)

1
gem sources --remove https://rubygems.org/ 

添加国内源

1
gem sources -a https://gems.ruby-china.com

查看仓库源

1
2
3
4
5
gem sources -l

*** CURRENT SOURCES ***

http://gems.ruby-china.com/

安装redis-dump

1
gem install redis-dump -V

导出命令为

1
redis-dump > filename.json

导入

将redis-dump导出的数据json文件导入到内存中

1
cat filename.json | redis-load -u 127.0.0.1:6379

rdb倒入导出

redis在命令行模式下输入

1
save

会将数据导出为dump.rdb,,如果要导入rdb,只需要把redis服务停止,然后把数据放置于/var/lib/redis目录下,再次启动redis服务时会自动导入数据

远程访问

Ubuntu20.04下编辑/etc/redis/redis.conf

1
bind 127.0.0.1 ::1

注释掉,就可以实现远程访问

但是如果实际访问会提示

1
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.

1
protected-mode yes

修改为

1
protected-mode no

基本操作

获取所有配置

CONFIG GET *


Redis操作合集
https://blog.jackeylea.com/web/collections-of-redis-operations/
作者
JackeyLea
发布于
2020年12月28日
许可协议