深刻理解Redis系列之單機Redis環境搭建

redis-white.png

序言


在實際開發項目過程當中, 若是說要用到緩存, 那麼第一個想到的必定是Redis, 可是爲何選Redis大多數人都不會去了解, 也不會去思考, 只知道它能當緩存使用, 比數據庫快一點, 恰巧我也是這樣的一我的;因此, 當我想寫一篇關於Redis介紹的時候, 我居然無從提及; 這也是對於Redis以及主流內存數據庫不熟的緣由; 不過, 在之後的日子裏, 必定增長本身對於框架的思考與深刻, 讓本身在後面的技術道路上有所沉澱, 但願之後有人讓我簡要介紹Redis的時候, 我不會無從提及;這或許就是我想寫Redis系列博客的目的所在吧!

1、Redis環境搭建

下載redis穩定版

curl -o redis.tar.gz http://download.redis.io/releases/redis-stable.tar.gz

解壓redis包

tar -zxvf redis-stable.tar.gz -C ./ // 該命令表示解壓tar.gz包到當前目錄

編譯安裝redis

進入到解壓的Redis的目錄下, 使用以下命令編譯安裝Redisredis

sudo make && make install PREFIX=/usr/local/redis

編輯配置Redis配置文件

sudo cp redis.conf /usr/local/redis/conf/

啓動Redis服務

./redis-server ../conf/redis.conf  & //啓動的時候後臺運行

啓動輸出日誌:數據庫

45894:C 02 Nov 2018 22:11:19.922 # Redis version=5.0.0, bits=64, commit=00000000, modified=0, pid=45894, just started
45894:C 02 Nov 2018 22:11:19.922 # Configuration loaded
45894:M 02 Nov 2018 22:11:19.924 * Increased maximum number of open files to 10032 (it was originally set to 256).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 5.0.0 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 45894
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

45894:M 02 Nov 2018 22:11:19.933 # Server initialized
45894:M 02 Nov 2018 22:11:19.933 * Ready to accept connections

驗證Redis服務

使用網絡工具telnet驗證緩存

terrydeMacBook-Air:bin terrylmay$ telnet 127.0.0.1 6379
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

使用系統進程ps 驗證網絡

terrydeMacBook-Air:bin terrylmay$ ps -ef | grep redis
  501 45894 44430   0 10:11下午 ttys000    0:00.04 ./redis-server 127.0.0.1:6379 //一個是Redis服務
  501 45897 44430   0 10:11下午 ttys000    0:00.00 grep redis //ps查詢進程本身

到這裏, 一個單機版的Redis服務就搭建完成了!框架

2、使用Redis存儲數據

Redis CLI鏈接Redis服務

terrydeMacBook-Air:bin terrylmay$ ./redis-cli
127.0.0.1:6379> 
127.0.0.1:6379> set name terrylmay
OK
127.0.0.1:6379> get name 
"terrylmay"
127.0.0.1:6379>

到此, 咱們可使用Redis系統來存儲數據字符串數據了.curl

相關文章
相關標籤/搜索