redis安裝及效能測試
Redis是一個開源的使用ANSI C語言編寫、遵守BSD協議、支援網路、可基於記憶體亦可持久化的日誌型、Key-Value資料庫。通常被稱為資料結構伺服器,因為值(value)可以是 字串(String), 雜湊(Hash), 列表(list), 集合(sets) 和 有序集合(sorted sets)等型別。
Linux安裝
1、選擇下載資源的檔案目錄(如:/opt),獲取redis資源
wget http://download.redis.io/releases/redis-4.0.8.tar.gz
2、解壓
tar xzvf redis-4.0.8.tar.gz
3、安裝
cdredis-2.8.17
make
cd src
make install PREFIX=/usr/local/redis (該處遇到失敗時,查詢了You need tcl 8.5 or newer in order to run the Redis test)
解決方案:
安裝tcl-8.5.13-8.el7.x86_64.rpm
1>wgethttp://mirror.centos.org/centos/7/os/x86_64/Packages/tcl-8.5.13-8.el7.x86_64.rpm
2>rpm -ivhtcl-8.5.13-8.el7.x86_64.rpm
4.移動配置檔案到安裝目錄下
cd ../
mkdir /usr/local/redis/etc
mv redis.conf /usr/local/redis/etc
5.配置redis為後臺啟動
vi /usr/local/redis/etc/redis.conf //將daemonize no改成daemonize yes
6.將redis加入到開機啟動
vi /etc/rc.local //在裡面新增內容:/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf (意思就是開機呼叫這段開啟redis的命令)
7.開啟redis
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
常用命令
redis-server /usr/local/redis/etc/redis.conf //啟動redis
pkill redis //停止redis
解除安裝redis:
rm -rf /usr/local/redis //刪除安裝目錄
rm -rf /usr/bin/redis-* //刪除所有redis相關命令指令碼
rm -rf /root/download/redis-4.0.4 //刪除redis解壓資料夾
redis效能測試
Redis 自帶了一個叫redis-benchmark
的工具來模擬 N 個客戶端同時發出 M 個請求。 (類似於 Apache ab 程式)。你可以使用 redis-benchmark -h 來檢視基準引數
以下引數被支援: Usage: redis-benchmark [-h <host>] [-p <port>] [-c <clients>] [-n <requests]> [-k <boolean>] -h <hostname> Server hostname (default 127.0.0.1) -p <port> Server port (default 6379) -s <socket> Server socket (overrides host and port) -a <password> Password for Redis Auth -c <clients> Number of parallel connections (default 50) -n <requests> Total number of requests (default 100000) -d <size> Data size of SET/GET value in bytes (default 2) -dbnum <db> SELECT the specified db number (default 0) -k <boolean> 1=keep alive 0=reconnect (default 1) -r <keyspacelen> Use random keys for SET/GET/INCR, random values for SADD Using this option the benchmark will expand the string __rand_int__ inside an argument with a 12 digits number in the specified range from 0 to keyspacelen-1. The substitution changes every time a command is executed. Default tests use this to hit random keys in the specified range. -P <numreq> Pipeline <numreq> requests. Default 1 (no pipeline). -q Quiet. Just show query/sec values --csv Output in CSV format -l Loop. Run the tests forever -t <tests> Only run the comma separated list of tests. The test names are the same as the ones produced as output. -I Idle mode. Just open N idle connections and wait.
參考部落格1:https://www.cnblogs.com/lauhp/p/8487029.html
參考部落格2:https://blog.csdn.net/zhangchaoyang/article/details/104456978