Skip to content

Commit

Permalink
Provide a convenience string overload for connectRedisDB
Browse files Browse the repository at this point in the history
  • Loading branch information
wilzbach committed Apr 2, 2018
1 parent e3a0d3a commit c08ba1f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions redis/vibe/db/redis/redis.d
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import std.utf;
*/
RedisClient connectRedis(string host, ushort port = RedisClient.defaultPort)
{
enforce(!host.startsWith("redis://", "Host must be a valid IP or domain, but not an URI."));
return new RedisClient(host, port);
}

Expand All @@ -48,6 +49,17 @@ RedisDatabase connectRedisDB(URL url)
return cli.getDatabase(url.localURI[1 .. $].to!long);
}

/// ditto
RedisDatabase connectRedisDB(string host_or_url)
{
/* If this looks like a URL try to parse it that way. */
if(host_or_url.startsWith("redis://")){
return connectRedisDB(URL(host_or_url));
} else {
return connectRedis(host_or_url).getDatabase(0);
}
}

/**
A redis client with connection pooling.
*/
Expand Down

0 comments on commit c08ba1f

Please sign in to comment.