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

Commit

Permalink
Merge pull request #8 from Cylix/remove_boost_asio_dependency
Browse files Browse the repository at this point in the history
Remove boost asio dependency
  • Loading branch information
Cylix authored Jul 22, 2016
2 parents 46417b4 + b7d313f commit ba48fc6
Show file tree
Hide file tree
Showing 44 changed files with 1,192 additions and 934 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ project(${PROJECT} CXX)
###
# compilation options
###
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -W -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -W -Wall -Wextra -O3")


###
Expand Down Expand Up @@ -60,7 +60,7 @@ endforeach()
# executable
###
add_library(${PROJECT} SHARED ${SOURCES})
target_link_libraries(${PROJECT} boost_system)
target_link_libraries(${PROJECT} pthread)
set_target_properties(${PROJECT}
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/target")
Expand All @@ -76,13 +76,13 @@ install (DIRECTORY ${CPP_REDIS_INCLUDES}/ DESTINATION include)
# examples
###
IF (BUILD_EXAMPLES)
add_subdirectory(examples)
add_subdirectory(examples)
ENDIF(BUILD_EXAMPLES)


###
# tests
###
IF (BUILD_TESTS)
add_subdirectory(tests)
add_subdirectory(tests)
ENDIF(BUILD_TESTS)
3 changes: 1 addition & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 Simon Ninon
Copyright (c) 2015-2016 Simon Ninon

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

39 changes: 21 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# cpp_redis
cpp_redis is C++11 Asynchronous Redis Client.

Network is based on Boost Asio library.
Network is based on raw sockets API. This, library is really lightweight.

## Requirements
* C++11
* Boost Asio

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

```cpp
#include "cpp_redis/cpp_redis"
#include <cpp_redis/cpp_redis>

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

void
sigint_handler(int) {
std::cout << "disconnected (sigint handler)" << std::endl;
client.disconnect();
std::cout << "disconnected (sigint handler)" << std::endl;
client.disconnect();
should_exit = true;
}

int
main(void) {
client.set_disconnection_handler([] (cpp_redis::redis_client&) {
std::cout << "client disconnected (disconnection handler)" << std::endl;
should_exit = true;
});
client.set_disconnection_handler([] (cpp_redis::redis_client&) {
std::cout << "client disconnected (disconnection handler)" << std::endl;
should_exit = true;
});

client.connect();
client.connect();

client.send({"SET", "hello", "world"});
client.send({"GET", "hello"}, [] (cpp_redis::reply& reply) {
std::cout << reply.as_string() << std::endl;
});
client.send({"SET", "hello", "world"}, [] (cpp_redis::reply& reply) {
std::cout << reply.as_string() << std::endl;
});
client.send({"GET", "hello"}, [] (cpp_redis::reply& reply) {
std::cout << reply.as_string() << std::endl;
});

signal(SIGINT, &sigint_handler);
while (not should_exit);
signal(SIGINT, &sigint_handler);
while (not should_exit);

return 0;
return 0;
}
```
Expand Down Expand Up @@ -133,7 +135,7 @@ Unsubscribe from the given pattern.
### Example
```cpp
#include "cpp_redis/cpp_redis"
#include <cpp_redis/cpp_redis>
#include <signal.h>
#include <iostream>
Expand All @@ -145,6 +147,7 @@ void
sigint_handler(int) {
std::cout << "disconnected (sigint handler)" << std::endl;
sub.disconnect();
should_exit = true;
}
int
Expand Down
31 changes: 17 additions & 14 deletions examples/redis_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,29 @@ cpp_redis::redis_client client;

void
sigint_handler(int) {
std::cout << "disconnected (sigint handler)" << std::endl;
client.disconnect();
std::cout << "disconnected (sigint handler)" << std::endl;
client.disconnect();
should_exit = true;
}

int
main(void) {
client.set_disconnection_handler([] (cpp_redis::redis_client&) {
std::cout << "client disconnected (disconnection handler)" << std::endl;
should_exit = true;
});
client.set_disconnection_handler([] (cpp_redis::redis_client&) {
std::cout << "client disconnected (disconnection handler)" << std::endl;
should_exit = true;
});

client.connect();
client.connect();

client.send({"SET", "hello", "world"});
client.send({"GET", "hello"}, [] (cpp_redis::reply& reply) {
std::cout << reply.as_string() << std::endl;
});
client.send({"SET", "hello", "world"}, [] (cpp_redis::reply& reply) {
std::cout << reply.as_string() << std::endl;
});
client.send({"GET", "hello"}, [] (cpp_redis::reply& reply) {
std::cout << reply.as_string() << std::endl;
});

signal(SIGINT, &sigint_handler);
while (not should_exit);
signal(SIGINT, &sigint_handler);
while (not should_exit);

return 0;
return 0;
}
33 changes: 17 additions & 16 deletions examples/redis_subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,29 @@ cpp_redis::redis_subscriber sub;

void
sigint_handler(int) {
std::cout << "disconnected (sigint handler)" << std::endl;
sub.disconnect();
std::cout << "disconnected (sigint handler)" << std::endl;
sub.disconnect();
should_exit = true;
}

int
main(void) {
sub.set_disconnection_handler([] (cpp_redis::redis_subscriber&) {
std::cout << "sub disconnected (disconnection handler)" << std::endl;
should_exit = true;
});
sub.set_disconnection_handler([] (cpp_redis::redis_subscriber&) {
std::cout << "sub disconnected (disconnection handler)" << std::endl;
should_exit = true;
});

sub.connect();
sub.connect();

sub.subscribe("some_chan", [] (const std::string& chan, const std::string& msg) {
std::cout << "MESSAGE " << chan << ": " << msg << std::endl;
});
sub.psubscribe("*", [] (const std::string& chan, const std::string& msg) {
std::cout << "PMESSAGE " << chan << ": " << msg << std::endl;
});
sub.subscribe("some_chan", [] (const std::string& chan, const std::string& msg) {
std::cout << "MESSAGE " << chan << ": " << msg << std::endl;
});
sub.psubscribe("*", [] (const std::string& chan, const std::string& msg) {
std::cout << "PMESSAGE " << chan << ": " << msg << std::endl;
});

signal(SIGINT, &sigint_handler);
while (not should_exit);
signal(SIGINT, &sigint_handler);
while (not should_exit);

return 0;
return 0;
}
34 changes: 17 additions & 17 deletions includes/cpp_redis/builders/array_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@ namespace builders {

class array_builder : public builder_iface {
public:
//! ctor & dtor
array_builder(void);
~array_builder(void) = default;
//! ctor & dtor
array_builder(void);
~array_builder(void) = default;

//! copy ctor & assignment operator
array_builder(const array_builder&) = delete;
array_builder& operator=(const array_builder&) = delete;
//! copy ctor & assignment operator
array_builder(const array_builder&) = delete;
array_builder& operator=(const array_builder&) = delete;

public:
//! builder_iface impl
builder_iface& operator<<(std::string&);
bool reply_ready(void) const;
reply get_reply(void) const;
//! builder_iface impl
builder_iface& operator<<(std::string&);
bool reply_ready(void) const;
reply get_reply(void) const;

private:
bool fetch_array_size(std::string& buffer);
bool build_row(std::string& buffer);
bool fetch_array_size(std::string& buffer);
bool build_row(std::string& buffer);

private:
integer_builder m_int_builder;
unsigned int m_array_size;
integer_builder m_int_builder;
unsigned int m_array_size;

std::unique_ptr<builder_iface> m_current_builder;
std::unique_ptr<builder_iface> m_current_builder;

bool m_reply_ready;
replies::array_reply m_reply;
bool m_reply_ready;
replies::array_reply m_reply;
};

} //! builders
Expand Down
16 changes: 8 additions & 8 deletions includes/cpp_redis/builders/builder_iface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ namespace builders {
//! interface inherited by all builders
class builder_iface {
public:
virtual ~builder_iface(void) = default;
virtual ~builder_iface(void) = default;

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

//! return whether the reply could be built
virtual bool reply_ready(void) const = 0;
//! return whether the reply could be built
virtual bool reply_ready(void) const = 0;

//! return reply object
virtual reply get_reply(void) const = 0;
//! return reply object
virtual reply get_reply(void) const = 0;
};

} //! builders
Expand Down
46 changes: 23 additions & 23 deletions includes/cpp_redis/builders/bulk_string_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,39 @@ namespace builders {

class bulk_string_builder : public builder_iface {
public:
//! ctor & dtor
bulk_string_builder(void);
~bulk_string_builder(void) = default;
//! ctor & dtor
bulk_string_builder(void);
~bulk_string_builder(void) = default;

//! copy ctor & assignment operator
bulk_string_builder(const bulk_string_builder&) = delete;
bulk_string_builder& operator=(const bulk_string_builder&) = delete;
//! copy ctor & assignment operator
bulk_string_builder(const bulk_string_builder&) = delete;
bulk_string_builder& operator=(const bulk_string_builder&) = delete;

public:
//! builder_iface impl
builder_iface& operator<<(std::string&);
bool reply_ready(void) const;
reply get_reply(void) const;
//! builder_iface impl
builder_iface& operator<<(std::string&);
bool reply_ready(void) const;
reply get_reply(void) const;

//! getter
const std::string& get_bulk_string(void) const;
bool is_null(void) const;
//! getter
const std::string& get_bulk_string(void) const;
bool is_null(void) const;

private:
void build_reply(void);
bool fetch_size(std::string& str);
void fetch_str(std::string& str);
void build_reply(void);
bool fetch_size(std::string& str);
void fetch_str(std::string& str);

private:
//! used to get bulk string size
integer_builder m_int_builder;
//! used to get bulk string size
integer_builder m_int_builder;

int m_str_size;
std::string m_str;
bool m_is_null;
int m_str_size;
std::string m_str;
bool m_is_null;

bool m_reply_ready;
replies::bulk_string_reply m_reply;
bool m_reply_ready;
replies::bulk_string_reply m_reply;
};

} //! builders
Expand Down
Loading

0 comments on commit ba48fc6

Please sign in to comment.