forked from Cylix/cpp_redis
-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c53f12d
commit d1fc9c7
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |