Skip to content

Commit

Permalink
database-redis: Support password authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Mar 11, 2017
1 parent d34f149 commit f83d868
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/database-redis.cpp
Expand Up @@ -53,6 +53,18 @@ Database_Redis::Database_Redis(Settings &conf)
redisFree(ctx);
throw DatabaseException(err);
}
if (conf.exists("redis_password")) {
tmp = conf.get("redis_password");
redisReply *reply = static_cast<redisReply *>(redisCommand(ctx, "AUTH %s", tmp.c_str()));
if (!reply)
throw DatabaseException("Redis authentication failed");
if (reply->type == REDIS_REPLY_ERROR) {
std::string err = "Redis authentication failed: " + std::string(reply->str, reply->len);
freeReplyObject(reply);
throw DatabaseException(err);
}
freeReplyObject(reply);
}
}

Database_Redis::~Database_Redis()
Expand Down

0 comments on commit f83d868

Please sign in to comment.