Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mult exec example #31

Merged
merged 1 commit into from
Apr 18, 2019
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 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;
}