File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ set(EXAMPLES cpp_redis_client
4747 cpp_redis_kill
4848 cpp_redis_streams_client
4949 cpp_redis_high_availability_client
50+ cpp_redis_multi_exec
5051 )
5152
5253foreach (EXAMPLE IN ITEMS ${EXAMPLES} )
Original file line number Diff line number Diff line change 1+ // The MIT License (MIT)
2+
3+ #include " winsock_initializer.h"
4+ #include < cpp_redis/cpp_redis>
5+ #include < string>
6+
7+ int
8+ main (void ) {
9+ winsock_initializer winsock_init;
10+ cpp_redis::client client;
11+
12+ client.connect (" 127.0.0.1" , 6379 ,
13+ [](const std::string& host, std::size_t port, cpp_redis::connect_state status) {
14+ if (status == cpp_redis::connect_state::dropped) {
15+ std::cout << " client disconnected from " << host << " :" << port << std::endl;
16+ }
17+ });
18+ client.multi ([](cpp_redis::reply& reply) {
19+ std::cout << " transaction start:" << reply << std::endl;
20+ });
21+ client.set (" hello" , " 42" , [](cpp_redis::reply& reply) {
22+ std::cout << " set hello 42: " << reply << std::endl;
23+ });
24+ client.decrby (" hello" , 12 , [](cpp_redis::reply& reply) {
25+ std::cout << " decrby hello 12: " << reply << std::endl;
26+ });
27+ // Previous two commands will be queued until exec called
28+ client.exec ([](cpp_redis::reply& reply) {
29+ std::cout << " transaction end:" << reply << std::endl;
30+ });
31+
32+ client.sync_commit ();
33+
34+ return 0 ;
35+ }
You can’t perform that action at this time.
0 commit comments