database-redis: Support password authentication
authorsfan5 <sfan5@live.de>
Sat, 11 Mar 2017 20:39:32 +0000 (21:39 +0100)
committersfan5 <sfan5@live.de>
Sat, 11 Mar 2017 20:39:32 +0000 (21:39 +0100)
src/database-redis.cpp

index 3df186944ea1697b974e492f057ccc237d345da6..93e6717fa7e5ee4f67dca84bb7e7663936d8307e 100644 (file)
@@ -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()