minetestmapper/include/db-redis.h

35 lines
933 B
C
Raw Normal View History

#pragma once
2014-04-26 15:01:35 +02:00
#include "db.h"
#include <unordered_map>
#include <utility>
#include <functional>
#include <hiredis/hiredis.h>
2014-04-26 15:01:35 +02:00
class DBRedis : public DB {
public:
DBRedis(const std::string &mapdir);
std::vector<BlockPos> getBlockPos(BlockPos min, BlockPos max) override;
void getBlocksOnXZ(BlockList &blocks, int16_t x, int16_t z,
int16_t min_y, int16_t max_y) override;
void getBlocksByPos(BlockList &blocks,
const std::vector<BlockPos> &positions) override;
~DBRedis() override;
bool preferRangeQueries() const override { return false; }
2014-04-26 15:01:35 +02:00
private:
using pos2d = std::pair<int16_t, int16_t>;
static const char *replyTypeStr(int type);
2014-04-26 15:01:35 +02:00
void loadPosCache();
void HMGET(const std::vector<BlockPos> &positions,
std::function<void(std::size_t, ustring)> result);
2014-04-26 15:01:35 +02:00
// indexed by Z, contains all (x,y) position pairs
std::unordered_map<int16_t, std::vector<pos2d>> posCache;
2014-04-26 15:01:35 +02:00
redisContext *ctx;
std::string hash;
};