#ifndef REDIS_MANAGER_INCLUDE
#define REDIS_MANAGER_INCLUDE

#include <iostream>
#include <sstream>
#include <Poco/Logger.h>
#include "server_config.h"
#include "hiredis/hiredis.h"
#include <Poco/zlib.h>
#include "stdlib.h"

using namespace Poco;
using Poco::Logger;
using namespace std;

class RedisManage{
public:
	RedisManage();
	~RedisManage();
	static RedisManage* getInstance();
	bool get(const std::string &stCommand, std::string &stValue, redisContext *pContext, int *iduration=NULL);
	redisReply *mget(const std::string &stCommand, redisContext *pContext, int *iduration=NULL);
	bool set(const std::string &stCommand, redisContext *pContext, int *iduration=NULL);
	bool scan(const std::string &stCommand, const int iCount, redisContext *pContext, std::map<string,string> &stMapResult,const char* pMatch=NULL, int *iduration=NULL);
	redisContext* connect(const std::string &stIp, const unsigned int &port, const int &timeout);
	void getRedisContext(redisContext **pContext);
	void freeRedisContext(redisContext **pContext);
public:
	static RedisManage *_redisIns;
private:
	Logger &_logger;
	std::string _redisIp;
	std::string _redisAuth;
	int _redisNeedAuth;
	int _redisPort;
	int _redisTimeOut;
	int _connRetryTimes;
	ServerConfig *_pConf;
};

#endif
