前言
笔者在上一个月写好为什么你学了N遍Springboot,至今还是学生项目?后,一直有粉丝催更中间件,原想写两篇redis
、rabbitmq
。但考虑以后还是决定给redis
专门写个专题。笔者认为,redis
在中间件
中的地位好比spring
在java
中的地位。
如果
redis
只是作为key-value
缓存,那无异于瑞士军刀
开瓶盖
通过本专题你将系统的学习到redis的各项数据结构
、特性
、高可用及原理
、集群及原理
、redis在Java设计实战
中的应用(如redis分布式锁
)。废话不多说,直接先用起来,这里笔者用的是Ubuntu
安装
# 安装wget
brew install wget
# 下载redis
wget http://download.redis.io/redis-stable.tar.gz
# 进入目录
cd redis-stable
# 编译
make
# 安装
make install
# 测试安装
test install
# 启动
redis-server
# 启动成功
10745:C 27 Feb 2020 21:10:24.554 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
10745:M 27 Feb 2020 21:10:24.555 * Increased maximum number of open files to 10032 (it was originally set to 256).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 5.0.7 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 10745
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
10745:M 27 Feb 2020 21:10:24.556 # Server initialized
10745:M 27 Feb 2020 21:10:24.557 * Ready to accept connections
启动连接Redis
服务端启动
# 直接启动
redis-server
# 动态参数启动
redis-server --port 6380
# 配置文件启动
redis-server redis.conf
客户端连接
# 连接 -h 地址 -p 端口
redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> set hello world
OK
127.0.0.1:6379> get hello
"world"
127.0.0.1:6379> shutdown
not connected> exit