/** * @file include/di/Redis.h * @brief Redis wrapper class * @date May 29, 2015 * @author R.W.A. van der Heijden * @copyright 2015 Dual Inventive Technology Centre B.V. * * Class which wraps Redis interface */ #ifndef INCLUDE_DI_REDIS_H_ #define INCLUDE_DI_REDIS_H_ #include #include #include #include #include struct redisContext; typedef struct redisContext redisContext; struct redisReply; typedef struct redisReply redisReply; namespace Di { /** * @class Redis * * Redis wrapper class */ class Redis { public: enum Event { EV_OK, EV_ERROR, EV_TIMEOUT }; Redis(std::string hostname, int port); ~Redis(); bool connect(uint16_t timeout_sec); bool disconnect(); bool connected(void); bool ping(void); bool keys(const std::string filter, std::vector *values); bool hset(std::string field, const std::string key, const std::string value); bool hget(std::string field, const std::string &key, std::string *value); bool hmget(std::string field, const std::vector &requestedKeys, std::vector *values); bool hincrby(std::string field, const std::string key, int64_t increment); bool hdecrby(std::string field, const std::string key, int64_t decrement); bool set(std::string key, const std::string &value); bool setex(std::string key, const std::string value, unsigned int expireSec); bool get(std::string key, std::string *value); bool persist(std::string key); bool incrby(std::string key, int64_t increment); bool decrby(std::string key, int64_t decrement); bool publish(const std::string &chan, const std::string &msg); bool psubscribe(const std::string pattern); bool readEvent(std::string *event, std::string *data); enum Redis::Event readEvent(std::string *event, std::string *data, int timeout); void setKeyPrefix(const std::string &prefix); private: redisContext *ctx; std::string __hostname; int __port; std::string __keyPrefix; std::mutex __lock; redisReply *redisCommand(const char *format, ...); redisReply *__redisCommandArgv(size_t argc, const char **argv, const size_t *argvlen); int redisSelect(redisContext *c, int *readev, int timeout); }; } // namespace Di #endif // INCLUDE_DI_REDIS_H_