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 | 26 | # --------------------------------------------------------- |
| 27 | 27 | |
| 28 | 28 | set(SRC_DIR ${CMAKE_SOURCE_DIR}/src) |
| 29 | +set(INC_DIR ${CMAKE_SOURCE_DIR}/include/redox) | |
| 29 | 30 | |
| 30 | 31 | set(SRC_CORE |
| 31 | 32 | ${SRC_DIR}/client.cpp |
| 32 | 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 | 51 | # Dependent libraries - you may have to change |
| 43 | 52 | # pthread to whatever C++11 threads depends on |
| 44 | 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 | 57 | # Library generation |
| ... | ... | @@ -50,7 +59,7 @@ set(REDOX_LIB_DEPS hiredis ev pthread) |
| 50 | 59 | |
| 51 | 60 | if (lib) |
| 52 | 61 | |
| 53 | - add_library(redox SHARED ${SRC_ALL}) | |
| 62 | + add_library(redox SHARED ${SRC_ALL} ${INC_CORE}) | |
| 54 | 63 | target_link_libraries(redox ${REDOX_LIB_DEPS}) |
| 55 | 64 | |
| 56 | 65 | set_target_properties(redox |
| ... | ... | @@ -139,17 +148,16 @@ endif() |
| 139 | 148 | # Install (sudo make install) |
| 140 | 149 | # --------------------------------------------------------- |
| 141 | 150 | |
| 151 | +set(CMAKE_INSTALL_PREFIX /usr/) | |
| 152 | + | |
| 142 | 153 | # Install the dynamic library to /usr/lib |
| 143 | 154 | install(TARGETS redox DESTINATION lib) |
| 144 | 155 | |
| 145 | 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 | 157 | install(FILES ${INC_CORE} DESTINATION include/redox) |
| 149 | 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 | 161 | install(FILES ${INC_WRAPPER} DESTINATION include) |
| 154 | 162 | |
| 155 | 163 | # --------------------------------------------------------- | ... | ... |
README.md
| ... | ... | @@ -27,25 +27,23 @@ Redox is built on top of |
| 27 | 27 | asynchronous API of hiredis, even for synchronous commands. There is no dependency on |
| 28 | 28 | Boost or any other libraries. |
| 29 | 29 | |
| 30 | -### Performance Benchmarks | |
| 30 | +## Benchmarks | |
| 31 | 31 | Benchmarks are given by averaging the results of five trials of the speed tests |
| 32 | 32 | in `examples/` on an AWS t2.medium instance running Ubuntu 14.04 (64-bit). |
| 33 | 33 | |
| 34 | 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 | 44 | Instructions provided are for Ubuntu, but all components are platform-independent. |
| 47 | 45 | |
| 48 | -### Build library from source | |
| 46 | +#### Build from source | |
| 49 | 47 | Get the build environment and dependencies: |
| 50 | 48 | |
| 51 | 49 | sudo apt-get install git cmake build-essential |
| ... | ... | @@ -61,7 +59,7 @@ Install into system directories (optional): |
| 61 | 59 | |
| 62 | 60 | sudo make install |
| 63 | 61 | |
| 64 | -### Build examples and test suite | |
| 62 | +#### Build examples and test suite | |
| 65 | 63 | Enable examples using ccmake or the following: |
| 66 | 64 | |
| 67 | 65 | cmake -Dexamples=ON .. |
| ... | ... | @@ -76,4 +74,25 @@ then: |
| 76 | 74 | ./test_redox |
| 77 | 75 | |
| 78 | 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 | 72 | const int port = REDIS_DEFAULT_PORT, |
| 73 | 73 | std::function<void(int)> connection_callback = nullptr, |
| 74 | 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 | 82 | const std::string& path, |
| 83 | 83 | std::function<void(int)> connection_callback, |
| 84 | 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 | 36 | const int port = REDIS_DEFAULT_PORT, |
| 37 | 37 | std::function<void(int)> connection_callback = nullptr, |
| 38 | 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 | 46 | const std::string& path, |
| 47 | 47 | std::function<void(int)> connection_callback, |
| 48 | 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