夜间模式
配置与启动
配置Redis
在Redis的安装目录下的redis.config
是redis的配置文件,Redis的配置可以在配置文件中修改
Windows下redis的配置文件名为redis.windows.conf
配置信息
命令行修改配置
除了在配置文件上修改Redis配置以外,redis还提供命令行修改配置的方式
Windows启动方式
redis文件目录下cmd
,使用redis-server
bash
E:\heima\Redis-x64-3.2.100>redis-server
[8828] 25 Jun 13:22:45.507 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.2.100 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 8828
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
[8828] 25 Jun 13:22:45.510 # Server started, Redis version 3.2.100
[8828] 25 Jun 13:22:45.511 * DB loaded from disk: 0.001 seconds
[8828] 25 Jun 13:22:45.511 * The server is now ready to accept connections on port 6379
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
不要关闭窗口,再使用一个窗口cmd
:redis-cli
bash
E:\heima\Redis-x64-3.2.100>redis-cli
127.0.0.1:6379>
1
2
2
这种方式是最简便的方式启动,全部使用默认配置,如果想要使用指定配置,在redis目录下的redis.windows.conf
修改配置,并且启动时加上配置文件名,如: redis-server redis.windows.conf
bash
E:\heima\Redis-x64-3.2.100>redis-server.exe redis.windows.conf
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.2.100 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 26408
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
[26408] 25 Jun 13:38:02.811 # Server started, Redis version 3.2.100
[26408] 25 Jun 13:38:02.813 * DB loaded from disk: 0.000 seconds
[26408] 25 Jun 13:38:02.813 * The server is now ready to accept connections on port 6379
[26408] 25 Jun 13:53:03.069 * 1 changes in 900 seconds. Saving...
[26408] 25 Jun 13:53:03.072 * Background saving started by pid 15812
[26408] 25 Jun 13:53:03.178 # fork operation complete
[26408] 25 Jun 13:53:03.179 * Background saving terminated with success
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
此时
bash
E:\heima\Redis-x64-3.2.100>redis-cli -h 127.0.0.1 -p 6379 -a 201819
127.0.0.1:6379> get name
"xiaoming"
1
2
3
2
3
redis-cli [option] [command]
其中 option 的选择有:
-h <hostName>
指定连接的主机IP地址,默认127.0.0.1
-p <port>
指定 Redis 服务器的端口号(默认是
6379
)。-a <password>
输入配置文件的密码,当设置密码后,不正确或者不输入时会出现
(error) NOAUTH Authentication required.
。例如
bashE:\heima\Redis-x64-3.2.100>redis-cli -a 201 127.0.0.1:6379> get name (error) NOAUTH Authentication required.
1
2
3-n <db>
指定要连接的数据库编号(默认是
0
)。进入redis后,可通过select [index]
的方式切换库
以上方式为连接Redis进入客户端的形式
如果使用redis [command]
则是向Redis发送指令,并不会进入客户端
例如:
bash
E:\heima\Redis-x64-3.2.100>redis-cli set pp 22
(error) NOAUTH Authentication required.
E:\heima\Redis-x64-3.2.100>redis-cli -a 201819 set name 16
OK
1
2
3
4
5
2
3
4
5
在发送命令的模式下,[option]
有以下几个选项:
-r <repeat>
指定命令重复执行的次数。
例子:
bashE:\heima\Redis-x64-3.2.100>redis-cli -a 201819 -r 15 set name 17 OK OK OK OK OK OK OK OK OK OK OK OK OK OK OK
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16-i <interval>
指定重复执行命令时的间隔时间(单位为秒)。
例如:
bashE:\heima\Redis-x64-3.2.100>redis-cli -a 201819 -r 15 -i 10 set name 17 OK OK//每隔10s运行一次,不等了,知道是这个意思就行
1
2
3