MAC 安装笔记

下载并且安装

  [plaintext]
1
2
3
4
5
6
7
$ wget http://download.redis.io/releases/redis-3.0.6.tar.gz $ tar xzf redis-3.0.6.tar.gz $ mv redis-3.0.6 redis $ cd redis $ make $ make test $ make install

编辑配置文件

打开 redis.conf 配置文件,找到 dir ./ 这一行内容。

这一行是用来保存数据的,你可以调整为你想要的路径,比如说我的设置如下:

  [plaintext]
1
2
3
4
dir /Users/houbinbin/redis/redis_data bind 127.0.0.1 //本地访问 requirepass 123456 //访问密码

启动 redis-server 服务端

  [plaintext]
1
2
3
$ src/redis-server redis.conf $ src/redis-server redis.conf & //后台-配置文件运行

然后命令行可以看到如下日志:

  [plaintext]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
houbinbindeMacBook-Pro:redis-3.2.3 houbinbin$ 17137:M 23 Oct 09:46:21.924 * Increased maximum number of open files to 10032 (it was originally set to 256). _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 3.2.3 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 17137 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 17137:M 23 Oct 09:46:21.929 # Server started, Redis version 3.2.3 17137:M 23 Oct 09:46:21.930 * The server is now ready to accept connections on port 6379

测试连接性

  [plaintext]
1
2
3
$ redis-cli -a 123456 ping PONG

可能出现的错误

  [plaintext]
1
redis-cli Could not connect to Redis at 127.0.0.1:6379: Connection refused
  • 指定配置文件,重新启动
  [plaintext]
1
2
$ redis-server /Users/houbinbin/redis/redis-3.2.3/redis.conf $ redis-cli

测试连接

使用 redis-cli 客户端连接 redis-server 服务端。

  [plaintext]
1
2
$ cd /Users/houbinbin/redis/redis-3.0.6 $ src/redis-cli -a 123456

命令测试:

  [plaintext]
1
2
3
4
127.0.0.1:6379> set houbinbin hi OK 127.0.0.1:6379> get houbinbin "hi"

关闭 redis-server 服务端

(error) NOAUTH Authentication required.

无奈之下,杀进程。

  [plaintext]
1

常规关闭方式:

  [plaintext]
1
2
3
4
5
$ 127.0.0.1:6379> shutdown not connected> $ redis-cli -a 123456 shutdown //关闭后台

设置密码

set

redis.conf 配置文件中找到 #requirepass foobared,修改为你想要的密码,比如 redis:

  [plaintext]
1
requirepass redis

卸载 redis

  • 删除 /usr/local/bin 文件夹下的文件 redis-*
  [plaintext]
1
$ sudo rm -rf redis-*