给 redis 设置密码

brew install redis

1
2
3
4
To have launchd start redis now and restart at login:
brew services start redis
Or, if you don't want/need a background service you can just run:
redis-server /usr/local/etc/redis.conf

可以编辑 /usr/local/etc/redis.conf, 设置 redis 密码 requirepass

启动:

1
2
# redis-server
redis-server /usr/local/etc/redis.conf
1
2
3
4
5
6
7
8
9
127.0.0.1:6379> pfadd mykey a b c
(integer) 1
127.0.0.1:6379> pfcount mykey
(integer) 3
127.0.0.1:6379> pfadd mykey2 a b c c d
(integer) 1
127.0.0.1:6379> pfcount mykey2
(integer) 4
127.0.0.1:6379>

批量删除某一类 key

1
redis-cli -h 10.0.0.200 -a 'verycomplexpassword' -n 3 KEYS 'ST_*Qr*' | xargs redis-cli -h 10.0.0.200 -a 'verycomplexpassword' -n 3  DEL

或者

1
redis-cli -h [127.0.0.1](127.0.0.1) -p 8177

进入后输入 auth 进行验证。