Skip to content

Commit

Permalink
Add mult exec example (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
theidexisted authored and appkins committed Apr 18, 2019
1 parent c53f12d commit d1fc9c7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ set(EXAMPLES cpp_redis_client
cpp_redis_kill
cpp_redis_streams_client
cpp_redis_high_availability_client
cpp_redis_multi_exec
)

foreach(EXAMPLE IN ITEMS ${EXAMPLES})
Expand Down
35 changes: 35 additions & 0 deletions examples/cpp_redis_multi_exec.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// The MIT License (MIT)

#include "winsock_initializer.h"
#include <cpp_redis/cpp_redis>
#include <string>

int
main(void) {
winsock_initializer winsock_init;
cpp_redis::client client;

client.connect("127.0.0.1", 6379,
[](const std::string& host, std::size_t port, cpp_redis::connect_state status) {
if (status == cpp_redis::connect_state::dropped) {
std::cout << "client disconnected from " << host << ":" << port << std::endl;
}
});
client.multi([](cpp_redis::reply& reply) {
std::cout << "transaction start:" << reply << std::endl;
});
client.set("hello", "42", [](cpp_redis::reply& reply) {
std::cout << "set hello 42: " << reply << std::endl;
});
client.decrby("hello", 12, [](cpp_redis::reply& reply) {
std::cout << "decrby hello 12: " << reply << std::endl;
});
// Previous two commands will be queued until exec called
client.exec([](cpp_redis::reply& reply) {
std::cout << "transaction end:" << reply << std::endl;
});

client.sync_commit();

return 0;
}

0 comments on commit d1fc9c7

Please sign in to comment.