Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d1fc9c7

Browse filesBrowse files
theidexistedappkins
authored andcommitted
Add mult exec example (#31)
1 parent c53f12d commit d1fc9c7
Copy full SHA for d1fc9c7

File tree

2 files changed

+36
-0
lines changed
Filter options

2 files changed

+36
-0
lines changed

‎examples/CMakeLists.txt

Copy file name to clipboardExpand all lines: examples/CMakeLists.txt
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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

5253
foreach(EXAMPLE IN ITEMS ${EXAMPLES})

‎examples/cpp_redis_multi_exec.cpp

Copy file name to clipboard
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.