Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Turbo码先生
redis
提交
74a64049
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,发现更多精彩内容 >>
提交
74a64049
编写于
5月 01, 2011
作者:
A
antirez
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'unstable' of github.com:antirez/redis into unstable
上级
5cbe90db
2f52dac9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
80 addition
and
7 deletion
+80
-7
src/cluster.c
src/cluster.c
+62
-0
src/db.c
src/db.c
+7
-3
src/networking.c
src/networking.c
+10
-4
src/redis.h
src/redis.h
+1
-0
未找到文件。
src/cluster.c
浏览文件 @
74a64049
...
...
@@ -1168,6 +1168,44 @@ void clusterCommand(redisClient *c) {
clusterUpdateState
();
clusterSaveConfigOrDie
();
addReply
(
c
,
shared
.
ok
);
}
else
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"setslot"
)
&&
c
->
argc
>=
4
)
{
/* SETSLOT 10 MIGRATING <instance ID> */
/* SETSLOT 10 IMPORTING <instance ID> */
/* SETSLOT 10 STABLE */
long
long
aux
;
unsigned
int
slot
;
clusterNode
*
n
;
if
(
getLongLongFromObjectOrReply
(
c
,
c
->
argv
[
2
],
&
aux
,
NULL
)
!=
REDIS_OK
)
return
;
if
(
aux
<
0
||
aux
>=
REDIS_CLUSTER_SLOTS
)
{
addReplyError
(
c
,
"Slot out of range"
);
return
;
}
slot
=
(
unsigned
int
)
aux
;
if
(
server
.
cluster
.
slots
[
slot
]
!=
server
.
cluster
.
myself
)
{
addReplyErrorFormat
(
c
,
"I'm not the owner of hash slot %u"
,
slot
);
return
;
}
if
(
!
strcasecmp
(
c
->
argv
[
3
]
->
ptr
,
"migrating"
)
&&
c
->
argc
==
5
)
{
if
((
n
=
clusterLookupNode
(
c
->
argv
[
4
]
->
ptr
))
==
NULL
)
{
addReplyErrorFormat
(
c
,
"I don't know about node %s"
,
(
char
*
)
c
->
argv
[
4
]
->
ptr
);
return
;
}
server
.
cluster
.
migrating_slots_to
[
slot
]
=
n
;
}
else
if
(
!
strcasecmp
(
c
->
argv
[
3
]
->
ptr
,
"importing"
)
&&
c
->
argc
==
5
)
{
if
((
n
=
clusterLookupNode
(
c
->
argv
[
4
]
->
ptr
))
==
NULL
)
{
addReplyErrorFormat
(
c
,
"I don't know about node %s"
,
(
char
*
)
c
->
argv
[
3
]
->
ptr
);
return
;
}
server
.
cluster
.
importing_slots_from
[
slot
]
=
n
;
}
else
if
(
!
strcasecmp
(
c
->
argv
[
3
]
->
ptr
,
"stable"
)
&&
c
->
argc
==
4
)
{
server
.
cluster
.
importing_slots_from
[
slot
]
=
NULL
;
}
else
{
addReplyError
(
c
,
"Invalid CLUSTER SETSLOT action or number of arguments"
);
}
}
else
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"info"
)
&&
c
->
argc
==
2
)
{
char
*
statestr
[]
=
{
"ok"
,
"fail"
,
"needhelp"
};
int
slots_assigned
=
0
,
slots_ok
=
0
,
slots_pfail
=
0
,
slots_fail
=
0
;
...
...
@@ -1205,6 +1243,30 @@ void clusterCommand(redisClient *c) {
(
unsigned
long
)
sdslen
(
info
)));
addReplySds
(
c
,
info
);
addReply
(
c
,
shared
.
crlf
);
}
else
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"keyslot"
)
&&
c
->
argc
==
3
)
{
sds
key
=
c
->
argv
[
2
]
->
ptr
;
addReplyLongLong
(
c
,
keyHashSlot
(
key
,
sdslen
(
key
)));
}
else
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"getkeysinslot"
)
&&
c
->
argc
==
4
)
{
long
long
maxkeys
,
slot
;
unsigned
int
numkeys
,
j
;
robj
**
keys
;
if
(
getLongLongFromObjectOrReply
(
c
,
c
->
argv
[
2
],
&
slot
,
NULL
)
!=
REDIS_OK
)
return
;
if
(
getLongLongFromObjectOrReply
(
c
,
c
->
argv
[
3
],
&
maxkeys
,
NULL
)
!=
REDIS_OK
)
return
;
if
(
slot
<
0
||
slot
>=
REDIS_CLUSTER_SLOTS
||
maxkeys
<
0
||
maxkeys
>
1024
*
1024
)
{
addReplyError
(
c
,
"Invalid slot or number of keys"
);
return
;
}
keys
=
zmalloc
(
sizeof
(
robj
*
)
*
maxkeys
);
numkeys
=
GetKeysInSlot
(
slot
,
keys
,
maxkeys
);
addReplyMultiBulkLen
(
c
,
numkeys
);
for
(
j
=
0
;
j
<
numkeys
;
j
++
)
addReplyBulk
(
c
,
keys
[
j
]);
zfree
(
keys
);
}
else
{
addReplyError
(
c
,
"Wrong CLUSTER subcommand or number of arguments"
);
}
...
...
src/db.c
浏览文件 @
74a64049
...
...
@@ -725,14 +725,18 @@ void SlotToKeyDel(robj *key) {
zslDelete
(
server
.
cluster
.
slots_to_keys
,
hashslot
,
key
);
}
robj
*
GetKeyInSlot
(
unsigned
int
hashslo
t
)
{
unsigned
int
GetKeysInSlot
(
unsigned
int
hashslot
,
robj
**
keys
,
unsigned
int
coun
t
)
{
zskiplistNode
*
n
;
zrangespec
range
;
int
j
=
0
;
range
.
min
=
range
.
max
=
hashslot
;
range
.
minex
=
range
.
maxex
=
0
;
n
=
zslFirstInRange
(
server
.
cluster
.
slots_to_keys
,
range
);
if
(
!
n
)
return
NULL
;
return
n
->
obj
;
while
(
n
&&
n
->
score
==
hashslot
&&
count
--
)
{
keys
[
j
++
]
=
n
->
obj
;
n
=
n
->
level
[
0
].
forward
;
}
return
j
;
}
src/networking.c
浏览文件 @
74a64049
...
...
@@ -526,10 +526,16 @@ void freeClient(redisClient *c) {
* close the connection with all our slaves if we have any, so
* when we'll resync with the master the other slaves will sync again
* with us as well. Note that also when the slave is not connected
* to the master it will keep refusing connections by other slaves. */
while
(
listLength
(
server
.
slaves
))
{
ln
=
listFirst
(
server
.
slaves
);
freeClient
((
redisClient
*
)
ln
->
value
);
* to the master it will keep refusing connections by other slaves.
*
* We do this only if server.masterhost != NULL. If it is NULL this
* means the user called SLAVEOF NO ONE and we are freeing our
* link with the master, so no need to close link with slaves. */
if
(
server
.
masterhost
!=
NULL
)
{
while
(
listLength
(
server
.
slaves
))
{
ln
=
listFirst
(
server
.
slaves
);
freeClient
((
redisClient
*
)
ln
->
value
);
}
}
}
/* Release memory */
...
...
src/redis.h
浏览文件 @
74a64049
...
...
@@ -1065,6 +1065,7 @@ long long emptyDb();
int
selectDb
(
redisClient
*
c
,
int
id
);
void
signalModifiedKey
(
redisDb
*
db
,
robj
*
key
);
void
signalFlushedDb
(
int
dbid
);
unsigned
int
GetKeysInSlot
(
unsigned
int
hashslot
,
robj
**
keys
,
unsigned
int
count
);
/* API to get key arguments from commands */
#define REDIS_GETKEYS_ALL 0
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录