下载:
http://redis.io/download
解压安装:
cd redis-3.0.1
make
make install
或者
make
cd src
cp redis-benchmark redis-check-aof redis-check-dump redis-cli redis-sentinel redis-server /usr/redis/bin
配置好参数文件,启动:
redis-server /etc/redis6379.cnf
查看是否正常启动
ps -ef | grep redis
登陆测试
[iyunv@localhost ~]# redis-cli
127.0.0.1:6379>
127.0.0.1:6379> set test hello
OK
127.0.0.1:6379> get test
"hello"
127.0.0.1:6379>
关闭:
redis-cli -h 127.0.0.1 -p 6379 shutdown
或者
直接kill掉
pkill redis-server
常用操作:
select N 选择使用的库,默认是0库
auth xxxxx 密码认证,在配置文件中 可以登陆的时候使用 -a xxxx
dbsize 返回库里面的键的个数
info 显示服务器相关信息
info CPU 显示CPU段的信息
config get logfile 获取服务器logfile参数的配置
flushdb 删除当前库中的所有键/表。
flushall 删除所有数据库中的所有键/表
keys * 查询所有键值
exists xxx 判断是否存在
del xxx 删除指定的键
expire a 10 设置键a过期时间
persist a 取消a的过期时间
ttl a 查询过期时间
move a 5 把a移动到数据库5
get a 获得a的值
randomkey 获取一个随机的key
rename a c 重命名a为c
type a 返回a的类型
ping 测试redis连接是否存活
redis-benchmark测试:
redis-benchmark --help
Usage: redis-benchmark [-h ] [-p ] [-c ] [-n [-k ]
-h Server hostname (default 127.0.0.1)
-p Server port (default 6379)
-s Server socket (overrides host and port)
-a Password for Redis Auth
-c Number of parallel connections (default 50)
-n Total number of requests (default 100000)
-d Data>
-dbnum SELECT the specified db number (default 0)
-k 1=keep alive 0=reconnect (default 1)
-r 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 Pipeline requests. Default 1 (no pipeline).
-q Quiet. Just show query/sec values
--csv Output in CSV format
-l Loop. Run the tests forever
-t Only run the comma separated list of tests. The test
names are the same as the ones produced as output.
-I > Examples:
Run the benchmark with the default configuration against 127.0.0.1:6379:
$ redis-benchmark
Use 20 parallel clients, for a total of 100k requests, against 192.168.1.1:
$ redis-benchmark -h 192.168.1.1 -p 6379 -n 100000 -c 20
Fill 127.0.0.1:6379 with about 1 million keys only using the SET test:
$ redis-benchmark -t set -n 1000000 -r 100000000
Benchmark 127.0.0.1:6379 for a few commands producing CSV output:
$ redis-benchmark -t ping,set,get -n 100000 --csv
Benchmark a specific command line:
$ redis-benchmark -r 10000 -n 10000 eval 'return redis.call("ping")' 0
Fill a list with 10000 random elements:
$ redis-benchmark -r 10000 -n 10000 lpush mylist __rand_int__
On user specified command lines __rand_int__ is replaced with a random integer
with a range of values selected by the -r option.
测试:
redis-benchmark -h 127.0.0.1 -p 6379 -c 1000 -n 100000
1000个并发连接,100000个请求,检测host为127.0.0.1 端口为6379的redis服务器性能