FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp_redis/src/cpp_redis/core/cluster.cpp at develop · cpp-redis/cpp_redis · GitHub
cpp-redis
cpp_redis
Repository navigation
Code
Issues
35
(35)
Pull requests
9
(9)
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp_redis
/
src
/
cpp_redis
/
core
/
cluster.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
66 lines (57 loc) · 1.84 KB
Breadcrumbs
cpp_redis
/
src
/
cpp_redis
/
core
/
cluster.cpp
Copy path
File metadata and controls
66 lines (57 loc) · 1.84 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#
include
<
cpp_redis/core/cluster.hpp
>
#
include
<
cpp_redis/misc/crc16.hpp
>
namespace
cpp_redis
{
void
cpp_redis::cluster::cluster_client::connect
() {
client_t
client;
m_is_first_connect =
true
;
client.
connect
(m_address.
first
, m_address.
second
);
client.
cluster_nodes
([
this
](
const
reply_t
&repl) {
std::cout <<
"
here
"
<< std::endl;
if
(!repl.
is_error
() && repl.
is_bulk_string
()) {
repl << m_nodes;
}
});
client.
sync_commit
();
for
(
const
auto
& node : m_nodes) {
auto
*nptr = node.
second
.
get
();
if
(nptr->
get_port
() == m_address.
second
) {
m_clients[node.
first
] = std::shared_ptr<
client_t
>(&client);
}
else
{
m_clients[node.
first
] = std::make_shared<
client_t
>();
m_clients[node.
first
]->
connect
(nptr->
get_ip
(), nptr->
get_port
());
}
m_ranges[node.
first
] = nptr->
get_range
();
}
//
m_nodes.emplace()
}
cluster::cluster_client &
cluster::cluster_client::getset
(
const
string_t
&key,
const
string_t
&val,
const
reply_callback_t
&reply_callback) {
auto
c =
get_client
(key);
c->
getset
(key, val, reply_callback);
c->
sync_commit
();
return
*
this
;
}
void
cluster::node::set_address
(
string_t
&address) {
int
sep = address.
find_first_of
(
'
:
'
);
m_ip = address.
substr
(
0
, sep);
string_t
v = address.
substr
(sep, address.
length
());
m_port =
std::stoi
(address.
substr
(sep+
1
,address.
length
()));
}
void
cluster::node::set_type
(
string_t
&type_str) {
if
(type_str ==
"
slave
"
) {
m_type = node_type::slave;
}
else
{
m_type = node_type::master;
}
}
void
cluster::node::set_range
(
string_t
&range_str) {
if
(m_type == node_type::master) {
int
sep = range_str.
find_first_of
(
'
-
'
);
auto
f = range_str.
substr
(
0
, sep);
m_slot.
first
=
std::stoi
(f);
auto
s = range_str.
substr
(sep+
1
, range_str.
length
());
m_slot.
second
=
std::stoi
(s);
}
}
}
//
namespace cpp_redis
Back
|
FazBrowse Home
|
New Git URL