Skip to content
This repository was archived by the owner on Apr 6, 2019. It is now read-only.

Commit ba48fc6

Browse files
authored
Merge pull request #8 from Cylix/remove_boost_asio_dependency
Remove boost asio dependency
2 parents 46417b4 + b7d313f commit ba48fc6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1192
-934
lines changed

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ project(${PROJECT} CXX)
2020
###
2121
# compilation options
2222
###
23-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -W -Wall -Wextra")
23+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -W -Wall -Wextra -O3")
2424

2525

2626
###
@@ -60,7 +60,7 @@ endforeach()
6060
# executable
6161
###
6262
add_library(${PROJECT} SHARED ${SOURCES})
63-
target_link_libraries(${PROJECT} boost_system)
63+
target_link_libraries(${PROJECT} pthread)
6464
set_target_properties(${PROJECT}
6565
PROPERTIES
6666
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/target")
@@ -76,13 +76,13 @@ install (DIRECTORY ${CPP_REDIS_INCLUDES}/ DESTINATION include)
7676
# examples
7777
###
7878
IF (BUILD_EXAMPLES)
79-
add_subdirectory(examples)
79+
add_subdirectory(examples)
8080
ENDIF(BUILD_EXAMPLES)
8181

8282

8383
###
8484
# tests
8585
###
8686
IF (BUILD_TESTS)
87-
add_subdirectory(tests)
87+
add_subdirectory(tests)
8888
ENDIF(BUILD_TESTS)

LICENSE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 Simon Ninon
3+
Copyright (c) 2015-2016 Simon Ninon
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
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-

README.md

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# cpp_redis
22
cpp_redis is C++11 Asynchronous Redis Client.
33

4-
Network is based on Boost Asio library.
4+
Network is based on raw sockets API. This, library is really lightweight.
55

66
## Requirements
77
* C++11
8-
* Boost Asio
98

109
## Compiling
1110
The library uses `cmake`. In order to build the library, follow these steps:
@@ -62,7 +61,7 @@ Reply callback is an `std::function<void(reply&)>`.
6261
### Example
6362

6463
```cpp
65-
#include "cpp_redis/cpp_redis"
64+
#include <cpp_redis/cpp_redis>
6665

6766
#include <signal.h>
6867
#include <iostream>
@@ -72,28 +71,31 @@ cpp_redis::redis_client client;
7271

7372
void
7473
sigint_handler(int) {
75-
std::cout << "disconnected (sigint handler)" << std::endl;
76-
client.disconnect();
74+
std::cout << "disconnected (sigint handler)" << std::endl;
75+
client.disconnect();
76+
should_exit = true;
7777
}
7878

7979
int
8080
main(void) {
81-
client.set_disconnection_handler([] (cpp_redis::redis_client&) {
82-
std::cout << "client disconnected (disconnection handler)" << std::endl;
83-
should_exit = true;
84-
});
81+
client.set_disconnection_handler([] (cpp_redis::redis_client&) {
82+
std::cout << "client disconnected (disconnection handler)" << std::endl;
83+
should_exit = true;
84+
});
8585

86-
client.connect();
86+
client.connect();
8787

88-
client.send({"SET", "hello", "world"});
89-
client.send({"GET", "hello"}, [] (cpp_redis::reply& reply) {
90-
std::cout << reply.as_string() << std::endl;
91-
});
88+
client.send({"SET", "hello", "world"}, [] (cpp_redis::reply& reply) {
89+
std::cout << reply.as_string() << std::endl;
90+
});
91+
client.send({"GET", "hello"}, [] (cpp_redis::reply& reply) {
92+
std::cout << reply.as_string() << std::endl;
93+
});
9294

93-
signal(SIGINT, &sigint_handler);
94-
while (not should_exit);
95+
signal(SIGINT, &sigint_handler);
96+
while (not should_exit);
9597

96-
return 0;
98+
return 0;
9799
}
98100
```
99101
@@ -133,7 +135,7 @@ Unsubscribe from the given pattern.
133135
### Example
134136
135137
```cpp
136-
#include "cpp_redis/cpp_redis"
138+
#include <cpp_redis/cpp_redis>
137139
138140
#include <signal.h>
139141
#include <iostream>
@@ -145,6 +147,7 @@ void
145147
sigint_handler(int) {
146148
std::cout << "disconnected (sigint handler)" << std::endl;
147149
sub.disconnect();
150+
should_exit = true;
148151
}
149152
150153
int

examples/redis_client.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,29 @@ cpp_redis::redis_client client;
88

99
void
1010
sigint_handler(int) {
11-
std::cout << "disconnected (sigint handler)" << std::endl;
12-
client.disconnect();
11+
std::cout << "disconnected (sigint handler)" << std::endl;
12+
client.disconnect();
13+
should_exit = true;
1314
}
1415

1516
int
1617
main(void) {
17-
client.set_disconnection_handler([] (cpp_redis::redis_client&) {
18-
std::cout << "client disconnected (disconnection handler)" << std::endl;
19-
should_exit = true;
20-
});
18+
client.set_disconnection_handler([] (cpp_redis::redis_client&) {
19+
std::cout << "client disconnected (disconnection handler)" << std::endl;
20+
should_exit = true;
21+
});
2122

22-
client.connect();
23+
client.connect();
2324

24-
client.send({"SET", "hello", "world"});
25-
client.send({"GET", "hello"}, [] (cpp_redis::reply& reply) {
26-
std::cout << reply.as_string() << std::endl;
27-
});
25+
client.send({"SET", "hello", "world"}, [] (cpp_redis::reply& reply) {
26+
std::cout << reply.as_string() << std::endl;
27+
});
28+
client.send({"GET", "hello"}, [] (cpp_redis::reply& reply) {
29+
std::cout << reply.as_string() << std::endl;
30+
});
2831

29-
signal(SIGINT, &sigint_handler);
30-
while (not should_exit);
32+
signal(SIGINT, &sigint_handler);
33+
while (not should_exit);
3134

32-
return 0;
35+
return 0;
3336
}

examples/redis_subscriber.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,29 @@ cpp_redis::redis_subscriber sub;
88

99
void
1010
sigint_handler(int) {
11-
std::cout << "disconnected (sigint handler)" << std::endl;
12-
sub.disconnect();
11+
std::cout << "disconnected (sigint handler)" << std::endl;
12+
sub.disconnect();
13+
should_exit = true;
1314
}
1415

1516
int
1617
main(void) {
17-
sub.set_disconnection_handler([] (cpp_redis::redis_subscriber&) {
18-
std::cout << "sub disconnected (disconnection handler)" << std::endl;
19-
should_exit = true;
20-
});
18+
sub.set_disconnection_handler([] (cpp_redis::redis_subscriber&) {
19+
std::cout << "sub disconnected (disconnection handler)" << std::endl;
20+
should_exit = true;
21+
});
2122

22-
sub.connect();
23+
sub.connect();
2324

24-
sub.subscribe("some_chan", [] (const std::string& chan, const std::string& msg) {
25-
std::cout << "MESSAGE " << chan << ": " << msg << std::endl;
26-
});
27-
sub.psubscribe("*", [] (const std::string& chan, const std::string& msg) {
28-
std::cout << "PMESSAGE " << chan << ": " << msg << std::endl;
29-
});
25+
sub.subscribe("some_chan", [] (const std::string& chan, const std::string& msg) {
26+
std::cout << "MESSAGE " << chan << ": " << msg << std::endl;
27+
});
28+
sub.psubscribe("*", [] (const std::string& chan, const std::string& msg) {
29+
std::cout << "PMESSAGE " << chan << ": " << msg << std::endl;
30+
});
3031

31-
signal(SIGINT, &sigint_handler);
32-
while (not should_exit);
32+
signal(SIGINT, &sigint_handler);
33+
while (not should_exit);
3334

34-
return 0;
35+
return 0;
3536
}

includes/cpp_redis/builders/array_builder.hpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,32 @@ namespace builders {
1010

1111
class array_builder : public builder_iface {
1212
public:
13-
//! ctor & dtor
14-
array_builder(void);
15-
~array_builder(void) = default;
13+
//! ctor & dtor
14+
array_builder(void);
15+
~array_builder(void) = default;
1616

17-
//! copy ctor & assignment operator
18-
array_builder(const array_builder&) = delete;
19-
array_builder& operator=(const array_builder&) = delete;
17+
//! copy ctor & assignment operator
18+
array_builder(const array_builder&) = delete;
19+
array_builder& operator=(const array_builder&) = delete;
2020

2121
public:
22-
//! builder_iface impl
23-
builder_iface& operator<<(std::string&);
24-
bool reply_ready(void) const;
25-
reply get_reply(void) const;
22+
//! builder_iface impl
23+
builder_iface& operator<<(std::string&);
24+
bool reply_ready(void) const;
25+
reply get_reply(void) const;
2626

2727
private:
28-
bool fetch_array_size(std::string& buffer);
29-
bool build_row(std::string& buffer);
28+
bool fetch_array_size(std::string& buffer);
29+
bool build_row(std::string& buffer);
3030

3131
private:
32-
integer_builder m_int_builder;
33-
unsigned int m_array_size;
32+
integer_builder m_int_builder;
33+
unsigned int m_array_size;
3434

35-
std::unique_ptr<builder_iface> m_current_builder;
35+
std::unique_ptr<builder_iface> m_current_builder;
3636

37-
bool m_reply_ready;
38-
replies::array_reply m_reply;
37+
bool m_reply_ready;
38+
replies::array_reply m_reply;
3939
};
4040

4141
} //! builders

includes/cpp_redis/builders/builder_iface.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ namespace builders {
1212
//! interface inherited by all builders
1313
class builder_iface {
1414
public:
15-
virtual ~builder_iface(void) = default;
15+
virtual ~builder_iface(void) = default;
1616

17-
//! take data as parameter which is consumed to build the reply
18-
//! every bytes used to build the reply must be removed from the buffer passed as parameter
19-
virtual builder_iface& operator<<(std::string&) = 0;
17+
//! take data as parameter which is consumed to build the reply
18+
//! every bytes used to build the reply must be removed from the buffer passed as parameter
19+
virtual builder_iface& operator<<(std::string&) = 0;
2020

21-
//! return whether the reply could be built
22-
virtual bool reply_ready(void) const = 0;
21+
//! return whether the reply could be built
22+
virtual bool reply_ready(void) const = 0;
2323

24-
//! return reply object
25-
virtual reply get_reply(void) const = 0;
24+
//! return reply object
25+
virtual reply get_reply(void) const = 0;
2626
};
2727

2828
} //! builders

includes/cpp_redis/builders/bulk_string_builder.hpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,39 @@ namespace builders {
1010

1111
class bulk_string_builder : public builder_iface {
1212
public:
13-
//! ctor & dtor
14-
bulk_string_builder(void);
15-
~bulk_string_builder(void) = default;
13+
//! ctor & dtor
14+
bulk_string_builder(void);
15+
~bulk_string_builder(void) = default;
1616

17-
//! copy ctor & assignment operator
18-
bulk_string_builder(const bulk_string_builder&) = delete;
19-
bulk_string_builder& operator=(const bulk_string_builder&) = delete;
17+
//! copy ctor & assignment operator
18+
bulk_string_builder(const bulk_string_builder&) = delete;
19+
bulk_string_builder& operator=(const bulk_string_builder&) = delete;
2020

2121
public:
22-
//! builder_iface impl
23-
builder_iface& operator<<(std::string&);
24-
bool reply_ready(void) const;
25-
reply get_reply(void) const;
22+
//! builder_iface impl
23+
builder_iface& operator<<(std::string&);
24+
bool reply_ready(void) const;
25+
reply get_reply(void) const;
2626

27-
//! getter
28-
const std::string& get_bulk_string(void) const;
29-
bool is_null(void) const;
27+
//! getter
28+
const std::string& get_bulk_string(void) const;
29+
bool is_null(void) const;
3030

3131
private:
32-
void build_reply(void);
33-
bool fetch_size(std::string& str);
34-
void fetch_str(std::string& str);
32+
void build_reply(void);
33+
bool fetch_size(std::string& str);
34+
void fetch_str(std::string& str);
3535

3636
private:
37-
//! used to get bulk string size
38-
integer_builder m_int_builder;
37+
//! used to get bulk string size
38+
integer_builder m_int_builder;
3939

40-
int m_str_size;
41-
std::string m_str;
42-
bool m_is_null;
40+
int m_str_size;
41+
std::string m_str;
42+
bool m_is_null;
4343

44-
bool m_reply_ready;
45-
replies::bulk_string_reply m_reply;
44+
bool m_reply_ready;
45+
replies::bulk_string_reply m_reply;
4646
};
4747

4848
} //! builders

0 commit comments

Comments
 (0)