From 2ba8b74f867bdbaf6309ee73a855a8c256f17dbc Mon Sep 17 00:00:00 2001 From: yamadapc Date: Tue, 19 Aug 2014 14:01:05 -0300 Subject: [PATCH] Fix `RedisClient` instantiation for authentication This removes the "INFO" command from the default `RedisClient` constructor, since its only there to support the `redisVersion` getter. This fixes creating clients for databases that require authentication for all commands. It moves the version fetching logic into the `redisVersion` getter, and caches its result in the `m_version` property. I think this is the cleanest solution to this issue. --- source/vibe/db/redis/redis.d | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/source/vibe/db/redis/redis.d b/source/vibe/db/redis/redis.d index 63a0a69b41..c86d277e51 100644 --- a/source/vibe/db/redis/redis.d +++ b/source/vibe/db/redis/redis.d @@ -30,7 +30,6 @@ RedisClient connectRedis(string host, ushort port = 6379) return new RedisClient(host, port); } - /** A redis client with connection pooling. */ @@ -47,23 +46,29 @@ final class RedisClient { m_connections = new ConnectionPool!RedisConnection({ return new RedisConnection(host, port); }); + } - import std.string; - auto info = info(); - auto lines = info.splitLines(); - if (lines.length > 1) { - foreach (string line; lines) { - auto lineParams = line.split(":"); - if (lineParams.length > 1 && lineParams[0] == "redis_version") { - m_version = lineParams[1]; - break; + /// Returns Redis version + @property string redisVersion() + { + if(!m_version) + { + import std.string; + auto info = info(); + auto lines = info.splitLines(); + if (lines.length > 1) { + foreach (string line; lines) { + auto lineParams = line.split(":"); + if (lineParams.length > 1 && lineParams[0] == "redis_version") { + m_version = lineParams[1]; + break; + } } } - } - } + } - /// Returns Redis version - @property string redisVersion() { return m_version; } + return m_version; + } /** Returns a handle to the given database. */