Redis學習筆記一:redis簡介及安裝使用

     Redis 是開源,BSD許可,高級的key-value存儲系統,可以用來存儲字符串,哈希結構,鏈表,集合,因此,常用來提供數據結構服務,相對於memcached它具有以下特點:

☞ redis可以用來做存儲(storge)即redis的持久化”功能,而memccached是用來做緩存(cache) 

☞ 存儲的數據有”結構”,相對於memcached來說,存儲的數據,只有1種類型--”字符串”, 而redis則可以存儲字符串、鏈表、哈希結構、集合、有序集合。


一、 Redis下載安裝


官方網站:redis.io 

版本:Redis 3.2.1 is the latest stable version.

[root@centos ~] wget http://download.redis.io/releases/redis-3.2.1.tar.gz
[root@centos ~] tar xf redis-3.2.1.tar.gz
[root@centos ~] cd redis-3.2.1
[root@centos redis-3.2.1] make
[root@centos redis-3.2.1] make test
[root@centos redis-3.2.1] make PREFIX=/application/redis install
[root@centos redis-3.2.1] cp redis.conf /application/redis/

☞  Redis安裝時不需要configure,直接make編譯

☞  編譯成功後需執行make test檢測有沒有錯誤

☞  執行make install時可指定軟件安裝位置PREFIX,注意PREFIX需要大寫

☞  安裝完成需要拷貝redis配置文件至redis根目錄下


二、 Redis目錄文件介紹介紹


Redis安裝成功後,目錄結構非常簡潔,在bin目錄下共有以下文件:

redis-benchmark       性能測試工具

redis-check-aof         aof日誌文件檢測工具(比如斷電造成日誌損壞,可以檢測並修復)

redis-check-dump     rbd快照文件檢測工具,效果類上

redis-cli                     客戶端

redis-server              服務端


三、啓動Redis服務進程


Redis 服務進程的啓動需要指定redis的服務端路徑和配置文件路徑: 

[root@template redis]# ./bin/redis-server ./redis.conf
6367:M 18 Jul 15:51:44.117 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 3.2.1 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 6367
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

Redis默認是不以後臺進程的方式啓動的,因此啓動後,終端界面會被佔用,並且ctrl+c後redis會退出,要想讓redis以臺進程的形式運行,需修改配置文件的daemonize爲yes

[root@template redis]# vi redis.conf
################################# GENERAL #####################################

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes

四、 連接Redis


[root@centos ~]# /application/redis/bin/redis-cli [-p 6379]  # 若是多實例或者端口不是6379,需要加-p指定端口號
127.0.0.1:6379>

也可將Redis的安裝目錄加入環境變量,

echo PATH=$PATH:/application/redis/bin>> /etc/profile

source /etc/profile

發佈了26 篇原創文章 · 獲贊 20 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章