Skip to content

Commit 6fdd1ae

Browse files
committed
type cleanup
clean up file naming for types
1 parent f62146c commit 6fdd1ae

File tree

10 files changed

+317
-73
lines changed

10 files changed

+317
-73
lines changed

include/cpp_redis/core/client.hpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#include <cpp_redis/network/redis_connection.hpp>
4242
#include <cpp_redis/network/tcp_client_iface.hpp>
4343

44+
#include <cpp_redis/misc/deprecated.hpp>
45+
4446
#include <cpp_redis/impl/reply.ipp>
4547

4648
#define __METER "m"
@@ -815,23 +817,29 @@ class client {
815817

816818
future_reply_t echo(const std::string &msg);
817819

818-
client &eval(const std::string &script, int numkeys,
819-
const std::vector<std::string> &keys,
820-
const std::vector<std::string> &args,
821-
const reply_callback_t &reply_callback);
820+
client &eval(const std::string &script, const std::vector<std::string> &keys,
821+
const std::vector<std::string> &args, const reply_callback_t &reply_callback);
822822

823-
future_reply_t eval(const std::string &script, int numkeys,
824-
const std::vector<std::string> &keys,
825-
const std::vector<std::string> &args);
823+
DEPRECATED client &eval(const std::string &script, int numkeys, const std::vector<std::string> &keys,
824+
const std::vector<std::string> &args, const reply_callback_t &reply_callback);
826825

827-
client &evalsha(const std::string &sha1, int numkeys,
828-
const std::vector<std::string> &keys,
829-
const std::vector<std::string> &args,
830-
const reply_callback_t &reply_callback);
826+
future_reply_t eval(const std::string &script, const std::vector<std::string> &keys,
827+
const std::vector<std::string> &args);
828+
829+
DEPRECATED future_reply_t eval(const std::string &script, int numkeys, const std::vector<std::string> &keys,
830+
const std::vector<std::string> &args);
831831

832-
future_reply_t evalsha(const std::string &sha1, int numkeys,
833-
const std::vector<std::string> &keys,
834-
const std::vector<std::string> &args);
832+
client &evalsha(const std::string &sha1, const std::vector<std::string> &keys,
833+
const std::vector<std::string> &args, const reply_callback_t &reply_callback);
834+
835+
DEPRECATED client &evalsha(const std::string &sha1, int numkeys, const std::vector<std::string> &keys,
836+
const std::vector<std::string> &args, const reply_callback_t &reply_callback);
837+
838+
future_reply_t evalsha(const std::string &sha1, const std::vector<std::string> &keys,
839+
const std::vector<std::string> &args);
840+
841+
DEPRECATED future_reply_t evalsha(const std::string &sha1, int numkeys, const std::vector<std::string> &keys,
842+
const std::vector<std::string> &args);
835843

836844
client &exec(const reply_callback_t &reply_callback);
837845

@@ -2694,6 +2702,8 @@ class client {
26942702

26952703
using client_t = client;
26962704

2705+
using client_ptr_t = std::unique_ptr<client_t>;
2706+
26972707
} // namespace cpp_redis
26982708

26992709
#include <cpp_redis/impl/client.ipp>

include/cpp_redis/core/cluster.hpp

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,29 +53,32 @@ enum class link_state_type { CONNECTED = 1, DISCONNECTED = 2 };
5353

5454
using link_state_t = link_state_type;
5555

56+
using slot_vec_t = std::vector<slot_t>;
57+
5658
class node {
5759
private:
58-
std::string m_ip;
59-
std::unique_ptr<client_t> m_client;
60+
string_t m_ip;
61+
client_ptr_t m_client;
6062
int m_port;
61-
// optional_t<std::string> master;
63+
// optional_t<string_t> master;
6264
int ping_sent;
6365
int ping_recv;
64-
// AKA version. Pick the highest version
65-
// when multiple nodes claim the same hash slot
66+
67+
//! AKA version. Pick the highest version
68+
//! when multiple nodes claim the same hash slot
6669
int config_epoch;
6770
link_state_t link_state;
68-
std::vector<slot_t> slots;
71+
slot_vec_t slots;
6972

7073
public:
71-
node(std::string ip, int port)
74+
node(string_t ip, int port)
7275
: m_client(new client_t()), m_ip(ip), m_port(port) {}
7376

74-
const void set_address(std::string &address) {
77+
const void set_address(string_t &address) {
7578
int sep = address.find_first_of(':');
7679
m_ip = address.substr(0, sep);
7780
std::cout << "ip: " << m_ip << std::endl;
78-
std::string v = address.substr(sep, address.length());
81+
string_t v = address.substr(sep, address.length());
7982
std::cout << "lksdjf " << v << std::endl;
8083
m_port = 8000;
8184
// m_port = std::stoi(address.substr(sep,address.length())); }
@@ -85,7 +88,11 @@ class node {
8588

8689
using node_t = node;
8790

88-
using node_map_t = std::map<std::string, std::shared_ptr<node_t>>;
91+
using node_pair_t = std::pair<string_t, node_t>;
92+
93+
using node_ptr_t = std::shared_ptr<node_t>;
94+
95+
using node_map_t = hash_map_t<node_ptr_t>;
8996

9097
class node_slots {
9198
public:
@@ -98,13 +105,13 @@ struct cluster_slot {
98105
slot_t range;
99106
};
100107

101-
std::istream &operator>>(std::istream &is, std::pair<std::string, node_t> &t) {
108+
std::istream &operator>>(std::istream &is, node_pair_t &t) {
102109
// Read string to space
103110
getline(is >> std::ws, t.first, ' ');
104111

105112
int i = 1;
106113
while ((is.peek() != '\n') && (is >> std::ws)) {
107-
std::string temp;
114+
string_t temp;
108115
getline(is >> std::ws, temp, ' ');
109116
switch (i) {
110117
case 1:
@@ -132,7 +139,7 @@ std::istream &operator>>(std::istream &is, std::pair<std::string, node_t> &t) {
132139

133140
std::istream &operator>>(std::istream &is, node_map_t &data) {
134141
data.clear();
135-
std::pair<std::string, node_t> rec = {"", node_t("", 0)};
142+
node_pair_t rec = {"", node_t("", 0)};
136143
while (is >> rec)
137144
data.insert({rec.first, std::shared_ptr<node_t>(&rec.second)});
138145
return is;
@@ -141,11 +148,11 @@ std::istream &operator>>(std::istream &is, node_map_t &data) {
141148
class cluster_client {
142149
private:
143150
node_map_t m_nodes;
144-
std::vector<std::string> m_slots;
145-
std::pair<std::string, int> m_address;
151+
std::vector<string_t> m_slots;
152+
std::pair<string_t, int> m_address;
146153

147154
public:
148-
cluster_client(const std::string ip, int port) : m_address({ip, port}) {}
155+
cluster_client(const string_t ip, int port) : m_address({ip, port}) {}
149156

150157
void connect() {
151158
client_t rclient;

include/cpp_redis/core/sentinel.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
2222

23-
#pragma once
23+
#ifndef CPP_REDIS_CORE_SENTINEL_HPP_
24+
#define CPP_REDIS_CORE_SENTINEL_HPP_
2425

2526
#include <atomic>
2627
#include <condition_variable>
@@ -445,3 +446,5 @@ class sentinel {
445446
using sentinel_t = sentinel;
446447

447448
} // namespace cpp_redis
449+
450+
#endif // !CPP_REDIS_CORE_SENTINEL_HPP_
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
// The MIT License (MIT)
2+
//
3+
// Copyright (c) 2015-2017 Simon Ninon <simon.ninon@gmail.com>
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in
13+
// all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
#ifndef CPP_REDIS_CORE_TYPES_HPP
24+
#define CPP_REDIS_CORE_TYPES_HPP
25+
26+
#include <chrono>
27+
#include <cpp_redis/core/reply.hpp>
28+
#include <cpp_redis/impl/types.hpp>
29+
#include <ctime>
30+
#include <functional>
31+
#include <map>
32+
#include <string>
33+
#include <vector>
34+
35+
namespace cpp_redis {
36+
37+
//!
38+
//! @brief first array is the session name, second is ids
39+
//!
40+
using streams_t = std::pair<std::vector<string_t>, std::vector<string_t>>;
41+
42+
//!
43+
//! @brief Options
44+
//!
45+
typedef struct xread_options {
46+
streams_t Streams;
47+
int_t Count;
48+
int_t Block;
49+
} xread_options_t;
50+
51+
typedef struct xreadgroup_options {
52+
string_t Group;
53+
string_t Consumer;
54+
streams_t Streams;
55+
int_t Count;
56+
int_t Block;
57+
bool NoAck;
58+
} xreadgroup_options_t;
59+
60+
typedef struct range_options {
61+
string_t Start;
62+
string_t Stop;
63+
int_t Count;
64+
} range_options_t;
65+
66+
typedef struct xclaim_options {
67+
int_t Idle;
68+
std::time_t *Time;
69+
int_t RetryCount;
70+
bool Force;
71+
bool JustId;
72+
} xclaim_options_t;
73+
74+
typedef struct xpending_options {
75+
range_options_t Range;
76+
string_t Consumer;
77+
} xpending_options_t;
78+
79+
//!
80+
//! @brief Replies
81+
//!
82+
class xmessage : public virtual message_type {
83+
public:
84+
xmessage();
85+
86+
explicit xmessage(const reply_t &data);
87+
88+
friend std::ostream &operator<<(std::ostream &os, const xmessage &xm);
89+
};
90+
91+
using xmessage_t = xmessage;
92+
93+
class xstream {
94+
public:
95+
explicit xstream(const reply_t &data);
96+
97+
friend std::ostream &operator<<(std::ostream &os, const xstream &xs);
98+
99+
string_t Stream;
100+
std::vector<xmessage_t> Messages;
101+
};
102+
103+
using xstream_t = xstream;
104+
105+
class xinfo_reply {
106+
public:
107+
explicit xinfo_reply(const cpp_redis::reply_t &data);
108+
109+
int_t Length;
110+
int_t RadixTreeKeys;
111+
int_t RadixTreeNodes;
112+
int_t Groups;
113+
string_t LastGeneratedId;
114+
xmessage_t FirstEntry;
115+
xmessage_t LastEntry;
116+
};
117+
118+
class xstream_reply : public std::vector<xstream_t> {
119+
public:
120+
explicit xstream_reply(const reply_t &data);
121+
122+
friend std::ostream &operator<<(std::ostream &os, const xstream_reply &xs);
123+
124+
bool is_null() const {
125+
if (empty())
126+
return true;
127+
for (auto &v : *this) {
128+
if (v.Messages.empty())
129+
return true;
130+
}
131+
return false;
132+
}
133+
};
134+
135+
using xstream_reply_t = xstream_reply;
136+
137+
//!
138+
//! @brief Callbacks
139+
//!
140+
141+
//!
142+
//! acknowledgment callback called whenever a subscribe completes
143+
//! takes as parameter the int returned by the redis server (usually the number
144+
//! of channels you are subscribed to)
145+
//!
146+
//!
147+
using acknowledgement_callback_t = std::function<void(const int_t &)>;
148+
149+
//!
150+
//! high availability (re)connection states
151+
//! * dropped: connection has dropped
152+
//! * start: attempt of connection has started
153+
//! * sleeping: sleep between two attempts
154+
//! * ok: connected
155+
//! * failed: failed to connect
156+
//! * lookup failed: failed to retrieve master sentinel
157+
//! * stopped: stop to try to reconnect
158+
//!
159+
//!
160+
enum class connect_state {
161+
dropped,
162+
start,
163+
sleeping,
164+
ok,
165+
failed,
166+
lookup_failed,
167+
stopped
168+
};
169+
170+
using connect_state_t = connect_state;
171+
172+
//!
173+
//! connect handler, called whenever a new connection even occurred
174+
//!
175+
//!
176+
typedef std::function<void(const string_t &host, std::size_t port,
177+
connect_state status)>
178+
connect_callback_t;
179+
180+
using message_callback_t = std::function<void(const cpp_redis::message_type &)>;
181+
} // namespace cpp_redis
182+
183+
#endif // CPP_REDIS_TYPES_HPP

include/cpp_redis/cpp_redis

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
#include <cpp_redis/core/reply.hpp>
3434
#include <cpp_redis/misc/error.hpp>
3535
#include <cpp_redis/misc/logger.hpp>
36-
#include <cpp_redis/core/types.hpp>
36+
#include <cpp_redis/types/cluster_types.hpp>
37+
#include <cpp_redis/types/streams_types.hpp>
3738

3839
#endif
3940

0 commit comments

Comments
 (0)