2014-04-26 15:01:35 +02:00
|
|
|
#ifndef DB_REDIS_HEADER
|
|
|
|
#define DB_REDIS_HEADER
|
|
|
|
|
|
|
|
#include "db.h"
|
2020-03-27 16:12:26 +01:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <utility>
|
2020-03-27 11:12:24 +01:00
|
|
|
#include <hiredis/hiredis.h>
|
2014-04-26 15:01:35 +02:00
|
|
|
|
|
|
|
class DBRedis : public DB {
|
|
|
|
public:
|
|
|
|
DBRedis(const std::string &mapdir);
|
2020-03-27 16:12:26 +01:00
|
|
|
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;
|
|
|
|
~DBRedis() override;
|
|
|
|
|
2014-04-26 15:01:35 +02:00
|
|
|
private:
|
2020-03-27 16:12:26 +01:00
|
|
|
using pos2d = std::pair<int16_t, int16_t>;
|
2016-10-09 00:27:31 +02:00
|
|
|
static std::string replyTypeStr(int type);
|
|
|
|
|
2014-04-26 15:01:35 +02:00
|
|
|
void loadPosCache();
|
2016-10-09 00:34:06 +02:00
|
|
|
void HMGET(const std::vector<BlockPos> &positions, std::vector<ustring> *result);
|
2014-04-26 15:01:35 +02:00
|
|
|
|
2020-03-27 16:12:26 +01: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;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DB_REDIS_HEADER
|