Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hanoi2005
redis
提交
9791f0f8
R
redis
项目概览
hanoi2005
/
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,发现更多精彩内容 >>
提交
9791f0f8
编写于
3月 23, 2011
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
new preloading implemented, still EXEC not handled correctly, everything to test
上级
03af999c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
98 addition
and
16 deletion
+98
-16
src/db.c
src/db.c
+72
-0
src/dscache.c
src/dscache.c
+9
-5
src/redis.c
src/redis.c
+1
-1
src/redis.h
src/redis.h
+16
-10
未找到文件。
src/db.c
浏览文件 @
9791f0f8
...
...
@@ -616,3 +616,75 @@ void persistCommand(redisClient *c) {
}
}
}
/* -----------------------------------------------------------------------------
* API to get key arguments from commands
* ---------------------------------------------------------------------------*/
int
*
getKeysUsingCommandTable
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
)
{
int
j
,
i
=
0
,
last
,
*
keys
;
REDIS_NOTUSED
(
argv
);
if
(
cmd
->
firstkey
==
0
)
{
*
numkeys
=
0
;
return
NULL
;
}
last
=
cmd
->
lastkey
;
if
(
last
<
0
)
last
=
argc
+
last
;
keys
=
zmalloc
(
sizeof
(
int
)
*
((
last
-
cmd
->
firstkey
)
+
1
));
for
(
j
=
cmd
->
firstkey
;
j
<=
last
;
j
+=
cmd
->
keystep
)
{
redisAssert
(
j
<
argc
);
keys
[
i
]
=
j
;
}
return
keys
;
}
int
*
getKeysFromCommand
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
,
int
flags
)
{
if
(
cmd
->
getkeys_proc
)
{
return
cmd
->
getkeys_proc
(
cmd
,
argv
,
argc
,
numkeys
,
flags
);
}
else
{
return
getKeysUsingCommandTable
(
cmd
,
argv
,
argc
,
numkeys
);
}
}
void
getKeysFreeResult
(
int
*
result
)
{
zfree
(
result
);
}
int
*
noPreloadGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
,
int
flags
)
{
if
(
flags
&
REDIS_GETKEYS_PRELOAD
)
{
*
numkeys
=
0
;
return
NULL
;
}
else
{
return
getKeysUsingCommandTable
(
cmd
,
argv
,
argc
,
numkeys
);
}
}
int
*
renameGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
,
int
flags
)
{
if
(
flags
&
REDIS_GETKEYS_PRELOAD
)
{
int
*
keys
=
zmalloc
(
sizeof
(
int
));
*
numkeys
=
1
;
keys
[
0
]
=
1
;
return
NULL
;
}
else
{
return
getKeysUsingCommandTable
(
cmd
,
argv
,
argc
,
numkeys
);
}
}
int
*
zunionInterGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
,
int
flags
)
{
int
i
,
num
,
*
keys
;
REDIS_NOTUSED
(
cmd
);
REDIS_NOTUSED
(
flags
);
num
=
atoi
(
argv
[
2
]
->
ptr
);
/* Sanity check. Don't return any key if the command is going to
* reply with syntax error. */
if
(
num
>
(
argc
-
3
))
{
*
numkeys
=
0
;
return
NULL
;
}
keys
=
zmalloc
(
num
);
for
(
i
=
0
;
i
<
num
;
i
++
)
keys
[
i
]
=
3
+
i
;
*
numkeys
=
num
;
return
keys
;
}
src/dscache.c
浏览文件 @
9791f0f8
...
...
@@ -903,6 +903,7 @@ int waitForSwappedKey(redisClient *c, robj *key) {
return
1
;
}
#if 0
/* Preload keys for any command with first, last and step values for
* the command keys prototype, as defined in the command table. */
void waitForMultipleSwappedKeys(redisClient *c, struct redisCommand *cmd, int argc, robj **argv) {
...
...
@@ -955,6 +956,7 @@ void execBlockClientOnSwappedKeys(redisClient *c, struct redisCommand *cmd, int
}
}
}
#endif
/* Is this client attempting to run a command against swapped keys?
* If so, block it ASAP, load the keys in background, then resume it.
...
...
@@ -967,11 +969,13 @@ void execBlockClientOnSwappedKeys(redisClient *c, struct redisCommand *cmd, int
* Return 1 if the client is marked as blocked, 0 if the client can
* continue as the keys it is going to access appear to be in memory. */
int
blockClientOnSwappedKeys
(
redisClient
*
c
,
struct
redisCommand
*
cmd
)
{
if
(
cmd
->
vm_preload_proc
!=
NULL
)
{
cmd
->
vm_preload_proc
(
c
,
cmd
,
c
->
argc
,
c
->
argv
);
}
else
{
waitForMultipleSwappedKeys
(
c
,
cmd
,
c
->
argc
,
c
->
argv
);
}
int
*
keyindex
,
numkeys
,
j
;
keyindex
=
getKeysFromCommand
(
cmd
,
c
->
argv
,
c
->
argc
,
&
numkeys
,
REDIS_GETKEYS_PRELOAD
);
for
(
j
=
0
;
j
<
numkeys
;
j
++
)
waitForSwappedKey
(
c
,
c
->
argv
[
keyindex
[
j
]]);
getKeysFreeResult
(
keyindex
);
#warning "Handle EXEC here"
/* If the client was blocked for at least one key, mark it as blocked. */
if
(
listLength
(
c
->
io_keys
))
{
...
...
src/redis.c
浏览文件 @
9791f0f8
...
...
@@ -168,7 +168,7 @@ struct redisCommand redisCommandTable[] = {
{
"lastsave"
,
lastsaveCommand
,
1
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"type"
,
typeCommand
,
2
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
{
"multi"
,
multiCommand
,
1
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"exec"
,
execCommand
,
1
,
REDIS_CMD_DENYOOM
,
execGetKeys
,
0
,
0
,
0
,
0
,
0
},
{
"exec"
,
execCommand
,
1
,
REDIS_CMD_DENYOOM
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"discard"
,
discardCommand
,
1
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"sync"
,
syncCommand
,
1
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"flushdb"
,
flushdbCommand
,
1
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
...
...
src/redis.h
浏览文件 @
9791f0f8
...
...
@@ -507,20 +507,19 @@ typedef struct pubsubPattern {
}
pubsubPattern
;
typedef
void
redisCommandProc
(
redisClient
*
c
);
typedef
void
redisVmPreloadProc
(
redisClient
*
c
,
struct
redisCommand
*
cmd
,
int
argc
,
robj
**
argv
);
typedef
int
*
redisGetKeysProc
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
,
int
flags
);
struct
redisCommand
{
char
*
name
;
redisCommandProc
*
proc
;
int
arity
;
int
flags
;
/* Use a function to determine which keys need to be loaded
* in the background prior to executing this command. Takes precedence
* over vm_firstkey and others, ignored when NULL */
redisVmPreloadProc
*
vm_preload_proc
;
/* Use a function to determine keys arguments in a command line.
* Used both for diskstore preloading and Redis Cluster. */
redisGetKeysProc
*
getkeys_proc
;
/* What keys should be loaded in background when calling this command? */
int
vm_
firstkey
;
/* The first argument that's a key (0 = no keys) */
int
vm_
lastkey
;
/* THe last argument that's a key */
int
vm_
keystep
;
/* The step between first and last key */
int
firstkey
;
/* The first argument that's a key (0 = no keys) */
int
lastkey
;
/* THe last argument that's a key */
int
keystep
;
/* The step between first and last key */
long
long
microseconds
,
calls
;
};
...
...
@@ -829,8 +828,6 @@ void freeIOJob(iojob *j);
void
queueIOJob
(
iojob
*
j
);
void
waitEmptyIOJobsQueue
(
void
);
void
processAllPendingIOJobs
(
void
);
void
zunionInterBlockClientOnSwappedKeys
(
redisClient
*
c
,
struct
redisCommand
*
cmd
,
int
argc
,
robj
**
argv
);
void
execBlockClientOnSwappedKeys
(
redisClient
*
c
,
struct
redisCommand
*
cmd
,
int
argc
,
robj
**
argv
);
int
blockClientOnSwappedKeys
(
redisClient
*
c
,
struct
redisCommand
*
cmd
);
int
dontWaitForSwappedKey
(
redisClient
*
c
,
robj
*
key
);
void
handleClientsBlockedOnSwappedKey
(
redisDb
*
db
,
robj
*
key
);
...
...
@@ -917,6 +914,15 @@ int selectDb(redisClient *c, int id);
void
signalModifiedKey
(
redisDb
*
db
,
robj
*
key
);
void
signalFlushedDb
(
int
dbid
);
/* API to get key arguments from commands */
#define REDIS_GETKEYS_ALL 0
#define REDIS_GETKEYS_PRELOAD 1
int
*
getKeysFromCommand
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
,
int
flags
);
void
getKeysFreeResult
(
int
*
result
);
int
*
noPreloadGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
,
int
flags
);
int
*
renameGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
,
int
flags
);
int
*
zunionInterGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
,
int
flags
);
/* Git SHA1 */
char
*
redisGitSHA1
(
void
);
char
*
redisGitDirty
(
void
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录