Skip to content

Commit f62146c

Browse files
committed
Merge branch 'master' into develop
2 parents cc7d525 + daec5f5 commit f62146c

18 files changed

+821
-359
lines changed

.cquery

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
%clang
2+
%c -std=gnu11
3+
%cpp -std=gnu++14
4+
-pthread
5+
6+
# Includes
7+
-I./vendor
8+
-I./include

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
.idea
2727
.vscode
2828

29+
# Vendor
30+
vendor/*
31+
!vendor/.gitkeep
32+
2933
# Autogen directories
3034
build
3135
*build*

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ addons:
2424

2525
before_install:
2626
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi
27-
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install llvm --with-clang; fi
27+
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install llvm; fi
2828

2929
install:
3030
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install ccache; fi

examples/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# compilation options
2525
###
2626
if(NOT WIN32)
27-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
27+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-unused-variable")
2828
endif(NOT WIN32)
2929

3030

@@ -65,4 +65,4 @@ foreach(EXAMPLE IN ITEMS ${EXAMPLES})
6565
else()
6666
target_link_libraries(${EXAMPLE} pthread)
6767
endif(WIN32)
68-
endforeach(EXAMPLE)
68+
endforeach(EXAMPLE)

examples/cpp_redis_client.cpp

Lines changed: 28 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -19,55 +19,40 @@
1919
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
22+
#include <string>
2223
#include <cpp_redis/cpp_redis>
2324
#include <cpp_redis/misc/macro.hpp>
24-
#include <string>
25+
#include "winsock_initializer.h"
2526

2627
#define ENABLE_SESSION = 1
2728

28-
#ifdef _WIN32
29-
#include <Winsock2.h>
30-
#endif //! _WIN32
31-
32-
int main() {
33-
#ifdef _WIN32
34-
//! Windows netword DLL init
35-
WORD version = MAKEWORD(2, 2);
36-
WSADATA data;
37-
38-
if (WSAStartup(version, &data) != 0) {
39-
std::cerr << "WSAStartup() failure" << std::endl;
40-
return -1;
41-
}
42-
#endif //! _WIN32
43-
44-
//! Enable logging
45-
cpp_redis::active_logger =
46-
std::unique_ptr<cpp_redis::logger>(new cpp_redis::logger);
47-
48-
cpp_redis::client client;
49-
50-
client.connect("127.0.0.1", 6379,
51-
[](const std::string &host, std::size_t port,
52-
cpp_redis::connect_state status) {
53-
if (status == cpp_redis::connect_state::dropped) {
54-
std::cout << "client disconnected from " << host << ":"
55-
<< port << std::endl;
56-
}
57-
});
58-
59-
auto replcmd = [](const cpp_redis::reply_t &reply) {
60-
std::cout << "set hello 42: " << reply << std::endl;
61-
// if (reply.is_string())
62-
// do_something_with_string(reply.as_string())
63-
};
29+
int
30+
main(void) {
31+
winsock_initializer winsock_init;
32+
//! Enable logging
33+
cpp_redis::active_logger = std::unique_ptr<cpp_redis::logger>(new cpp_redis::logger);
6434

65-
const std::string group_name = "groupone";
66-
const std::string session_name = "sessone";
67-
const std::string consumer_name = "ABCD";
35+
cpp_redis::client client;
6836

69-
std::multimap<std::string, std::string> ins;
70-
ins.insert(std::pair<std::string, std::string>{"message", "hello"});
37+
client.connect("127.0.0.1", 6379,
38+
[](const std::string &host, std::size_t port, cpp_redis::connect_state status) {
39+
if (status == cpp_redis::connect_state::dropped) {
40+
std::cout << "client disconnected from " << host << ":" << port << std::endl;
41+
}
42+
});
43+
44+
auto replcmd = [](const cpp_redis::reply &reply) {
45+
std::cout << "set hello 42: " << reply << std::endl;
46+
// if (reply.is_string())
47+
// do_something_with_string(reply.as_string())
48+
};
49+
50+
const std::string group_name = "groupone";
51+
const std::string session_name = "sessone";
52+
const std::string consumer_name = "ABCD";
53+
54+
std::multimap<std::string, std::string> ins;
55+
ins.insert(std::pair<std::string, std::string>{"message", "hello"});
7156

7257
#ifdef ENABLE_SESSION
7358

@@ -126,12 +111,6 @@ int main() {
126111
// synchronous commit, no timeout
127112
client.sync_commit();
128113

129-
// synchronous commit, timeout
130-
// client.sync_commit(std::chrono::milliseconds(100));
131-
132-
#ifdef _WIN32
133-
WSACleanup();
134-
#endif //! _WIN32
135114

136-
return 0;
115+
return 0;
137116
}

examples/cpp_redis_consumer.cpp

Lines changed: 62 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -19,98 +19,77 @@
1919
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
22+
#include <string>
2223
#include <condition_variable>
2324
#include <iostream>
2425
#include <mutex>
2526
#include <signal.h>
26-
#include <string>
2727

2828
#include <cpp_redis/cpp_redis>
29-
30-
#ifdef _WIN32
31-
#include <Winsock2.h>
32-
#endif // _WIN32
29+
#include "winsock_initializer.h"
3330

3431
std::condition_variable should_exit;
3532

3633
void sigint_handler(int) { should_exit.notify_all(); }
3734

38-
int main() {
39-
#ifdef _WIN32
40-
//! Windows netword DLL init
41-
WORD version = MAKEWORD(2, 2);
42-
WSADATA data;
43-
44-
if (WSAStartup(version, &data) != 0) {
45-
std::cerr << "WSAStartup() failure" << std::endl;
46-
return -1;
47-
}
48-
#endif // _WIN32
49-
50-
//! Enable logging
51-
52-
// const std::string group_name = "groupone";
53-
const std::vector<std::string> group_names = {"groupone"}; //, "grouptwo"};
54-
const std::string session_name = "sessone";
55-
const std::string consumer_name = "ABCD";
56-
57-
cpp_redis::active_logger =
58-
std::unique_ptr<cpp_redis::logger>(new cpp_redis::logger);
59-
60-
cpp_redis::consumer sub(session_name, consumer_name);
61-
62-
sub.connect("127.0.0.1", 6379,
63-
[](const std::string &host, std::size_t port,
64-
cpp_redis::connect_state status) {
65-
if (status == cpp_redis::connect_state::dropped) {
66-
std::cout << "client disconnected from " << host << ":"
67-
<< port << std::endl;
68-
}
69-
});
70-
71-
sub.auth("{redis_key}");
72-
73-
for (auto &group : group_names) {
74-
75-
sub.subscribe(group,
76-
[group](const cpp_redis::message_type msg) {
77-
cpp_redis::consumer_response_t res;
78-
// Callback will run for each message obtained from the
79-
// queue
80-
std::cout << "Group: " << group << std::endl;
81-
std::cout << "Id in the cb: " << msg.get_id() << std::endl;
82-
res.insert({"Id", msg.get_id()});
83-
return res;
84-
},
85-
[group](int ack_status) {
86-
// Callback will run upon return of xack
87-
std::cout << "Group: " << group << std::endl;
88-
std::cout << "Ack status: " << ack_status << std::endl;
89-
});
90-
}
91-
92-
/*sub.subscribe(group_name,
93-
[](const cpp_redis::message_type msg) {
94-
// Callback will run for each message
95-
obtained from the queue std::cout << "Id in the cb: " << msg.get_id()
96-
<< std::endl; return msg;
97-
},
98-
[](int ack_status) {
99-
// Callback will run upon return of
100-
xack std::cout << "Ack status: " << ack_status
101-
<< std::endl;
102-
});*/
103-
104-
sub.commit();
105-
106-
signal(SIGINT, &sigint_handler);
107-
std::mutex mtx;
108-
std::unique_lock<std::mutex> l(mtx);
109-
should_exit.wait(l);
110-
111-
#ifdef _WIN32
112-
WSACleanup();
113-
#endif // _WIN32
114-
115-
return 0;
35+
int
36+
main() {
37+
winsock_initializer winsock_init;
38+
//! Enable logging
39+
40+
//const std::string group_name = "groupone";
41+
const std::vector<std::string> group_names = {"groupone"}; //, "grouptwo"};
42+
const std::string session_name = "sessone";
43+
const std::string consumer_name = "ABCD";
44+
45+
cpp_redis::active_logger = std::unique_ptr<cpp_redis::logger>(new cpp_redis::logger);
46+
47+
cpp_redis::consumer sub(session_name, consumer_name);
48+
49+
sub.connect("127.0.0.1", 6379,
50+
[](const std::string &host, std::size_t port, cpp_redis::connect_state status) {
51+
if (status == cpp_redis::connect_state::dropped) {
52+
std::cout << "client disconnected from " << host << ":" << port << std::endl;
53+
}
54+
});
55+
56+
sub.auth("{redis_key}");
57+
58+
for (auto &group : group_names) {
59+
60+
sub.subscribe(group,
61+
[group](const cpp_redis::message_type msg) {
62+
cpp_redis::consumer_response_t res;
63+
// Callback will run for each message obtained from the queue
64+
std::cout << "Group: " << group << std::endl;
65+
std::cout << "Id in the cb: " << msg.get_id() << std::endl;
66+
res.insert({"Id", msg.get_id()});
67+
return res;
68+
},
69+
[group](int ack_status) {
70+
// Callback will run upon return of xack
71+
std::cout << "Group: " << group << std::endl;
72+
std::cout << "Ack status: " << ack_status << std::endl;
73+
});
74+
}
75+
76+
/*sub.subscribe(group_name,
77+
[](const cpp_redis::message_type msg) {
78+
// Callback will run for each message obtained from the queue
79+
std::cout << "Id in the cb: " << msg.get_id() << std::endl;
80+
return msg;
81+
},
82+
[](int ack_status) {
83+
// Callback will run upon return of xack
84+
std::cout << "Ack status: " << ack_status << std::endl;
85+
});*/
86+
87+
sub.commit();
88+
89+
signal(SIGINT, &sigint_handler);
90+
std::mutex mtx;
91+
std::unique_lock<std::mutex> l(mtx);
92+
should_exit.wait(l);
93+
94+
return 0;
11695
}

examples/cpp_redis_future_client.cpp

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,11 @@
2323
#include <cpp_redis/cpp_redis>
2424

2525
#include <iostream>
26+
#include "winsock_initializer.h"
2627

27-
#ifdef _WIN32
28-
#include <Winsock2.h>
29-
#endif //! _WIN32
30-
31-
int main(void) {
32-
#ifdef _WIN32
33-
//! Windows netword DLL init
34-
WORD version = MAKEWORD(2, 2);
35-
WSADATA data;
36-
37-
if (WSAStartup(version, &data) != 0) {
38-
std::cerr << "WSAStartup() failure" << std::endl;
39-
return -1;
40-
}
41-
#endif //! _WIN32
28+
int
29+
main(void) {
30+
winsock_initializer winsock_init;
4231

4332
//! Enable logging
4433
cpp_redis::active_logger =
@@ -78,9 +67,5 @@ int main(void) {
7867

7968
std::cout << "get 'hello': " << get.get() << std::endl;
8069

81-
#ifdef _WIN32
82-
WSACleanup();
83-
#endif //! _WIN32
84-
8570
return 0;
8671
}

0 commit comments

Comments
 (0)