Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ set(CMAKE_CXX_STANDARD 11)
# Build options
option(ADDRESS_SANITIZER "Enable address sanitizer" OFF)
option(BENCHMARK "Build benmarks" OFF)
option(BUILD_SHARED_LIBS "Whether to build shared libraries" ON)
option(BUILD_TEST "Whether to build the unit tests" ON)
option(BUILD_SHARED_LIBS "Whether to build shared libraries" OFF)
option(BUILD_TEST "Whether to build the unit tests" OFF)
option(BUILD_EXAMPLES "Whether to build the examples" ON)
option(HEADER_ONLY "Whether to build in header-only mode" OFF)
option(HEADER_ONLY "Whether to build in header-only mode" ON)

# Default to Release mode
if (NOT CMAKE_BUILD_TYPE)
Expand Down
8 changes: 4 additions & 4 deletions src/redisclient/impl/redisasyncclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void RedisAsyncClient::command(const std::string &cmd, std::deque<RedisBuffer> a

RedisAsyncClient::Handle RedisAsyncClient::subscribe(
const std::string &channel,
std::function<void(std::vector<char> msg)> msgHandler,
RedisClientImpl::MsgHandler msgHandler,
std::function<void(RedisValue)> handler)
{
auto handleId = pimpl->subscribe("subscribe", channel, msgHandler, handler);
Expand All @@ -112,7 +112,7 @@ RedisAsyncClient::Handle RedisAsyncClient::subscribe(

RedisAsyncClient::Handle RedisAsyncClient::psubscribe(
const std::string &pattern,
std::function<void(std::vector<char> msg)> msgHandler,
RedisClientImpl::MsgHandler msgHandler,
std::function<void(RedisValue)> handler)
{
auto handleId = pimpl->subscribe("psubscribe", pattern, msgHandler, handler);
Expand All @@ -130,14 +130,14 @@ void RedisAsyncClient::punsubscribe(const Handle &handle)
}

void RedisAsyncClient::singleShotSubscribe(const std::string &channel,
std::function<void(std::vector<char> msg)> msgHandler,
RedisClientImpl::MsgHandler msgHandler,
std::function<void(RedisValue)> handler)
{
pimpl->singleShotSubscribe("subscribe", channel, msgHandler, handler);
}

void RedisAsyncClient::singleShotPSubscribe(const std::string &pattern,
std::function<void(std::vector<char> msg)> msgHandler,
RedisClientImpl::MsgHandler msgHandler,
std::function<void(RedisValue)> handler)
{
pimpl->singleShotSubscribe("psubscribe", pattern, msgHandler, handler);
Expand Down
8 changes: 4 additions & 4 deletions src/redisclient/impl/redisclientimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ void RedisClientImpl::doProcessMessage(RedisValue v)
SingleShotHandlersMap::iterator it = singleShotMsgHandlers.find(pattern.toString());
if( it != singleShotMsgHandlers.end() )
{
strand.post(std::bind(it->second, value.toByteArray()));
strand.post(std::bind(it->second, value.toByteArray(), queueName.toByteArray()));
singleShotMsgHandlers.erase(it);
}

Expand All @@ -285,7 +285,7 @@ void RedisClientImpl::doProcessMessage(RedisValue v)
for(MsgHandlersMap::iterator handlerIt = pair.first;
handlerIt != pair.second; ++handlerIt)
{
strand.post(std::bind(handlerIt->second.second, value.toByteArray()));
strand.post(std::bind(handlerIt->second.second, value.toByteArray(), queueName.toByteArray()));
}
}
else if( handlers.empty() == false &&
Expand Down Expand Up @@ -555,7 +555,7 @@ void RedisClientImpl::defaulErrorHandler(const std::string &s)
size_t RedisClientImpl::subscribe(
const std::string &command,
const std::string &channel,
std::function<void(std::vector<char> msg)> msgHandler,
MsgHandler msgHandler,
std::function<void(RedisValue)> handler)
{
assert(state == State::Connected ||
Expand Down Expand Up @@ -586,7 +586,7 @@ size_t RedisClientImpl::subscribe(
void RedisClientImpl::singleShotSubscribe(
const std::string &command,
const std::string &channel,
std::function<void(std::vector<char> msg)> msgHandler,
MsgHandler msgHandler,
std::function<void(RedisValue)> handler)
{
assert(state == State::Connected ||
Expand Down
11 changes: 7 additions & 4 deletions src/redisclient/impl/redisclientimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class RedisClientImpl : public std::enable_shared_from_this<RedisClientImpl> {
Subscribed,
Closed
};

typedef std::function<void(const std::vector<char> &buf,const std::vector<char> &p)> MsgHandler;
typedef std::pair<size_t, MsgHandler > MsgHandlerType;
typedef std::function<void(const std::vector<char> &buf,const std::vector<char> &p)> SingleShotHandlerType;


REDIS_CLIENT_DECL RedisClientImpl(boost::asio::io_service &ioService);
REDIS_CLIENT_DECL ~RedisClientImpl();
Expand All @@ -46,12 +51,12 @@ class RedisClientImpl : public std::enable_shared_from_this<RedisClientImpl> {

REDIS_CLIENT_DECL size_t subscribe(const std::string &command,
const std::string &channel,
std::function<void(std::vector<char> msg)> msgHandler,
MsgHandler msgHandler,
std::function<void(RedisValue)> handler);

REDIS_CLIENT_DECL void singleShotSubscribe(const std::string &command,
const std::string &channel,
std::function<void(std::vector<char> msg)> msgHandler,
MsgHandler msgHandler,
std::function<void(RedisValue)> handler);

REDIS_CLIENT_DECL void unsubscribe(const std::string &command,
Expand Down Expand Up @@ -98,8 +103,6 @@ class RedisClientImpl : public std::enable_shared_from_this<RedisClientImpl> {
size_t bufSize; // only for sync
size_t subscribeSeq;

typedef std::pair<size_t, std::function<void(const std::vector<char> &buf)> > MsgHandlerType;
typedef std::function<void(const std::vector<char> &buf)> SingleShotHandlerType;

typedef std::multimap<std::string, MsgHandlerType> MsgHandlersMap;
typedef std::multimap<std::string, SingleShotHandlerType> SingleShotHandlersMap;
Expand Down
8 changes: 4 additions & 4 deletions src/redisclient/redisasyncclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ class RedisAsyncClient : boost::noncopyable {
// when someone publish message on channel. Call unsubscribe
// to stop the subscription.
REDIS_CLIENT_DECL Handle subscribe(const std::string &channelName,
std::function<void(std::vector<char> msg)> msgHandler,
RedisClientImpl::MsgHandler msgHandler,
std::function<void(RedisValue)> handler = &dummyHandler);


REDIS_CLIENT_DECL Handle psubscribe(const std::string &pattern,
std::function<void(std::vector<char> msg)> msgHandler,
RedisClientImpl::MsgHandler msgHandler,
std::function<void(RedisValue)> handler = &dummyHandler);

// Unsubscribe
Expand All @@ -86,12 +86,12 @@ class RedisAsyncClient : boost::noncopyable {
// unsubscribed after call.
REDIS_CLIENT_DECL void singleShotSubscribe(
const std::string &channel,
std::function<void(std::vector<char> msg)> msgHandler,
RedisClientImpl::MsgHandler msgHandler,
std::function<void(RedisValue)> handler = &dummyHandler);

REDIS_CLIENT_DECL void singleShotPSubscribe(
const std::string &channel,
std::function<void(std::vector<char> msg)> msgHandler,
RedisClientImpl::MsgHandler msgHandler,
std::function<void(RedisValue)> handler = &dummyHandler);

// Publish message on channel.
Expand Down