Skip to content

Commit

Permalink
Fix RedisClient instantiation for authentication
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yamadapc committed Aug 19, 2014
1 parent 3e51af2 commit 2ba8b74
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions source/vibe/db/redis/redis.d
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ RedisClient connectRedis(string host, ushort port = 6379)
return new RedisClient(host, port);
}


/**
A redis client with connection pooling.
*/
Expand All @@ -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.
*/
Expand Down

0 comments on commit 2ba8b74

Please sign in to comment.