下载地址: http://redis.io/download
Github:https://github.com/dmajkic/redis/downloads
选择需要使用的版本
Redis简介: 是一个key-value存储系统,和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、 set(集合)和zset(有序集 合)。这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操作,而且这些操作都是原子性的。在此基础上,redis 支持各种不同方式的排序。与memcached一样,为了保证效率,数据都是缓存在内存中。区别的是redis会周期性的把更新的数据写入磁盘或者把修改 操作写入追加的记录文件,并且在此基础上实现了master-slave(主从)同步.
Redis安装文件解压后,有以下几个文件。见下图
redis-server.exe:服务程序
redis-check-dump.exe:本地数据库检查
redis-check-aof.exe:更新日志检查
redis-benchmark.exe:性能测试,用以模拟同时由N个客户端发送M个 SETs/GETs 查询 (类似于 Apache 的ab 工具).
将这些文件拷贝到安装你要安装redis的目录
我安装在 E:\wamp\redis目录下面
编辑redis.conf文件(配置略)
启动redis服务端
运行cmd命令
e:wamp/redis> redis-server.exe redis.conf
启动成功后如下
启动cmd窗口要一直开着,关闭后则Redis服务关闭。
这时服务开启着,另外开一个窗口进行,设置客户端:
输入命令:redis-cli.exe -h 127.0.0.1 -p 6379
输入后如下图所示:
然后可以开始玩了:
设置一个Key并获取返回的值:
redis 127.0.0.1:6379> set mykey somevalue
OK
redis 127.0.0.1:6379> get mykey
"somevalue"
如何添加值到list:
(integer) 1
redis 127.0.0.1:6379> lpush mylist val2
(integer) 2
redis 127.0.0.1:6379> lpush mylist val3
(integer) 3
redis 127.0.0.1:6379> lpush mylist val4
(integer) 4
redis 127.0.0.1:6379> lrange mylist 0 -1
1> val1
2> val2
3> val3
4> val4
redis 127.0.0.1:6379> rpop mylist
"val1"
redis-benchmark.exe:性能测试,用以模拟同时由N个客户端发送M个 SETs/GETs 查询 (类似于 Apache 的 ab 工具).
99.96% <= 11 milliseconds
99.96% <= 12 milliseconds
99.97% <= 13 milliseconds
99.97% <= 14 milliseconds
99.97% <= 15 milliseconds
99.98% <= 16 milliseconds
99.98% <= 17 milliseconds
99.98% <= 18 milliseconds
99.98% <= 19 milliseconds
99.98% <= 20 milliseconds
99.99% <= 21 milliseconds
99.99% <= 22 milliseconds
99.99% <= 23 milliseconds
99.99% <= 24 milliseconds
99.99% <= 25 milliseconds
99.99% <= 26 milliseconds
99.99% <= 27 milliseconds
99.99% <= 28 milliseconds
100.00% <= 29 milliseconds
100.00% <= 30 milliseconds
100.00% <= 31 milliseconds
100.00% <= 32 milliseconds
110497.24 requests per second
====== SPOP ======
100000 requests completed in 0.83 seconds
50 parallel clients
3 bytes payload
keep alive: 1
68.84% <= 1 milliseconds
99.61% <= 2 milliseconds
99.92% <= 3 milliseconds
99.95% <= 5 milliseconds
99.96% <= 6 milliseconds
99.96% <= 7 milliseconds
99.97% <= 8 milliseconds
99.97% <= 9 milliseconds
99.97% <= 10 milliseconds
99.97% <= 11 milliseconds
99.97% <= 12 milliseconds
99.97% <= 13 milliseconds
99.98% <= 14 milliseconds
99.98% <= 15 milliseconds
99.98% <= 16 milliseconds
99.98% <= 17 milliseconds
99.98% <= 18 milliseconds
99.98% <= 19 milliseconds
99.98% <= 20 milliseconds
99.99% <= 21 milliseconds
99.99% <= 23 milliseconds
99.99% <= 24 milliseconds
99.99% <= 25 milliseconds
99.99% <= 26 milliseconds
99.99% <= 27 milliseconds
100.00% <= 28 milliseconds
100.00% <= 29 milliseconds
100.00% <= 31 milliseconds
100.00% <= 32 milliseconds
100.00% <= 32 milliseconds
120336.95 requests per second
====== LPUSH (again, in order to bench LRANGE) ======
100000 requests completed in 0.88 seconds
50 parallel clients
3 bytes payload
keep alive: 1
65.95% <= 1 milliseconds
99.46% <= 2 milliseconds
99.79% <= 3 milliseconds
99.94% <= 4 milliseconds
99.95% <= 5 milliseconds
99.96% <= 6 milliseconds
99.96% <= 7 milliseconds
99.97% <= 8 milliseconds
99.97% <= 9 milliseconds
99.97% <= 10 milliseconds
99.97% <= 11 milliseconds
99.97% <= 12 milliseconds
99.97% <= 13 milliseconds
99.97% <= 14 milliseconds
99.98% <= 15 milliseconds
99.98% <= 16 milliseconds
99.98% <= 17 milliseconds
99.98% <= 18 milliseconds
99.98% <= 19 milliseconds
99.98% <= 20 milliseconds
99.99% <= 21 milliseconds
99.99% <= 22 milliseconds
99.99% <= 23 milliseconds
99.99% <= 24 milliseconds
99.99% <= 25 milliseconds
99.99% <= 26 milliseconds
99.99% <= 27 milliseconds
99.99% <= 28 milliseconds
100.00% <= 29 milliseconds
100.00% <= 30 milliseconds
100.00% <= 31 milliseconds
100.00% <= 32 milliseconds
113250.28 requests per second
====== LRANGE (first 100 elements) ======
100000 requests completed in 1.55 seconds
50 parallel clients
3 bytes payload
keep alive: 1
32.39% <= 1 milliseconds
98.90% <= 2 milliseconds
99.83% <= 3 milliseconds
99.96% <= 4 milliseconds
99.96% <= 5 milliseconds
99.96% <= 6 milliseconds
99.96% <= 7 milliseconds
99.96% <= 8 milliseconds
99.97% <= 9 milliseconds
99.97% <= 10 milliseconds
99.97% <= 11 milliseconds
99.97% <= 12 milliseconds
99.97% <= 13 milliseconds
99.97% <= 14 milliseconds
99.98% <= 15 milliseconds
99.98% <= 16 milliseconds
99.98% <= 17 milliseconds
99.98% <= 18 milliseconds
99.98% <= 19 milliseconds
99.98% <= 20 milliseconds
99.98% <= 21 milliseconds
99.99% <= 22 milliseconds
99.99% <= 23 milliseconds
99.99% <= 24 milliseconds
99.99% <= 25 milliseconds
99.99% <= 26 milliseconds
99.99% <= 27 milliseconds
99.99% <= 28 milliseconds
99.99% <= 29 milliseconds
99.99% <= 30 milliseconds
100.00% <= 31 milliseconds
100.00% <= 32 milliseconds
100.00% <= 33 milliseconds
100.00% <= 34 milliseconds
100.00% <= 34 milliseconds
64308.68 requests per second
====== LRANGE (first 300 elements) ======
100000 requests completed in 3.06 seconds
50 parallel clients
3 bytes payload
keep alive: 1
0.59% <= 1 milliseconds
63.75% <= 2 milliseconds
98.37% <= 3 milliseconds
99.57% <= 4 milliseconds
99.81% <= 5 milliseconds
99.92% <= 6 milliseconds
99.94% <= 7 milliseconds
99.95% <= 8 milliseconds
99.96% <= 9 milliseconds
99.96% <= 10 milliseconds
99.96% <= 11 milliseconds
99.97% <= 12 milliseconds
99.97% <= 13 milliseconds
99.97% <= 14 milliseconds
99.97% <= 16 milliseconds
99.98% <= 17 milliseconds
99.98% <= 18 milliseconds
99.98% <= 19 milliseconds
99.98% <= 20 milliseconds
99.98% <= 21 milliseconds
99.98% <= 22 milliseconds
99.98% <= 23 milliseconds
99.98% <= 24 milliseconds
99.99% <= 25 milliseconds
99.99% <= 26 milliseconds
99.99% <= 27 milliseconds
99.99% <= 29 milliseconds
99.99% <= 30 milliseconds
99.99% <= 31 milliseconds
99.99% <= 32 milliseconds
99.99% <= 33 milliseconds
99.99% <= 34 milliseconds
99.99% <= 36 milliseconds
100.00% <= 37 milliseconds
100.00% <= 38 milliseconds
100.00% <= 39 milliseconds
100.00% <= 40 milliseconds
100.00% <= 41 milliseconds
100.00% <= 42 milliseconds
32690.42 requests per second
====== LRANGE (first 450 elements) ======
100000 requests completed in 4.15 seconds
50 parallel clients
3 bytes payload
keep alive: 1
0.11% <= 1 milliseconds
23.15% <= 2 milliseconds
85.78% <= 3 milliseconds
99.29% <= 4 milliseconds
99.87% <= 5 milliseconds
99.92% <= 6 milliseconds
99.93% <= 7 milliseconds
99.94% <= 8 milliseconds
99.95% <= 9 milliseconds
99.95% <= 10 milliseconds
99.95% <= 11 milliseconds
99.95% <= 12 milliseconds
99.95% <= 13 milliseconds
99.96% <= 14 milliseconds
99.97% <= 15 milliseconds
99.97% <= 16 milliseconds
99.97% <= 17 milliseconds
99.98% <= 18 milliseconds
99.98% <= 20 milliseconds
99.98% <= 21 milliseconds
99.98% <= 22 milliseconds
99.98% <= 24 milliseconds
99.98% <= 25 milliseconds
99.98% <= 26 milliseconds
99.98% <= 27 milliseconds
99.98% <= 28 milliseconds
99.99% <= 29 milliseconds
99.99% <= 31 milliseconds
99.99% <= 32 milliseconds
99.99% <= 33 milliseconds
99.99% <= 34 milliseconds
99.99% <= 36 milliseconds
99.99% <= 37 milliseconds
99.99% <= 39 milliseconds
99.99% <= 40 milliseconds
99.99% <= 42 milliseconds
100.00% <= 44 milliseconds
100.00% <= 45 milliseconds
100.00% <= 47 milliseconds
100.00% <= 48 milliseconds
100.00% <= 49 milliseconds
100.00% <= 50 milliseconds
24096.38 requests per second
====== LRANGE (first 600 elements) ======
100000 requests completed in 5.20 seconds
50 parallel clients
3 bytes payload
keep alive: 1
0.11% <= 1 milliseconds
6.76% <= 2 milliseconds
64.66% <= 3 milliseconds
94.50% <= 4 milliseconds
99.59% <= 5 milliseconds
99.90% <= 6 milliseconds
99.94% <= 7 milliseconds
99.95% <= 8 milliseconds
99.95% <= 9 milliseconds
99.96% <= 10 milliseconds
99.96% <= 11 milliseconds
99.96% <= 12 milliseconds
99.97% <= 13 milliseconds
99.97% <= 14 milliseconds
99.97% <= 15 milliseconds
99.97% <= 16 milliseconds
99.97% <= 17 milliseconds
99.97% <= 18 milliseconds
99.97% <= 19 milliseconds
99.97% <= 21 milliseconds
99.97% <= 22 milliseconds
99.97% <= 23 milliseconds
99.98% <= 25 milliseconds
99.98% <= 26 milliseconds
99.98% <= 28 milliseconds
99.98% <= 29 milliseconds
99.98% <= 30 milliseconds
99.98% <= 31 milliseconds
99.98% <= 33 milliseconds
99.98% <= 34 milliseconds
99.99% <= 35 milliseconds
99.99% <= 37 milliseconds
99.99% <= 39 milliseconds
99.99% <= 41 milliseconds
99.99% <= 42 milliseconds
99.99% <= 44 milliseconds
99.99% <= 45 milliseconds
99.99% <= 47 milliseconds
99.99% <= 49 milliseconds
99.99% <= 51 milliseconds
100.00% <= 52 milliseconds
100.00% <= 54 milliseconds
100.00% <= 56 milliseconds
100.00% <= 58 milliseconds
100.00% <= 59 milliseconds
100.00% <= 60 milliseconds
19219.68 requests per second
e:\wamp\redis>
php 测试
$act = $_GET['action'];
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
if($act=='lpush'){
while(True){
try{
$value = 'value_'.date('Y-m-d H:i:s');
$redis->LPUSH('key1',$value);
sleep(rand()%3);
}catch(Exception $e){
echo $e->getMessage()."\n";
}
}
}elseif($act=='lpop'){
while(True){
try{
$val = $redis->LPOP('key1')."\n";
$fp = fopen('test.txt','a+');
if( $fp === FALSE){
echo("创建可写文件:test.txt失败");
exit();
}
if(!fwrite ($fp,$val)){ //将信息写入文件
echo ("尝试向文件".$fp."写入".$val."失败!");
fclose($fp);
exit();
}
fclose ($fp);
}catch(Exception $e){
echo $e->getMessage()."\n";
}
}
}
?>