caching - 用于 hget 和 hset 命令的 Redis 基准测试

标签 caching redis

我找不到使用 Redis 对 HGET 和 HSET(哈希表命令)进行基准测试的示例。任何示例或资源都会对此有所帮助。

最佳答案

我刚刚意识到 redis-benchmark 命令不会对 hSethGet 命令进行基准测试。 (我使用的是 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 hSet 花费的时间 = 557 毫秒(对于 10,000 个键) hSet(批量)花费的时间 = 51 毫秒(对于 10,000 个键) hGet 花费的时间 = 483 毫秒(对于 10,000 个键) hGet(批量)花费的时间 = 43ms(10,000 个键) hDel(批量)花费的时间 = 49 毫秒(10,000 个键)

关于caching - 用于 hget 和 hset 命令的 Redis 基准测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22822543/

相关文章:

javascript - 停止在 jQuery 中缓存图像

database - Redis:我可以为不同的键保存超过 1 个值吗?

redis - 是否可以为 redis 中的所有键设置默认 ttl?

angularjs - 在 Ionic 中完全删除缓存

java - Ehcache 多个 JVM - 开源?

json - Redis 获取 “\” 到 JSON 字符串

java - JedisCluster 在 2.7.x 中工作,但在 Jedis 2.9.x 中不工作,JedisConnectionException 和 Connection refused

apache-spark - Azure DataBricks Stream foreach 因 NotSerializableException 而失败

caching - Redis集群不支持多个master节点同时失效

caching - 在 StackExchange.Redis 中设置缓存时出现 TimeoutException