Commit 7a15a7f2b983c1a8a25f46cd96efefac2e55268b
1 parent
5db70130
Separated out include directory, started tutorial
Separate include directory so that examples can reference the same thing whether installed in the system or from the local folder.
Showing
9 changed files
with
59 additions
and
32 deletions
CMakeLists.txt
| @@ -26,23 +26,32 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC -Wall") | @@ -26,23 +26,32 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC -Wall") | ||
| 26 | # --------------------------------------------------------- | 26 | # --------------------------------------------------------- |
| 27 | 27 | ||
| 28 | set(SRC_DIR ${CMAKE_SOURCE_DIR}/src) | 28 | set(SRC_DIR ${CMAKE_SOURCE_DIR}/src) |
| 29 | +set(INC_DIR ${CMAKE_SOURCE_DIR}/include/redox) | ||
| 29 | 30 | ||
| 30 | set(SRC_CORE | 31 | set(SRC_CORE |
| 31 | ${SRC_DIR}/client.cpp | 32 | ${SRC_DIR}/client.cpp |
| 32 | ${SRC_DIR}/command.cpp | 33 | ${SRC_DIR}/command.cpp |
| 33 | - ${SRC_DIR}/subscriber.cpp | ||
| 34 | -) | 34 | + ${SRC_DIR}/subscriber.cpp) |
| 35 | 35 | ||
| 36 | -set(SRC_LOGGER ${SRC_DIR}/utils/logger.cpp) | 36 | +set(INC_CORE |
| 37 | + ${INC_DIR}/client.hpp | ||
| 38 | + ${INC_DIR}/subscriber.hpp | ||
| 39 | + ${INC_DIR}/command.hpp) | ||
| 37 | 40 | ||
| 38 | -set(SRC_ALL ${SRC_CORE} ${SRC_LOGGER}) | 41 | +set(SRC_UTILS ${SRC_DIR}/utils/logger.cpp) |
| 42 | +set(INC_UTILS ${INC_DIR}/utils/logger.hpp) | ||
| 39 | 43 | ||
| 40 | -include_directories(${SRC_DIR}) | 44 | +set(INC_WRAPPER ${CMAKE_SOURCE_DIR}/include/redox.hpp) |
| 45 | + | ||
| 46 | +set(SRC_ALL ${SRC_CORE} ${SRC_UTILS}) | ||
| 47 | +set(INC_ALL ${INC_CORE} ${INC_UTILS} ${INC_WRAPPER}) | ||
| 48 | + | ||
| 49 | +include_directories(${INC_DIR} ${INC_DIR/redox}) | ||
| 41 | 50 | ||
| 42 | # Dependent libraries - you may have to change | 51 | # Dependent libraries - you may have to change |
| 43 | # pthread to whatever C++11 threads depends on | 52 | # pthread to whatever C++11 threads depends on |
| 44 | # for your platform | 53 | # for your platform |
| 45 | -set(REDOX_LIB_DEPS hiredis ev pthread) | 54 | +set(REDOX_LIB_DEPS ev pthread hiredis) |
| 46 | 55 | ||
| 47 | # --------------------------------------------------------- | 56 | # --------------------------------------------------------- |
| 48 | # Library generation | 57 | # Library generation |
| @@ -50,7 +59,7 @@ set(REDOX_LIB_DEPS hiredis ev pthread) | @@ -50,7 +59,7 @@ set(REDOX_LIB_DEPS hiredis ev pthread) | ||
| 50 | 59 | ||
| 51 | if (lib) | 60 | if (lib) |
| 52 | 61 | ||
| 53 | - add_library(redox SHARED ${SRC_ALL}) | 62 | + add_library(redox SHARED ${SRC_ALL} ${INC_CORE}) |
| 54 | target_link_libraries(redox ${REDOX_LIB_DEPS}) | 63 | target_link_libraries(redox ${REDOX_LIB_DEPS}) |
| 55 | 64 | ||
| 56 | set_target_properties(redox | 65 | set_target_properties(redox |
| @@ -139,17 +148,16 @@ endif() | @@ -139,17 +148,16 @@ endif() | ||
| 139 | # Install (sudo make install) | 148 | # Install (sudo make install) |
| 140 | # --------------------------------------------------------- | 149 | # --------------------------------------------------------- |
| 141 | 150 | ||
| 151 | +set(CMAKE_INSTALL_PREFIX /usr/) | ||
| 152 | + | ||
| 142 | # Install the dynamic library to /usr/lib | 153 | # Install the dynamic library to /usr/lib |
| 143 | install(TARGETS redox DESTINATION lib) | 154 | install(TARGETS redox DESTINATION lib) |
| 144 | 155 | ||
| 145 | # Install the headers into /usr/include/redox | 156 | # Install the headers into /usr/include/redox |
| 146 | -set(INC_CORE ${SRC_DIR}/client.hpp ${SRC_DIR}/subscriber.hpp) | ||
| 147 | -set(INC_UTILS ${SRC_DIR}/utils/logger.hpp) | ||
| 148 | install(FILES ${INC_CORE} DESTINATION include/redox) | 157 | install(FILES ${INC_CORE} DESTINATION include/redox) |
| 149 | install(FILES ${INC_UTILS} DESTINATION include/redox/utils) | 158 | install(FILES ${INC_UTILS} DESTINATION include/redox/utils) |
| 150 | 159 | ||
| 151 | -# Install the top-level header into /usr/include directly | ||
| 152 | -set(INC_WRAPPER ${SRC_DIR}/redox.hpp) | 160 | +# Install the top-level header directly into /usr/include |
| 153 | install(FILES ${INC_WRAPPER} DESTINATION include) | 161 | install(FILES ${INC_WRAPPER} DESTINATION include) |
| 154 | 162 | ||
| 155 | # --------------------------------------------------------- | 163 | # --------------------------------------------------------- |
README.md
| @@ -27,25 +27,23 @@ Redox is built on top of | @@ -27,25 +27,23 @@ Redox is built on top of | ||
| 27 | asynchronous API of hiredis, even for synchronous commands. There is no dependency on | 27 | asynchronous API of hiredis, even for synchronous commands. There is no dependency on |
| 28 | Boost or any other libraries. | 28 | Boost or any other libraries. |
| 29 | 29 | ||
| 30 | -### Performance Benchmarks | 30 | +## Benchmarks |
| 31 | Benchmarks are given by averaging the results of five trials of the speed tests | 31 | Benchmarks are given by averaging the results of five trials of the speed tests |
| 32 | in `examples/` on an AWS t2.medium instance running Ubuntu 14.04 (64-bit). | 32 | in `examples/` on an AWS t2.medium instance running Ubuntu 14.04 (64-bit). |
| 33 | 33 | ||
| 34 | Local Redis server, TCP connection: | 34 | Local Redis server, TCP connection: |
| 35 | 35 | ||
| 36 | - * 100 commandLoop calls (`speed_test_async_multi`): **710,014 commands/s** | ||
| 37 | - * One commandLoop call (`speed_test_async`): **195,159 commands/s** | ||
| 38 | - * Looped commandSync call (`speed_test_sync`): **23,609 commands/s** | 36 | + * 100 command loops (`speed_test_async_multi`): **710,014 commands/s** |
| 37 | + * One command loop (`speed_test_async`): **195,159 commands/s** | ||
| 38 | + * Looped synchronous command (`speed_test_sync`): **28,609 commands/s** | ||
| 39 | 39 | ||
| 40 | -Results are comparable to that of an | ||
| 41 | -average laptop. On a high-end laptop or PC, `speed_test_async_multi` usually tops | ||
| 42 | -1 million commands per second. All results are slightly faster if over Unix sockets | ||
| 43 | -than TCP. | 40 | +Results are comparable to that of an average laptop. On a high-end machine, |
| 41 | +`speed_test_async_multi` usually tops 1,000,000 commands/s. | ||
| 44 | 42 | ||
| 45 | -## Install | 43 | +## Installation |
| 46 | Instructions provided are for Ubuntu, but all components are platform-independent. | 44 | Instructions provided are for Ubuntu, but all components are platform-independent. |
| 47 | 45 | ||
| 48 | -### Build library from source | 46 | +#### Build from source |
| 49 | Get the build environment and dependencies: | 47 | Get the build environment and dependencies: |
| 50 | 48 | ||
| 51 | sudo apt-get install git cmake build-essential | 49 | sudo apt-get install git cmake build-essential |
| @@ -61,7 +59,7 @@ Install into system directories (optional): | @@ -61,7 +59,7 @@ Install into system directories (optional): | ||
| 61 | 59 | ||
| 62 | sudo make install | 60 | sudo make install |
| 63 | 61 | ||
| 64 | -### Build examples and test suite | 62 | +#### Build examples and test suite |
| 65 | Enable examples using ccmake or the following: | 63 | Enable examples using ccmake or the following: |
| 66 | 64 | ||
| 67 | cmake -Dexamples=ON .. | 65 | cmake -Dexamples=ON .. |
| @@ -76,4 +74,25 @@ then: | @@ -76,4 +74,25 @@ then: | ||
| 76 | ./test_redox | 74 | ./test_redox |
| 77 | 75 | ||
| 78 | ## Tutorial | 76 | ## Tutorial |
| 79 | -Coming soon. Take a look at `examples/` for now. | 77 | +Here is a hello world program for redox: |
| 78 | + | ||
| 79 | + #include <iostream> | ||
| 80 | + #include "redox.hpp" | ||
| 81 | + | ||
| 82 | + int main(int argc, char* argv[]) { | ||
| 83 | + | ||
| 84 | + redox::Redox rdx = {"localhost", 6379}; | ||
| 85 | + if(!rdx.connect()) return 1; | ||
| 86 | + | ||
| 87 | + rdx.set("hello", "world!"); | ||
| 88 | + std::cout << "Hello, " << rdx.get("hello") << std::endl; | ||
| 89 | + | ||
| 90 | + rdx.disconnect(); | ||
| 91 | + return 0; | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | +Compile and run: | ||
| 95 | + | ||
| 96 | + $ g++ hello.cpp -o hello -std=c++11 -lredox -lev -lhiredis | ||
| 97 | + $ ./hello | ||
| 98 | + Hello, world! |
src/redox.hpp renamed to include/redox.hpp
src/client.hpp renamed to include/redox/client.hpp
| @@ -72,7 +72,7 @@ public: | @@ -72,7 +72,7 @@ public: | ||
| 72 | const int port = REDIS_DEFAULT_PORT, | 72 | const int port = REDIS_DEFAULT_PORT, |
| 73 | std::function<void(int)> connection_callback = nullptr, | 73 | std::function<void(int)> connection_callback = nullptr, |
| 74 | std::ostream& log_stream = std::cout, | 74 | std::ostream& log_stream = std::cout, |
| 75 | - log::Level log_level = log::Info | 75 | + log::Level log_level = log::Warning |
| 76 | ); | 76 | ); |
| 77 | 77 | ||
| 78 | /** | 78 | /** |
| @@ -82,7 +82,7 @@ public: | @@ -82,7 +82,7 @@ public: | ||
| 82 | const std::string& path, | 82 | const std::string& path, |
| 83 | std::function<void(int)> connection_callback, | 83 | std::function<void(int)> connection_callback, |
| 84 | std::ostream& log_stream = std::cout, | 84 | std::ostream& log_stream = std::cout, |
| 85 | - log::Level log_level = log::Info | 85 | + log::Level log_level = log::Warning |
| 86 | ); | 86 | ); |
| 87 | 87 | ||
| 88 | /** | 88 | /** |
src/command.hpp renamed to include/redox/command.hpp
src/subscriber.hpp renamed to include/redox/subscriber.hpp
| @@ -36,7 +36,7 @@ public: | @@ -36,7 +36,7 @@ public: | ||
| 36 | const int port = REDIS_DEFAULT_PORT, | 36 | const int port = REDIS_DEFAULT_PORT, |
| 37 | std::function<void(int)> connection_callback = nullptr, | 37 | std::function<void(int)> connection_callback = nullptr, |
| 38 | std::ostream& log_stream = std::cout, | 38 | std::ostream& log_stream = std::cout, |
| 39 | - log::Level log_level = log::Info | 39 | + log::Level log_level = log::Warning |
| 40 | ); | 40 | ); |
| 41 | 41 | ||
| 42 | /** | 42 | /** |
| @@ -46,7 +46,7 @@ public: | @@ -46,7 +46,7 @@ public: | ||
| 46 | const std::string& path, | 46 | const std::string& path, |
| 47 | std::function<void(int)> connection_callback, | 47 | std::function<void(int)> connection_callback, |
| 48 | std::ostream& log_stream = std::cout, | 48 | std::ostream& log_stream = std::cout, |
| 49 | - log::Level log_level = log::Info | 49 | + log::Level log_level = log::Warning |
| 50 | ); | 50 | ); |
| 51 | 51 | ||
| 52 | /** | 52 | /** |
src/utils/logger.hpp renamed to include/redox/utils/logger.hpp
src/client.cpp
src/utils/logger.cpp
| @@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
| 5 | * http://vilipetek.com/2014/04/17/thread-safe-simple-logger-in-c11/ | 5 | * http://vilipetek.com/2014/04/17/thread-safe-simple-logger-in-c11/ |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | -#include "logger.hpp" | 8 | +#include "utils/logger.hpp" |
| 9 | #include <iostream> | 9 | #include <iostream> |
| 10 | #include <iomanip> | 10 | #include <iomanip> |
| 11 | 11 |