]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/database-redis.cpp
Replace std::list by std::vector into ServerMap::listAllLoadableBlocks ServerMap...
[dragonfireclient.git] / src / database-redis.cpp
index b9e75ededd957d8452a946cab59fddfc7530aaac..0962e97baa23553ad78de88da3c63673171fc433 100644 (file)
@@ -35,6 +35,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "main.h"
 #include "settings.h"
 #include "log.h"
+#include "filesys.h"
+
 
 Database_Redis::Database_Redis(ServerMap *map, std::string savedir)
 {
@@ -121,7 +123,31 @@ std::string Database_Redis::loadBlock(v3s16 blockpos)
        return str;
 }
 
-void Database_Redis::listAllLoadableBlocks(std::list<v3s16> &dst)
+bool Database_Redis::deleteBlock(v3s16 blockpos)
+{
+       std::string tmp = i64tos(getBlockAsInteger(blockpos));
+
+       redisReply *reply = (redisReply *)redisCommand(ctx, "HDEL %s %s",
+               hash.c_str(), tmp.c_str());
+       if (!reply) {
+               errorstream << "WARNING: deleteBlock: redis command 'HDEL' failed on "
+                       "block " << PP(blockpos) << ": " << ctx->errstr << std::endl;
+               freeReplyObject(reply);
+               return false;
+       }
+
+       if (reply->type == REDIS_REPLY_ERROR) {
+               errorstream << "WARNING: deleteBlock: deleting block " << PP(blockpos)
+                       << "failed" << std::endl;
+               freeReplyObject(reply);
+               return false;
+       }
+
+       freeReplyObject(reply);
+       return true;
+}
+
+void Database_Redis::listAllLoadableBlocks(std::vector<v3s16> &dst)
 {
        redisReply *reply;
        reply = (redisReply*) redisCommand(ctx, "HKEYS %s", hash.c_str());
@@ -129,8 +155,7 @@ void Database_Redis::listAllLoadableBlocks(std::list<v3s16> &dst)
                throw FileNotGoodException(std::string("redis command 'HKEYS %s' failed: ") + ctx->errstr);
        if(reply->type != REDIS_REPLY_ARRAY)
                throw FileNotGoodException("Failed to get keys from database");
-       for(size_t i = 0; i < reply->elements; i++)
-       {
+       for(size_t i = 0; i < reply->elements; i++) {
                assert(reply->element[i]->type == REDIS_REPLY_STRING);
                dst.push_back(getIntegerAsBlock(stoi64(reply->element[i]->str)));
        }