安装redis install - redis.io


远程连接 RDM : redis desktop manager

本地连接默认情况不需要密码,直接 redis-cli

# You will also need to set a password unless you explicitly disable protected
# mode.

# When protected mode is on and the default user has no password, the server
# only accepts local connections from the IPv4 address (127.0.0.1), IPv6 address
# (::1) or Unix domain sockets.

# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured.

bind 0.0.0.0
protected-mode no
requirepass default

测试连接

root@u20:/# redis-cli
127.0.0.1:6379> ping
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth default
OK
127.0.0.1:6379> ping
PONG

# 或者直接在命令行输入密码
root@u20t:/# redis-cli -a default
127.0.0.1:6379> ping
PONG

主从复制

# replicaof <masterip> <masterport>
# masterauth <master-password>
# masteruser <username>
  • 指定当前 Redis 实例作为从节点,并连接到指定的主节点进行数据复制。
  • 设置连接到主节点时所需的密码认证。当主节点启用了密码认证(通过 requirepass 配置项),从节点需要提供相应的密码才能成功连接并进行数据复制。
  • 指定用于连接主节点的用户名(需要 Redis 6 及以上版本,并且主节点启用了 ACL)。username 是主节点上配置的具有复制权限的用户名
Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐