]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/database-redis.cpp
Conf.example: Update using auto-generation
[dragonfireclient.git] / src / database-redis.cpp
index 3bcedad9bfdaddc71b50e753570164b2ab66d5b4..096ea504db12c82d08094cd2ab9591c8ccfd2629 100644 (file)
@@ -38,13 +38,14 @@ Database_Redis::Database_Redis(Settings &conf)
        try {
                tmp = conf.get("redis_address");
                hash = conf.get("redis_hash");
-       } catch (SettingNotFoundException) {
+       } catch (SettingNotFoundException &) {
                throw SettingNotFoundException("Set redis_address and "
                        "redis_hash in world.mt to use the redis backend");
        }
        const char *addr = tmp.c_str();
        int port = conf.exists("redis_port") ? conf.getU16("redis_port") : 6379;
-       ctx = redisConnect(addr, port);
+       // if redis_address contains '/' assume unix socket, else hostname/ip
+       ctx = tmp.find('/') != std::string::npos ? redisConnectUnix(addr) : redisConnect(addr, port);
        if (!ctx) {
                throw DatabaseException("Cannot allocate redis context");
        } else if (ctx->err) {
@@ -52,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()