2019-03-20 22:29:02 +01:00
|
|
|
/*
|
|
|
|
* IXRedisClient.h
|
|
|
|
* Author: Benjamin Sergeant
|
|
|
|
* Copyright (c) 2019 Machine Zone, Inc. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <functional>
|
2019-05-30 17:46:50 +02:00
|
|
|
#include <memory>
|
2019-03-20 22:29:02 +01:00
|
|
|
|
|
|
|
namespace ix
|
|
|
|
{
|
|
|
|
class Socket;
|
|
|
|
|
2019-05-30 17:46:50 +02:00
|
|
|
class RedisClient
|
|
|
|
{
|
2019-03-20 22:29:02 +01:00
|
|
|
public:
|
2019-03-26 17:33:22 +01:00
|
|
|
using OnRedisSubscribeResponseCallback = std::function<void(const std::string&)>;
|
2019-03-20 22:29:02 +01:00
|
|
|
using OnRedisSubscribeCallback = std::function<void(const std::string&)>;
|
|
|
|
|
|
|
|
RedisClient() = default;
|
|
|
|
~RedisClient() = default;
|
|
|
|
|
2019-05-30 17:46:50 +02:00
|
|
|
bool connect(const std::string& hostname, int port);
|
2019-03-20 22:29:02 +01:00
|
|
|
|
2019-05-30 17:46:50 +02:00
|
|
|
bool auth(const std::string& password, std::string& response);
|
2019-03-26 17:33:22 +01:00
|
|
|
|
2019-05-30 17:46:50 +02:00
|
|
|
bool publish(const std::string& channel, const std::string& message, std::string& errMsg);
|
2019-03-20 22:29:02 +01:00
|
|
|
|
|
|
|
bool subscribe(const std::string& channel,
|
2019-03-26 17:33:22 +01:00
|
|
|
const OnRedisSubscribeResponseCallback& responseCallback,
|
2019-03-20 22:29:02 +01:00
|
|
|
const OnRedisSubscribeCallback& callback);
|
|
|
|
|
|
|
|
private:
|
2019-04-23 02:24:01 +02:00
|
|
|
std::string writeString(const std::string& str);
|
|
|
|
|
2019-03-20 22:29:02 +01:00
|
|
|
std::shared_ptr<Socket> _socket;
|
|
|
|
};
|
2019-05-30 17:46:50 +02:00
|
|
|
} // namespace ix
|