Skip to content

Commit f83d868

Browse files
committedMar 11, 2017
database-redis: Support password authentication
1 parent d34f149 commit f83d868

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
 

‎src/database-redis.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ Database_Redis::Database_Redis(Settings &conf)
5353
redisFree(ctx);
5454
throw DatabaseException(err);
5555
}
56+
if (conf.exists("redis_password")) {
57+
tmp = conf.get("redis_password");
58+
redisReply *reply = static_cast<redisReply *>(redisCommand(ctx, "AUTH %s", tmp.c_str()));
59+
if (!reply)
60+
throw DatabaseException("Redis authentication failed");
61+
if (reply->type == REDIS_REPLY_ERROR) {
62+
std::string err = "Redis authentication failed: " + std::string(reply->str, reply->len);
63+
freeReplyObject(reply);
64+
throw DatabaseException(err);
65+
}
66+
freeReplyObject(reply);
67+
}
5668
}
5769

5870
Database_Redis::~Database_Redis()

0 commit comments

Comments
 (0)
Please sign in to comment.