diff --git a/CMakeLists.txt b/CMakeLists.txt index 6eca8c0..e0a7e22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,23 +26,32 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC -Wall") # --------------------------------------------------------- set(SRC_DIR ${CMAKE_SOURCE_DIR}/src) +set(INC_DIR ${CMAKE_SOURCE_DIR}/include/redox) set(SRC_CORE ${SRC_DIR}/client.cpp ${SRC_DIR}/command.cpp - ${SRC_DIR}/subscriber.cpp -) + ${SRC_DIR}/subscriber.cpp) -set(SRC_LOGGER ${SRC_DIR}/utils/logger.cpp) +set(INC_CORE + ${INC_DIR}/client.hpp + ${INC_DIR}/subscriber.hpp + ${INC_DIR}/command.hpp) -set(SRC_ALL ${SRC_CORE} ${SRC_LOGGER}) +set(SRC_UTILS ${SRC_DIR}/utils/logger.cpp) +set(INC_UTILS ${INC_DIR}/utils/logger.hpp) -include_directories(${SRC_DIR}) +set(INC_WRAPPER ${CMAKE_SOURCE_DIR}/include/redox.hpp) + +set(SRC_ALL ${SRC_CORE} ${SRC_UTILS}) +set(INC_ALL ${INC_CORE} ${INC_UTILS} ${INC_WRAPPER}) + +include_directories(${INC_DIR} ${INC_DIR/redox}) # Dependent libraries - you may have to change # pthread to whatever C++11 threads depends on # for your platform -set(REDOX_LIB_DEPS hiredis ev pthread) +set(REDOX_LIB_DEPS ev pthread hiredis) # --------------------------------------------------------- # Library generation @@ -50,7 +59,7 @@ set(REDOX_LIB_DEPS hiredis ev pthread) if (lib) - add_library(redox SHARED ${SRC_ALL}) + add_library(redox SHARED ${SRC_ALL} ${INC_CORE}) target_link_libraries(redox ${REDOX_LIB_DEPS}) set_target_properties(redox @@ -139,17 +148,16 @@ endif() # Install (sudo make install) # --------------------------------------------------------- +set(CMAKE_INSTALL_PREFIX /usr/) + # Install the dynamic library to /usr/lib install(TARGETS redox DESTINATION lib) # Install the headers into /usr/include/redox -set(INC_CORE ${SRC_DIR}/client.hpp ${SRC_DIR}/subscriber.hpp) -set(INC_UTILS ${SRC_DIR}/utils/logger.hpp) install(FILES ${INC_CORE} DESTINATION include/redox) install(FILES ${INC_UTILS} DESTINATION include/redox/utils) -# Install the top-level header into /usr/include directly -set(INC_WRAPPER ${SRC_DIR}/redox.hpp) +# Install the top-level header directly into /usr/include install(FILES ${INC_WRAPPER} DESTINATION include) # --------------------------------------------------------- diff --git a/README.md b/README.md index 2e60aae..838b438 100644 --- a/README.md +++ b/README.md @@ -27,25 +27,23 @@ Redox is built on top of asynchronous API of hiredis, even for synchronous commands. There is no dependency on Boost or any other libraries. -### Performance Benchmarks +## Benchmarks Benchmarks are given by averaging the results of five trials of the speed tests in `examples/` on an AWS t2.medium instance running Ubuntu 14.04 (64-bit). Local Redis server, TCP connection: - * 100 commandLoop calls (`speed_test_async_multi`): **710,014 commands/s** - * One commandLoop call (`speed_test_async`): **195,159 commands/s** - * Looped commandSync call (`speed_test_sync`): **23,609 commands/s** + * 100 command loops (`speed_test_async_multi`): **710,014 commands/s** + * One command loop (`speed_test_async`): **195,159 commands/s** + * Looped synchronous command (`speed_test_sync`): **28,609 commands/s** -Results are comparable to that of an -average laptop. On a high-end laptop or PC, `speed_test_async_multi` usually tops -1 million commands per second. All results are slightly faster if over Unix sockets -than TCP. +Results are comparable to that of an average laptop. On a high-end machine, +`speed_test_async_multi` usually tops 1,000,000 commands/s. -## Install +## Installation Instructions provided are for Ubuntu, but all components are platform-independent. -### Build library from source +#### Build from source Get the build environment and dependencies: sudo apt-get install git cmake build-essential @@ -61,7 +59,7 @@ Install into system directories (optional): sudo make install -### Build examples and test suite +#### Build examples and test suite Enable examples using ccmake or the following: cmake -Dexamples=ON .. @@ -76,4 +74,25 @@ then: ./test_redox ## Tutorial -Coming soon. Take a look at `examples/` for now. +Here is a hello world program for redox: + + #include + #include "redox.hpp" + + int main(int argc, char* argv[]) { + + redox::Redox rdx = {"localhost", 6379}; + if(!rdx.connect()) return 1; + + rdx.set("hello", "world!"); + std::cout << "Hello, " << rdx.get("hello") << std::endl; + + rdx.disconnect(); + return 0; + } + +Compile and run: + + $ g++ hello.cpp -o hello -std=c++11 -lredox -lev -lhiredis + $ ./hello + Hello, world! diff --git a/src/redox.hpp b/include/redox.hpp index 07791b0..785e693 100644 --- a/src/redox.hpp +++ b/include/redox.hpp @@ -20,6 +20,6 @@ #pragma once -#include "client.hpp" -#include "command.hpp" -#include "subscriber.hpp" +#include "redox/client.hpp" +#include "redox/command.hpp" +#include "redox/subscriber.hpp" diff --git a/src/client.hpp b/include/redox/client.hpp index c00c48c..d5f7570 100644 --- a/src/client.hpp +++ b/include/redox/client.hpp @@ -72,7 +72,7 @@ public: const int port = REDIS_DEFAULT_PORT, std::function connection_callback = nullptr, std::ostream& log_stream = std::cout, - log::Level log_level = log::Info + log::Level log_level = log::Warning ); /** @@ -82,7 +82,7 @@ public: const std::string& path, std::function connection_callback, std::ostream& log_stream = std::cout, - log::Level log_level = log::Info + log::Level log_level = log::Warning ); /** diff --git a/src/command.hpp b/include/redox/command.hpp index 6c574a7..6c574a7 100644 --- a/src/command.hpp +++ b/include/redox/command.hpp diff --git a/src/subscriber.hpp b/include/redox/subscriber.hpp index 4eb3dbc..bbb444b 100644 --- a/src/subscriber.hpp +++ b/include/redox/subscriber.hpp @@ -36,7 +36,7 @@ public: const int port = REDIS_DEFAULT_PORT, std::function connection_callback = nullptr, std::ostream& log_stream = std::cout, - log::Level log_level = log::Info + log::Level log_level = log::Warning ); /** @@ -46,7 +46,7 @@ public: const std::string& path, std::function connection_callback, std::ostream& log_stream = std::cout, - log::Level log_level = log::Info + log::Level log_level = log::Warning ); /** diff --git a/src/utils/logger.hpp b/include/redox/utils/logger.hpp index 14b762b..14b762b 100644 --- a/src/utils/logger.hpp +++ b/include/redox/utils/logger.hpp diff --git a/src/client.cpp b/src/client.cpp index 3364b4e..a209f2a 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -19,7 +19,7 @@ */ #include -#include "redox.hpp" +#include "client.hpp" using namespace std; diff --git a/src/utils/logger.cpp b/src/utils/logger.cpp index d336460..6d3e8b6 100644 --- a/src/utils/logger.cpp +++ b/src/utils/logger.cpp @@ -5,7 +5,7 @@ * http://vilipetek.com/2014/04/17/thread-safe-simple-logger-in-c11/ */ -#include "logger.hpp" +#include "utils/logger.hpp" #include #include