我无法找到替补HGET,HSET(哈希表命令)用Redis的标记的例子。 任何实例或资源将对此有用。
Answer 1:
我只是意识到redis-benchmark
命令不基准hSet
和hGet
命令。 (我使用v2.8.5)
你可以做的是写一个小程序,以基准性能:
<?php
$redis = new Redis();
$redis->pconnect("127.0.0.1");
$count = 10000;
$start_t = microtime(true);
for ($i = 1; $i < $count; $i++) {
$redis->hSet("h{$i}", 'f', $i);
}
$end_t = microtime(true);
echo "Time taken for hSet = " . round(1000 * ($end_t - $start_t)) . "ms (for " . number_format($count) . " keys)\n";
$start_t = microtime(true);
$pipeline1 = $redis->pipeline();
for ($i = 1; $i < $count; $i++) {
$pipeline1->hSet("h{$i}", 'f', $i);
}
$result2 = $pipeline1->exec();
$end_t = microtime(true);
echo "Time taken for hSet (bulk) = " . round(1000 * ($end_t - $start_t)) . "ms (for " . number_format($count) . " keys)\n";
$start_t = microtime(true);
for ($i = 1; $i < $count; $i++) {
$redis->hGet("h{$i}", 'f');
}
$end_t = microtime(true);
echo "Time taken for hGet = " . round(1000 * ($end_t - $start_t)) . "ms (for " . number_format($count) . " keys)\n";
$start_t = microtime(true);
$pipeline2 = $redis->pipeline();
for ($i = 1; $i < $count; $i++) {
$pipeline2->hGet("h{$i}", 'f');
}
$result2 = $pipeline2->exec();
$end_t = microtime(true);
echo "Time taken for hGet (bulk) = " . round(1000 * ($end_t - $start_t)) . "ms (for " . number_format($count) . " keys)\n";
$start_t = microtime(true);
$pipeline3 = $redis->pipeline();
for ($i = 1; $i < $count; $i++) {
$pipeline3->hDel("h{$i}", 'f');
}
$result3 = $pipeline3->exec();
$end_t = microtime(true);
echo "Time taken for hDel (bulk) = " . round(1000 * ($end_t - $start_t)) . "ms (for " . number_format($count) . " keys)\n";
在我的测试服务器,结果如下:
$ php redis/benchmark_redis.php Time taken for hSet = 557ms (for 10,000 keys) Time taken for hSet (bulk) = 51ms (for 10,000 keys) Time taken for hGet = 483ms (for 10,000 keys) Time taken for hGet (bulk) = 43ms (for 10,000 keys) Time taken for hDel (bulk) = 49ms (for 10,000 keys)
Answer 2:
我使用3.0.2,下面的命令可以基准HSET redisredis-benchmark -h 192.168.22.58 -p 6379 -d 100 -c 10 -n 1000000 hset myhash rand_int rand_string
文章来源: Redis benchmarking for hget and hset commands