From 9bbc4466ef886627f554e2e2db4a32562d1009f1 Mon Sep 17 00:00:00 2001 From: Christophe Le Roy Date: Sun, 9 Oct 2016 00:57:52 +0200 Subject: [PATCH] DBRedis: use HMGET in getBlocksOnZ Big performance increase on big maps. --- db-redis.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/db-redis.cpp b/db-redis.cpp index 053f704..dcc4695 100644 --- a/db-redis.cpp +++ b/db-redis.cpp @@ -169,22 +169,20 @@ void DBRedis::HMGET(const std::vector &positions, std::vector void DBRedis::getBlocksOnZ(std::map &blocks, int16_t zPos) { - redisReply *reply; - std::string tmp; - - for (std::vector::iterator it = posCache.begin(); it != posCache.end(); ++it) { + std::vector z_positions; + for (std::vector::const_iterator it = posCache.begin(); it != posCache.end(); ++it) { if (it->z != zPos) { continue; } - tmp = i64tos(encodeBlockPos(*it)); - reply = (redisReply*) redisCommand(ctx, "HGET %s %s", hash.c_str(), tmp.c_str()); - if(!reply) - throw std::runtime_error(std::string("redis command 'HGET %s %s' failed: ") + ctx->errstr); - if (reply->type == REDIS_REPLY_STRING && reply->len != 0) { - Block b(*it, ustring((const unsigned char *) reply->str, reply->len)); - blocks[b.first.x].push_back(b); - } else - throw std::runtime_error("Got wrong response to 'HGET %s %s' command"); - freeReplyObject(reply); + z_positions.push_back(*it); + } + std::vector z_blocks; + HMGET(z_positions, &z_blocks); + + std::vector::const_iterator z_block = z_blocks.begin(); + for (std::vector::const_iterator pos = z_positions.begin(); + pos != z_positions.end(); + ++pos, ++z_block) { + blocks[pos->x].push_back(Block(*pos, *z_block)); } }