前言
筆者在上一個月寫好爲什麼你學了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