redis及服務安裝部署

redis安裝包: 鏈接:https://pan.baidu.com/s/1zFmJhduaw9umB2ECp9xVaA 提取碼:5d6z

前言

redis是一個key-value存儲系統,它支持存儲的value類型相對更多,包括string(字符串)、list(鏈表)、set(集合)、zset(sorted set --有序集合)和hash(哈希類型)。redis支持各種不同方式的排序,與memcached一樣,爲了保證效率,數據都是緩存在內存中。區別的是redis會週期性的把更新的數據寫入磁盤或者把修改操作寫入追加的記錄文件,並且可以實現主從同步。

實驗過程

1、安裝環境包

[root@redis ~]# yum install gcc gcc-c++ make -y

2、編譯安裝

[root@redis redis]# tar zxvf redis-5.0.7.tar.gz -C /opt
[root@redis redis]# cd /opt/redis-5.0.7/
#因爲配置腳本被封裝化了,此處直接執行make
[root@redis redis-5.0.7]# make
#make install指定命令文件目錄
[root@redis redis-5.0.7]# make PREFIX=/usr/local/redis/ install

3、配置redis

[root@redis ~]# cd /opt/redis-5.0.7/utils/
[root@redis utils]# ./install_server.sh
#默認端口6379
Please select the redis port for this instance: [6379] 
Selecting default: 6379
#配置文件存放目錄
Please select the redis config file name [/etc/redis/6379.conf] 
Selected default - /etc/redis/6379.conf
#日誌文件存放目錄
Please select the redis log file name [/var/log/redis_6379.log] 
Selected default - /var/log/redis_6379.log
#數據文件存放目錄
Please select the data directory for this instance [/var/lib/redis/6379] 
Selected default - /var/lib/redis/6379
#拓展文件路徑,自定義路徑
Please select the redis executable path [] /usr/local/redis/bin/redis-server

4、命令文件創建軟連接,是系統能夠識別

[root@redis ~]# ln -s /usr/local/redis/bin/* /usr/local/bin/

5、更改監聽端口

[root@redis ~]# vim /etc/redis/6379.conf
bind 127.0.0.1 192.168.7.128
[root@redis ~]# /etc/init.d/redis_6379 restart

6、登陸數據庫

#本地直接登陸
[root@redis ~]# redis-cli
127.0.0.1:6379> 
#使用本地IP地址登陸
[root@redis ~]# redis-cli -h 192.168.7.128 -p 6379	//-h:指定IP地址;-p:指定端口號
192.168.7.128:6379> 

7、常用redis語句
redis語句相對比較友好,輸入命令會自動提示且可以使用Tab鍵補全命令

[root@redis ~]# redis-cli -h 192.168.7.128 -p 6379
#獲取列表幫助信息
192.168.7.128:6379> help @list
#創建
192.168.7.128:6379> set people zhangsan
OK
192.168.7.128:6379> set tea red
OK
#查看所有的鍵
192.168.7.128:6379> keys *
1) "tea"
2) "people"
#可使用特殊符號查詢
192.168.7.128:6379> keys t??
1) "tea"
#查看鍵對應的值
192.168.7.128:6379> get people
"zhangsan"
#查看鍵的狀態,輸出爲1表示存在,0表示不存在
192.168.7.128:6379> exists tea
(integer) 1
192.168.7.128:6379> exists teas
(integer) 0
#刪除
192.168.7.128:6379> del tea
(integer) 1
192.168.7.128:6379> keys *
1) "people"
#查看鍵的類型
192.168.7.128:6379> type people
string
#重命名
192.168.7.128:6379> rename people test01
OK
192.168.7.128:6379> keys *
1) "test01"
192.168.7.128:6379> get test01
"zhangsan"
#移動數據到指定的庫
192.168.7.128:6379> move test01 10
(integer) 1
#進入庫10
192.168.7.128:6379> select 10
OK
192.168.7.128:6379[10]> keys *
1) "test01"
192.168.7.128:6379[10]> get test01
"zhangsan"
#清除(慎用flushall,會清除所有的庫的數據)
192.168.7.128:6379[10]> flushdb
OK
192.168.7.128:6379[10]> keys *
(empty list or set)

8、壓測
(1)發送100個併發與100000個請求測試性能

[root@redis ~]# redis-benchmark -h 192.168.7.128 -p 6379 -c 100 -n 100000	//-c:指定併發連接數;-n:指定請求數
#查看讀取的時間
====== SET ======
  100000 requests completed in 0.80 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

98.01% <= 1 milliseconds
99.71% <= 2 milliseconds
99.75% <= 6 milliseconds
99.80% <= 11 milliseconds
99.85% <= 14 milliseconds
99.95% <= 17 milliseconds
100.00% <= 17 milliseconds
125313.29 requests per second

====== GET ======
  100000 requests completed in 0.76 seconds
  100 parallel clients
  3 bytes payload
  keep alive: 1

97.85% <= 1 milliseconds
99.82% <= 2 milliseconds
99.96% <= 3 milliseconds
100.00% <= 3 milliseconds
132275.14 requests per second

(2)測試存取大小爲100字節的數據包的性能

[root@redis ~]# redis-benchmark -h 192.168.7.128 -p 6379 -q -d 100	//-q:強制退出;-d:指定字節大小
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章