Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Turbo码先生
redis
提交
513eb572
R
redis
项目概览
Turbo码先生
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
513eb572
编写于
6月 22, 2018
作者:
A
artix
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cluster Manager: auth support (-a argument).
上级
f3980bb9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
41 addition
and
19 deletion
+41
-19
src/redis-cli.c
src/redis-cli.c
+41
-19
未找到文件。
src/redis-cli.c
浏览文件 @
513eb572
...
...
@@ -79,10 +79,8 @@
"and port (ie. 120.0.0.1 7000)\n"
#define CLUSTER_MANAGER_MODE() (config.cluster_manager_command.name != NULL)
#define CLUSTER_MANAGER_MASTERS_COUNT(nodes, replicas) (nodes/(replicas + 1))
#define CLUSTER_MANAGER_NODE_CONNECT(n) \
(n->context = redisConnect(n->ip, n->port));
#define CLUSTER_MANAGER_COMMAND(n,...) \
(re
connectingRe
disCommand(n->context, __VA_ARGS__))
(redisCommand(n->context, __VA_ARGS__))
#define CLUSTER_MANAGER_NODE_ARRAY_FREE(array) zfree(array->alloc)
...
...
@@ -2171,6 +2169,31 @@ static int clusterManagerCheckRedisReply(clusterManagerNode *n,
return
1
;
}
static
int
clusterManagerNodeConnect
(
clusterManagerNode
*
node
)
{
if
(
node
->
context
)
redisFree
(
node
->
context
);
node
->
context
=
redisConnect
(
node
->
ip
,
node
->
port
);
if
(
node
->
context
->
err
)
{
fprintf
(
stderr
,
"Could not connect to Redis at "
);
fprintf
(
stderr
,
"%s:%d: %s
\n
"
,
node
->
ip
,
node
->
port
,
node
->
context
->
errstr
);
redisFree
(
node
->
context
);
node
->
context
=
NULL
;
return
0
;
}
/* Set aggressive KEEP_ALIVE socket option in the Redis context socket
* in order to prevent timeouts caused by the execution of long
* commands. At the same time this improves the detection of real
* errors. */
anetKeepAlive
(
NULL
,
node
->
context
->
fd
,
REDIS_CLI_KEEPALIVE_INTERVAL
);
if
(
config
.
auth
)
{
redisReply
*
reply
=
redisCommand
(
node
->
context
,
"AUTH %s"
,
config
.
auth
);
int
ok
=
clusterManagerCheckRedisReply
(
node
,
reply
,
NULL
);
if
(
reply
!=
NULL
)
freeReplyObject
(
reply
);
if
(
!
ok
)
return
0
;
}
return
1
;
}
static
void
clusterManagerRemoveNodeFromList
(
list
*
nodelist
,
clusterManagerNode
*
node
)
{
listIter
li
;
...
...
@@ -2718,6 +2741,7 @@ static redisReply *clusterManagerMigrateKeysInReply(clusterManagerNode *source,
char
**
argv
=
NULL
;
size_t
*
argv_len
=
NULL
;
int
c
=
(
replace
?
8
:
7
);
if
(
config
.
auth
)
c
+=
2
;
size_t
argc
=
c
+
reply
->
elements
;
size_t
i
,
offset
=
6
;
// Keys Offset
argv
=
zcalloc
(
argc
*
sizeof
(
char
*
));
...
...
@@ -2743,6 +2767,14 @@ static redisReply *clusterManagerMigrateKeysInReply(clusterManagerNode *source,
argv_len
[
offset
]
=
7
;
offset
++
;
}
if
(
config
.
auth
)
{
argv
[
offset
]
=
"AUTH"
;
argv_len
[
offset
]
=
4
;
offset
++
;
argv
[
offset
]
=
config
.
auth
;
argv_len
[
offset
]
=
strlen
(
config
.
auth
);
offset
++
;
}
argv
[
offset
]
=
"KEYS"
;
argv_len
[
offset
]
=
4
;
offset
++
;
...
...
@@ -3146,12 +3178,7 @@ cleanup:
* Warning: if something goes wrong, it will free the starting node before
* returning 0. */
static
int
clusterManagerLoadInfoFromNode
(
clusterManagerNode
*
node
,
int
opts
)
{
if
(
node
->
context
==
NULL
)
CLUSTER_MANAGER_NODE_CONNECT
(
node
);
if
(
node
->
context
->
err
)
{
fprintf
(
stderr
,
"Could not connect to Redis at "
);
fprintf
(
stderr
,
"%s:%d: %s
\n
"
,
node
->
ip
,
node
->
port
,
node
->
context
->
errstr
);
if
(
node
->
context
==
NULL
&&
!
clusterManagerNodeConnect
(
node
))
{
freeClusterManagerNode
(
node
);
return
0
;
}
...
...
@@ -3187,9 +3214,8 @@ static int clusterManagerLoadInfoFromNode(clusterManagerNode *node, int opts) {
while
((
ln
=
listNext
(
&
li
))
!=
NULL
)
{
clusterManagerNode
*
friend
=
ln
->
value
;
if
(
!
friend
->
ip
||
!
friend
->
port
)
goto
invalid_friend
;
if
(
!
friend
->
context
)
CLUSTER_MANAGER_NODE_CONNECT
(
friend
);
if
(
friend
->
context
->
err
)
goto
invalid_friend
;
if
(
!
friend
->
context
&&
!
clusterManagerNodeConnect
(
friend
))
goto
invalid_friend
;
e
=
NULL
;
if
(
clusterManagerNodeLoadInfo
(
friend
,
0
,
&
e
))
{
if
(
friend
->
flags
&
(
CLUSTER_MANAGER_FLAG_NOADDR
|
...
...
@@ -4184,10 +4210,7 @@ static int clusterManagerCommandCreate(int argc, char **argv) {
char
*
ip
=
addr
;
int
port
=
atoi
(
++
c
);
clusterManagerNode
*
node
=
clusterManagerNewNode
(
ip
,
port
);
CLUSTER_MANAGER_NODE_CONNECT
(
node
);
if
(
node
->
context
->
err
)
{
fprintf
(
stderr
,
"Could not connect to Redis at "
);
fprintf
(
stderr
,
"%s:%d: %s
\n
"
,
ip
,
port
,
node
->
context
->
errstr
);
if
(
!
clusterManagerNodeConnect
(
node
))
{
freeClusterManagerNode
(
node
);
return
0
;
}
...
...
@@ -4478,8 +4501,7 @@ static int clusterManagerCommandAddNode(int argc, char **argv) {
// Add the new node
clusterManagerNode
*
new_node
=
clusterManagerNewNode
(
ip
,
port
);
int
added
=
0
;
CLUSTER_MANAGER_NODE_CONNECT
(
new_node
);
if
(
new_node
->
context
->
err
)
{
if
(
!
clusterManagerNodeConnect
(
new_node
))
{
clusterManagerLogErr
(
"[ERR] Sorry, can't connect to node %s:%d
\n
"
,
ip
,
port
);
success
=
0
;
...
...
@@ -5225,7 +5247,7 @@ static int clusterManagerCommandCall(int argc, char **argv) {
listRewind
(
cluster_manager
.
nodes
,
&
li
);
while
((
ln
=
listNext
(
&
li
))
!=
NULL
)
{
clusterManagerNode
*
n
=
ln
->
value
;
if
(
!
n
->
context
)
CLUSTER_MANAGER_NODE_CONNECT
(
n
)
;
if
(
!
n
->
context
&&
!
clusterManagerNodeConnect
(
n
))
continue
;
redisReply
*
reply
=
NULL
;
redisAppendCommandArgv
(
n
->
context
,
argc
,
(
const
char
**
)
argv
,
argvlen
);
int
status
=
redisGetReply
(
n
->
context
,
(
void
**
)(
&
reply
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录