#include "main.h"
#include "settings.h"
#include "log.h"
+#include "filesys.h"
+
Database_Redis::Database_Redis(ServerMap *map, std::string savedir)
{
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());
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)));
}