Skip to content
This repository was archived by the owner on Apr 6, 2019. It is now read-only.
Merged
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
1 change: 1 addition & 0 deletions sources/network/redis_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ redis_connection::commit(void) {
m_client->async_write(request);
}
catch (const std::exception& e) {
m_buffer = std::move(buffer);
__CPP_REDIS_LOG(error, std::string("cpp_redis::network::redis_connection ") + e.what());
throw redis_error(e.what());
}
Expand Down
3 changes: 1 addition & 2 deletions sources/redis_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ redis_client::try_commit(void) {
}
catch (const cpp_redis::redis_error& e) {
__CPP_REDIS_LOG(error, "cpp_redis::redis_client could not send pipelined commands");
clear_callbacks();
throw e;
}
}
Expand All @@ -126,10 +125,10 @@ redis_client::connection_receive_handler(network::redis_connection&, reply& repl
__CPP_REDIS_LOG(info, "cpp_redis::redis_client received reply");
{
std::lock_guard<std::mutex> lock(m_callbacks_mutex);
m_callbacks_running += 1;

if (m_callbacks.size()) {
callback = m_callbacks.front();
m_callbacks_running += 1;
m_callbacks.pop();
}
}
Expand Down
26 changes: 22 additions & 4 deletions tests/sources/spec/redis_client_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ TEST(RedisClient, SendNotConnectedSyncCommitNotConnectedSyncCommitConnected) {
EXPECT_THROW(client.sync_commit(), cpp_redis::redis_error);
client.connect();
client.sync_commit();
//! should have cleared commands in the buffer
EXPECT_FALSE(callback_run);
//! should not have cleared commands in the buffer
EXPECT_TRUE(callback_run);
}

TEST(RedisClient, Send) {
Expand Down Expand Up @@ -297,7 +297,7 @@ TEST(RedisClient, DisconnectionHandlerWithoutQuit) {
EXPECT_FALSE(disconnection_handler_called);
}

TEST(RedisClient, ClearBufferOnError) {
TEST(RedisClient, DoNotClearBufferOnError) {
cpp_redis::redis_client client;

client.connect();
Expand All @@ -310,7 +310,25 @@ TEST(RedisClient, ClearBufferOnError) {
client.connect();
client.send({"GET", "HELLO"}, [&](cpp_redis::reply& reply) {
EXPECT_TRUE(reply.is_string());
EXPECT_TRUE(reply.as_string() == "BEFORE");
EXPECT_TRUE(reply.as_string() == "AFTER");
});
client.sync_commit();
}

TEST(RedisClient, ClearBufferOnUserDisconnect) {
cpp_redis::redis_client client;

client.connect();
client.send({"SET", "HELLO", "BEFORE"});
client.sync_commit();
client.send({"SET", "HELLO", "AFTER"});
client.disconnect();

EXPECT_THROW(client.sync_commit(), cpp_redis::redis_error);
client.connect();
client.send({"GET", "HELLO"}, [&](cpp_redis::reply& reply) {
EXPECT_TRUE(reply.is_string());
EXPECT_TRUE(reply.as_string() == "AFTER");
});
client.sync_commit();
}
2 changes: 1 addition & 1 deletion tests/sources/spec/redis_subscriber_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ TEST(RedisSubscriber, SubNotConnectedCommitNotConnectedCommitConnected) {

std::this_thread::sleep_for(std::chrono::seconds(2));

EXPECT_FALSE(callback_run);
EXPECT_TRUE(callback_run);
}

TEST(RedisSubscriber, SubscribeSomethingPublished) {
Expand Down