redis 安裝和使用

環境:centos6.5  

安裝gcc、gcc-c++編譯的環境

1、下載Redis

wget http://download.redis.io/releases/redis-2.8.3.tar.gz

2、解壓

tar xf redis-2.8.3.tar.gz -C /usr/src/

cd /usr/src/redis-2.8.3/

3、安裝Redis之前測試一下make test(執行make test必須先安裝tcl語言包)

wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz

tar xf tcl8.6.1-src.tar.gz

cd tcl8.6.1/unix/

./configure && make && make install

這個時候在命令行就可以輸入tclsh進入tcl解釋器 tcl就可以使用了。

4、安裝

[root@moban src]# make PREFIX=/usr/local/redis install

[root@moban src]# cd /usr/local/redis/

[root@moban redis]# ls

bin

[root@moban redis]# cd bin/

[root@moban bin]# ls

redis-benchmark  redis-check-aof  redis-check-dump  redis-cli  redis-server

[root@moban bin]# cp /usr/src/redis-2.8.3/redis.conf /usr/local/redis

[root@localhost redis]# ls

bin  redis.conf 到這裏redis已經安裝成功了

5、啓動Redis

方法一:進入 安裝路徑下的bin下

[root@localhost redis]# cd bin

[root@localhost bin]# ./redis-server redis.conf

[23753] 13 Nov 00:43:50.340 * Max number of open files set to 10032

                _._                                                  

           _.-``__ ''-._                                             

      _.-``    `.  `_.  ''-._           Redis 2.8.3 (00000000/0) 64 bit

  .-`` .-```.  ```\/    _.,_ ''-._                                   

 (    '      ,       .-`  | `,    )     Running in stand alone mode

 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379

 |    `-._   `._    /     _.-'    |     PID: 23753

  `-._    `-._  `-./  _.-'    _.-'                                   

 |`-._`-._    `-.__.-'    _.-'_.-'|                                  

 |    `-._`-._        _.-'_.-'    |           http://redis.io        

  `-._    `-._`-.__.-'_.-'    _.-'                                   

 |`-._`-._    `-.__.-'    _.-'_.-'|                                  

 |    `-._`-._        _.-'_.-'    |                                  

  `-._    `-._`-.__.-'_.-'    _.-'                                   

      `-._    `-.__.-'    _.-'                                       

          `-._        _.-'                                           

              `-.__.-'                                               


[23753] 13 Nov 00:43:50.342 # Server started, Redis version 2.8.3

[23753] 13 Nov 00:43:50.342 * DB loaded from disk: 0.000 seconds

[23753] 13 Nov 00:43:50.342 * The server is now ready to accept connections on port 6379

這樣其實已經啓動成功了,但是這屬於前端啓動,啓動redis之後,我們的控制檯就不能進行任何操作了。只能ctrl+c停止啓動。

方法二:後臺啓動

編輯redis.conf文件  daemonize no 改爲yes保存退出

再次啓動

[root@localhost bin]# ./redis-server redis.conf

查看啓動成功沒有:

netstat -anptl |grep redis

[root@moban redis]# netstat -antp|grep redis

tcp        0      0 0.0.0.0:6379                0.0.0.0:*                   LISTEN      23767/./bin/redis-s 

tcp        0      0 :::6379                     :::*                        LISTEN      23767/./bin/redis-s

6、關閉redis

[root@localhost redis]# ./bin/redis-cli shutdown

7、簡單的使用

//連接客戶端

[root@moban redis]# ./bin/redis-cli 

127.0.0.1:6379>

//檢查網絡是否通

127.0.0.1:6379> ping

PONG

//設置一個鍵值對

127.0.0.1:6379> set name cheny

OK

//獲取剛剛設置的鍵值對

127.0.0.1:6379> get name

"cheny"

//查看所有的鍵

127.0.0.1:6379> keys *

1) "name"

//刪除name這個鍵

127.0.0.1:6379> del name

(integer)

1127.0.0.1:6379> keys * (empty list or set)

127.0.0.1:6379>

到這裏簡單的redis安裝就好了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章