一、首先系统要安装 homebrew
$ brew install redis
安装后的配置文件位置
redis-server /usr/local/etc/redis.conf
用redis-cli连接会报错:
$ redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
编辑配置文件 需要先开启服务端
$ sudo vim /usr/local/etc/redis.conf
查找daemonize /daemonize 把no 改为yes
$ redis-server /usr/local/etc/redis.conf
现在可以了
$ redis-cli
127.0.0.1:6379> set 'a' '123'
OK
127.0.0.1:6379> get 'a'
"123"
127.0.0.1:6379> exit
二、配置redis
开启远程访问,注释bind,在69行
#bind 127.0.0.1 ::1
增加登录密码
查找requirepass /requirepass ,在500行
# requirepass foobared,记得打开注释并修改密码
保存配置文件并退出
重启redis服务
先查看服务的状态:
$ brew services list
Name Status User Plist
kafka stopped
nginx stopped
redis started wangjun /Users/wangjun/Library/LaunchAgents/homebrew.mxcl.redis.plist
zookeeper stopped
重启redis服务
$ brew services restart redis
==> Successfully started `redis` (label: homebrew.mxcl.redis)
$redis-cli -a ********
Warning: Using a password with '-a' option on the command line interface may not be safe
127.0.0.1:6379> get 'a'
"123"