Skip to content

Commit 49805bb

Browse files
committed
includes moved to include, sources moved to src
1 parent 63c7529 commit 49805bb

32 files changed

+121
-957
lines changed

CMakeLists.txt

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ set(VENDOR_LIBRARY_DIR ${VENDOR_DIR}/lib ${VENDOR_DIR}/lib64)
8989

9090
# find_path(TACOPIE_INCLUDE_DIR tacopie/tacopie PATHS ${PROJECT_SOURCE_DIR}/tacopie/includes/)
9191
# find_library(TACOPIE_LIBRARY tacopie)
92-
set(CPP_REDIS_INCLUDES ${PROJECT_SOURCE_DIR}/includes)
92+
set(CPP_REDIS_INCLUDES ${PROJECT_SOURCE_DIR}/include)
9393

9494
if (NOT USE_CUSTOM_TCP_CLIENT)
9595
set(VENDOR_INCLUDES ${VENDOR_INCLUDES} ${TACOPIE_INCLUDE_DIR})
@@ -104,29 +104,43 @@ include_directories(${CPP_REDIS_INCLUDES} ${VENDOR_INCLUDES} /usr/include/c++/6)
104104
###
105105
# sources
106106
###
107-
set(SRC_DIRS "sources"
108-
"sources/builders"
109-
"sources/core"
110-
"sources/misc"
111-
"sources/network"
112-
"includes/cpp_redis"
113-
"includes/cpp_redis/builders"
114-
"includes/cpp_redis/core"
115-
"includes/cpp_redis/misc"
116-
"includes/cpp_redis/network")
117-
118-
foreach (dir ${SRC_DIRS})
107+
# set(SRC_DIRS "src"
108+
# "src/cpp_redis/builders"
109+
# "src/cpp_redis/core"
110+
# "src/cpp_redis/misc"
111+
# "src/cpp_redis/network"
112+
# )
113+
114+
# set(INCLUDE_DIRS "includes/cpp_redis"
115+
# "includes/cpp_redis/builders"
116+
# "includes/cpp_redis/core"
117+
# "includes/cpp_redis/misc"
118+
# "includes/cpp_redis/network")
119+
120+
121+
#foreach (dir ${SRC_DIRS})
119122
# get directory sources and headers
120-
file(GLOB s_${dir} "${dir}/*.cpp")
121-
file(GLOB h_${dir} "${dir}/*.hpp")
122-
file(GLOB i_${dir} "${dir}/*.ipp")
123+
# file(GLOB s_${dir} "${dir}/*.cpp")
124+
# file(GLOB h_${dir} "${dir}/*.hpp")
125+
# file(GLOB i_${dir} "${dir}/*.ipp")
123126

124127
# set sources
125-
set(SOURCES ${SOURCES} ${s_${dir}} ${h_${dir}} ${i_${dir}})
126-
endforeach ()
128+
#set(SOURCES ${SOURCES} ${s_${dir}} ${h_${dir}} ${i_${dir}})
129+
#endforeach ()
130+
131+
file(GLOB_RECURSE INCLUDES
132+
LIST_DIRECTORIES TRUE
133+
RELATIVE "${PROJECT_SOURCE_DIR}" *.hpp *.ipp)
134+
135+
file(GLOB_RECURSE SOURCES
136+
LIST_DIRECTORIES TRUE
137+
RELATIVE "${PROJECT_SOURCE_DIR}" *.cpp)
138+
139+
set(SOURCES ${SOURCES} ${INCLUDES})
140+
127141
# filter tcp_client if no tacopie
128142
if (USE_CUSTOM_TCP_CLIENT)
129-
file(GLOB tacopie_cpp "sources/network/tcp_client.cpp")
143+
file(GLOB tacopie_cpp "sources/cpp_redis/network/tcp_client.cpp")
130144
file(GLOB tacopie_h "includes/cpp_redis/network/tcp_client.hpp")
131145
list(REMOVE_ITEM SOURCES ${tacopie_cpp} ${tacopie_h})
132146
endif ()

examples/cpp_redis_cluster.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@
3232
#endif //! _WIN32
3333

3434
int main(void) {
35-
std::string buffer = "131\r\n07c37dfeb235213a872192d90877d0cd55635b91 127.0.0.1:30004 slave e7d1eecce10fd6bb5eb35b9f99a514335d9ba9ca 0 1426238317239 4 connected\r";
36-
37-
35+
std::string buffer = "235\r\n07c37dfeb235213a872192d90877d0cd55635b91 127.0.0.1:30004 slave e7d1eecce10fd6bb5eb35b9f99a514335d9ba9ca 0 1426238317239 4 connected";
3836

3937
cpp_redis::builders::bulk_string_builder builder;
38+
builder << buffer;
39+
40+
buffer += "\n67ed2db8d677e59ec4a4cefb06858cf2a1a89fa1 127.0.0.1:30002 master - 0 1426238316232 2 connected 5461-10922\r";
41+
4042
builder << buffer;
4143

4244
buffer += "\n";

includes/cpp_redis/core/client.hpp renamed to include/cpp_redis/core/client.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <string>
3434
#include <vector>
3535

36+
#include <cpp_redis/core/reply.hpp>
3637
#include <cpp_redis/core/sentinel.hpp>
3738
#include <cpp_redis/core/types.hpp>
3839
#include <cpp_redis/helpers/variadic_template.hpp>

includes/cpp_redis/core/cluster.hpp renamed to include/cpp_redis/core/cluster.hpp

Lines changed: 52 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ enum class link_state_type { CONNECTED = 1, DISCONNECTED = 2 };
5454
using link_state_t = link_state_type;
5555

5656
class node {
57-
private:
57+
private:
5858
std::string m_ip;
5959
std::unique_ptr<client_t> m_client;
6060
int m_port;
@@ -66,23 +66,21 @@ class node {
6666
int config_epoch;
6767
link_state_t link_state;
6868
std::vector<slot_t> slots;
69+
6970
public:
7071
node(std::string ip, int port)
7172
: m_client(new client_t()), m_ip(ip), m_port(port) {}
7273

7374
const void set_address(std::string &address) {
7475
int sep = address.find_first_of(':');
75-
m_ip = address.substr (0,sep);
76+
m_ip = address.substr(0, sep);
7677
std::cout << "ip: " << m_ip << std::endl;
77-
std::string v = address.substr(sep,address.length());
78+
std::string v = address.substr(sep, address.length());
7879
std::cout << "lksdjf " << v << std::endl;
7980
m_port = 8000;
80-
//m_port = std::stoi(address.substr(sep,address.length())); }
81-
81+
// m_port = std::stoi(address.substr(sep,address.length())); }
8282
}
83-
const int get_port() {
84-
return m_port;
85-
}
83+
const int get_port() { return m_port; }
8684
};
8785

8886
using node_t = node;
@@ -101,66 +99,66 @@ struct cluster_slot {
10199
};
102100

103101
std::istream &operator>>(std::istream &is, std::pair<std::string, node_t> &t) {
104-
// Read string to space
105-
getline( is >> std::ws, t.first, ' ' );
106-
107-
int i = 1;
108-
while ((is.peek()!='\n') && (is>>std::ws)) {
109-
std::string temp;
110-
getline( is >> std::ws, temp, ' ' );
111-
switch (i)
112-
{
113-
case 1:
114-
t.second.set_address(temp);
115-
break;
116-
case 2: // flags
117-
std::cout << temp << std::endl;
118-
break;
119-
case 3: // master
120-
std::cout << temp << std::endl;
121-
break;
122-
default:
123-
std::cout << temp << std::endl;
124-
break;
125-
}
126-
i++;
102+
// Read string to space
103+
getline(is >> std::ws, t.first, ' ');
104+
105+
int i = 1;
106+
while ((is.peek() != '\n') && (is >> std::ws)) {
107+
std::string temp;
108+
getline(is >> std::ws, temp, ' ');
109+
switch (i) {
110+
case 1:
111+
t.second.set_address(temp);
112+
break;
113+
case 2: // flags
114+
std::cout << temp << std::endl;
115+
break;
116+
case 3: // master
117+
std::cout << temp << std::endl;
118+
break;
119+
default:
120+
std::cout << temp << std::endl;
121+
break;
127122
}
128-
129-
// Read formatted input; ignore everything else to end of line
130-
// is >> t.avg;
131-
// is.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
132-
133-
return is;
123+
i++;
124+
}
125+
126+
// Read formatted input; ignore everything else to end of line
127+
// is >> t.avg;
128+
// is.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
129+
130+
return is;
134131
}
135132

136133
std::istream &operator>>(std::istream &is, node_map_t &data) {
137-
data.clear();
138-
std::pair<std::string, node_t> rec = {"", node_t("",0)};
139-
while (is >> rec)
140-
data.insert({rec.first, std::shared_ptr<node_t>(&rec.second)});
141-
return is;
134+
data.clear();
135+
std::pair<std::string, node_t> rec = {"", node_t("", 0)};
136+
while (is >> rec)
137+
data.insert({rec.first, std::shared_ptr<node_t>(&rec.second)});
138+
return is;
142139
}
143140

144141
class cluster_client {
145142
private:
146-
node_map_t m_nodes;
147-
std::vector<std::string> m_slots;
148-
std::pair<std::string, int> m_address;
143+
node_map_t m_nodes;
144+
std::vector<std::string> m_slots;
145+
std::pair<std::string, int> m_address;
146+
149147
public:
150148
cluster_client(const std::string ip, int port) : m_address({ip, port}) {}
151149

152150
void connect() {
153-
client_t rclient;
151+
client_t rclient;
154152

155-
rclient.connect(m_address.first, m_address.second);
153+
rclient.connect(m_address.first, m_address.second);
156154

157-
rclient.cluster_nodes([&](const reply_t &repl) {
158-
if (!repl.is_error() && repl.is_bulk_string()) {
159-
node_map_t nm;
160-
std::istringstream(repl.as_string()) >> nm;
161-
}
162-
});
163-
//m_nodes.emplace()
155+
rclient.cluster_nodes([&](const reply_t &repl) {
156+
if (!repl.is_error() && repl.is_bulk_string()) {
157+
node_map_t nm;
158+
std::istringstream(repl.as_string()) >> nm;
159+
}
160+
});
161+
// m_nodes.emplace()
164162
}
165163
};
166164
} // namespace cluster

includes/cpp_redis/core/consumer.hpp renamed to include/cpp_redis/core/consumer.hpp

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,6 @@ class consumer {
116116
void poll();
117117

118118
private:
119-
std::string m_stream;
120-
std::string m_name;
121-
std::string m_read_id;
122-
int m_block_sec;
123-
std::size_t m_max_concurrency;
124-
int m_read_count;
125119

126120
client_container_ptr_t m_client;
127121

@@ -135,6 +129,36 @@ class consumer {
135129

136130
bool is_ready = false;
137131
std::atomic_bool m_should_read_pending{true};
132+
private:
133+
//!
134+
//! the name of the stream
135+
//!
136+
std::string m_stream;
137+
138+
//!
139+
//! the name of this consumer group
140+
//!
141+
std::string m_name;
142+
143+
//!
144+
//! the topic ID
145+
//!
146+
std::string m_read_id;
147+
148+
//!
149+
//! number of milliseconds to block when polling
150+
//!
151+
int m_block_sec;
152+
153+
//!
154+
//! maximum number of worker threads
155+
//!
156+
std::size_t m_max_concurrency;
157+
158+
//!
159+
//! number of messages read
160+
//!
161+
int m_read_count;
138162
};
139163

140164
using consumer_t = consumer;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)