Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
f4e7502e
R
redis
项目概览
xindoo
/
redis
通知
2
Star
2
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,发现更多精彩内容 >>
提交
f4e7502e
编写于
12月 07, 2017
作者:
D
Dvir Volk
提交者:
antirez
2月 15, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix indentation and comment style in testmodule
上级
3c8456c6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
92 addition
and
98 deletion
+92
-98
src/modules/testmodule.c
src/modules/testmodule.c
+92
-98
未找到文件。
src/modules/testmodule.c
浏览文件 @
f4e7502e
...
...
@@ -125,6 +125,7 @@ int failTest(RedisModuleCtx *ctx, const char *msg) {
RedisModule_ReplyWithError
(
ctx
,
msg
);
return
REDISMODULE_ERR
;
}
int
TestUnlink
(
RedisModuleCtx
*
ctx
,
RedisModuleString
**
argv
,
int
argc
)
{
RedisModule_AutoMemory
(
ctx
);
REDISMODULE_NOT_USED
(
argv
);
...
...
@@ -154,10 +155,12 @@ int TestUnlink(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
}
int
NotifyCallback
(
RedisModuleCtx
*
ctx
,
int
type
,
const
char
*
event
,
RedisModuleString
*
key
)
{
// Increment a counter on the notifications:
// for each key notified we increment a counter
RedisModule_Log
(
ctx
,
"notice"
,
"Got event type %d, event %s, key %s"
,
type
,
event
,
RedisModule_StringPtrLen
(
key
,
NULL
));
int
NotifyCallback
(
RedisModuleCtx
*
ctx
,
int
type
,
const
char
*
event
,
RedisModuleString
*
key
)
{
/* Increment a counter on the notifications: for each key notified we
* increment a counter */
RedisModule_Log
(
ctx
,
"notice"
,
"Got event type %d, event %s, key %s"
,
type
,
event
,
RedisModule_StringPtrLen
(
key
,
NULL
));
RedisModule_Call
(
ctx
,
"HINCRBY"
,
"csc"
,
"notifications"
,
key
,
"1"
);
return
REDISMODULE_OK
;
...
...
@@ -165,149 +168,140 @@ int NotifyCallback(RedisModuleCtx *ctx, int type, const char *event, RedisModule
/* TEST.NOTIFICATIONS -- Test Keyspace Notifications. */
int
TestNotifications
(
RedisModuleCtx
*
ctx
,
RedisModuleString
**
argv
,
int
argc
)
{
REDISMODULE_NOT_USED
(
argv
);
REDISMODULE_NOT_USED
(
argc
);
#define FAIL(msg, ...) \
{ \
RedisModule_Log(ctx, "warning", "Failed NOTIFY Test. Reason: " #msg, \
##__VA_ARGS__); \
goto err; \
}
RedisModule_Call
(
ctx
,
"FLUSHDB"
,
""
);
RedisModule_Call
(
ctx
,
"SET"
,
"cc"
,
"foo"
,
"bar"
);
RedisModule_Call
(
ctx
,
"SET"
,
"cc"
,
"foo"
,
"baz"
);
RedisModule_Call
(
ctx
,
"SADD"
,
"cc"
,
"bar"
,
"x"
);
RedisModule_Call
(
ctx
,
"SADD"
,
"cc"
,
"bar"
,
"y"
);
RedisModule_Call
(
ctx
,
"HSET"
,
"ccc"
,
"baz"
,
"x"
,
"y"
);
// LPUSH should be ignored and not increment any counters
RedisModule_Call
(
ctx
,
"LPUSH"
,
"cc"
,
"l"
,
"y"
);
RedisModule_Call
(
ctx
,
"LPUSH"
,
"cc"
,
"l"
,
"y"
);
size_t
sz
;
const
char
*
rep
;
RedisModuleCallReply
*
r
=
RedisModule_Call
(
ctx
,
"HGET"
,
"cc"
,
"notifications"
,
"foo"
);
if
(
r
==
NULL
||
RedisModule_CallReplyType
(
r
)
!=
REDISMODULE_REPLY_STRING
)
{
FAIL
(
"Wrong or no reply for foo"
);
}
else
{
rep
=
RedisModule_CallReplyStringPtr
(
r
,
&
sz
);
if
(
sz
!=
1
||
*
rep
!=
'2'
)
{
FAIL
(
"Got reply '%s'. expected '2'"
,
RedisModule_CallReplyStringPtr
(
r
,
NULL
));
REDISMODULE_NOT_USED
(
argv
);
REDISMODULE_NOT_USED
(
argc
);
#define FAIL(msg, ...) \
{ \
RedisModule_Log(ctx, "warning", "Failed NOTIFY Test. Reason: " #msg, ##__VA_ARGS__); \
goto err; \
}
RedisModule_Call
(
ctx
,
"FLUSHDB"
,
""
);
RedisModule_Call
(
ctx
,
"SET"
,
"cc"
,
"foo"
,
"bar"
);
RedisModule_Call
(
ctx
,
"SET"
,
"cc"
,
"foo"
,
"baz"
);
RedisModule_Call
(
ctx
,
"SADD"
,
"cc"
,
"bar"
,
"x"
);
RedisModule_Call
(
ctx
,
"SADD"
,
"cc"
,
"bar"
,
"y"
);
RedisModule_Call
(
ctx
,
"HSET"
,
"ccc"
,
"baz"
,
"x"
,
"y"
);
/* LPUSH should be ignored and not increment any counters */
RedisModule_Call
(
ctx
,
"LPUSH"
,
"cc"
,
"l"
,
"y"
);
RedisModule_Call
(
ctx
,
"LPUSH"
,
"cc"
,
"l"
,
"y"
);
size_t
sz
;
const
char
*
rep
;
RedisModuleCallReply
*
r
=
RedisModule_Call
(
ctx
,
"HGET"
,
"cc"
,
"notifications"
,
"foo"
);
if
(
r
==
NULL
||
RedisModule_CallReplyType
(
r
)
!=
REDISMODULE_REPLY_STRING
)
{
FAIL
(
"Wrong or no reply for foo"
);
}
else
{
rep
=
RedisModule_CallReplyStringPtr
(
r
,
&
sz
);
if
(
sz
!=
1
||
*
rep
!=
'2'
)
{
FAIL
(
"Got reply '%s'. expected '2'"
,
RedisModule_CallReplyStringPtr
(
r
,
NULL
));
}
}
}
r
=
RedisModule_Call
(
ctx
,
"HGET"
,
"cc"
,
"notifications"
,
"bar"
);
if
(
r
==
NULL
||
RedisModule_CallReplyType
(
r
)
!=
REDISMODULE_REPLY_STRING
)
{
FAIL
(
"Wrong or no reply for bar"
);
}
else
{
rep
=
RedisModule_CallReplyStringPtr
(
r
,
&
sz
);
if
(
sz
!=
1
||
*
rep
!=
'2'
)
{
FAIL
(
"Got reply '%s'. expected '2'"
,
rep
);
r
=
RedisModule_Call
(
ctx
,
"HGET"
,
"cc"
,
"notifications"
,
"bar"
);
if
(
r
==
NULL
||
RedisModule_CallReplyType
(
r
)
!=
REDISMODULE_REPLY_STRING
)
{
FAIL
(
"Wrong or no reply for bar"
);
}
else
{
rep
=
RedisModule_CallReplyStringPtr
(
r
,
&
sz
);
if
(
sz
!=
1
||
*
rep
!=
'2'
)
{
FAIL
(
"Got reply '%s'. expected '2'"
,
rep
);
}
}
r
=
RedisModule_Call
(
ctx
,
"HGET"
,
"cc"
,
"notifications"
,
"baz"
);
if
(
r
==
NULL
||
RedisModule_CallReplyType
(
r
)
!=
REDISMODULE_REPLY_STRING
)
{
FAIL
(
"Wrong or no reply for baz"
);
}
else
{
rep
=
RedisModule_CallReplyStringPtr
(
r
,
&
sz
);
if
(
sz
!=
1
||
*
rep
!=
'1'
)
{
FAIL
(
"Got reply '%.*s'. expected '1'"
,
sz
,
rep
);
}
}
}
r
=
RedisModule_Call
(
ctx
,
"HGET"
,
"cc"
,
"notifications"
,
"baz"
);
if
(
r
==
NULL
||
RedisModule_CallReplyType
(
r
)
!=
REDISMODULE_REPLY_STRING
)
{
FAIL
(
"Wrong or no reply for baz"
);
}
else
{
rep
=
RedisModule_CallReplyStringPtr
(
r
,
&
sz
);
if
(
sz
!=
1
||
*
rep
!=
'1'
)
{
FAIL
(
"Got reply '%.*s'. expected '1'"
,
sz
,
rep
);
/* For l we expect nothing since we didn't subscribe to list events */
r
=
RedisModule_Call
(
ctx
,
"HGET"
,
"cc"
,
"notifications"
,
"l"
);
if
(
r
==
NULL
||
RedisModule_CallReplyType
(
r
)
!=
REDISMODULE_REPLY_NULL
)
{
FAIL
(
"Wrong reply for l"
);
}
}
// for l we expect nothing since we didn't subscribe to list events
r
=
RedisModule_Call
(
ctx
,
"HGET"
,
"cc"
,
"notifications"
,
"l"
);
if
(
r
==
NULL
||
RedisModule_CallReplyType
(
r
)
!=
REDISMODULE_REPLY_NULL
)
{
FAIL
(
"Wrong reply for l"
);
}
RedisModule_Call
(
ctx
,
"FLUSHDB"
,
""
);
return
RedisModule_ReplyWithSimpleString
(
ctx
,
"OK"
);
return
RedisModule_ReplyWithSimpleString
(
ctx
,
"OK"
);
err:
RedisModule_Call
(
ctx
,
"FLUSHDB"
,
""
);
RedisModule_Call
(
ctx
,
"FLUSHDB"
,
""
);
return
RedisModule_ReplyWithSimpleString
(
ctx
,
"ERR"
);
return
RedisModule_ReplyWithSimpleString
(
ctx
,
"ERR"
);
}
/* TEST.CTXFLAGS -- Test GetContextFlags. */
int
TestCtxFlags
(
RedisModuleCtx
*
ctx
,
RedisModuleString
**
argv
,
int
argc
)
{
REDISMODULE_NOT_USED
(
argc
);
REDISMODULE_NOT_USED
(
argv
);
RedisModule_AutoMemory
(
ctx
);
int
ok
=
1
;
const
char
*
errString
=
NULL
;
#undef FAIL
#define FAIL(msg)
\
{ \
ok = 0; \
errString = msg; \
goto end; \
#undef FAIL
#define FAIL(msg)
\
{
\
ok = 0; \
errString = msg; \
goto end; \
}
int
flags
=
RedisModule_GetContextFlags
(
ctx
);
if
(
flags
==
0
)
{
FAIL
(
"Got no flags"
);
FAIL
(
"Got no flags"
);
}
if
(
flags
&
REDISMODULE_CTX_FLAGS_LUA
)
FAIL
(
"Lua flag was set"
);
if
(
flags
&
REDISMODULE_CTX_FLAGS_MULTI
)
FAIL
(
"Multi flag was set"
);
if
(
flags
&
REDISMODULE_CTX_FLAGS_AOF
)
FAIL
(
"AOF Flag was set"
)
/* Enable AOF to test AOF flags */
RedisModule_Call
(
ctx
,
"config"
,
"ccc"
,
"set"
,
"appendonly"
,
"yes"
);
flags
=
RedisModule_GetContextFlags
(
ctx
);
if
(
!
(
flags
&
REDISMODULE_CTX_FLAGS_AOF
))
FAIL
(
"AOF Flag not set after config set"
);
if
(
!
(
flags
&
REDISMODULE_CTX_FLAGS_AOF
))
FAIL
(
"AOF Flag not set after config set"
);
if
(
flags
&
REDISMODULE_CTX_FLAGS_RDB
)
FAIL
(
"RDB Flag was set"
);
/* Enable RDB to test RDB flags */
RedisModule_Call
(
ctx
,
"config"
,
"ccc"
,
"set"
,
"save"
,
"900 1"
);
flags
=
RedisModule_GetContextFlags
(
ctx
);
if
(
!
(
flags
&
REDISMODULE_CTX_FLAGS_RDB
))
FAIL
(
"RDB Flag was not set after config set"
);
if
(
!
(
flags
&
REDISMODULE_CTX_FLAGS_RDB
))
FAIL
(
"RDB Flag was not set after config set"
);
if
(
!
(
flags
&
REDISMODULE_CTX_FLAGS_MASTER
))
FAIL
(
"Master flag was not set"
);
if
(
flags
&
REDISMODULE_CTX_FLAGS_SLAVE
)
FAIL
(
"Slave flag was set"
);
if
(
flags
&
REDISMODULE_CTX_FLAGS_READONLY
)
FAIL
(
"Read-only flag was set"
);
if
(
flags
&
REDISMODULE_CTX_FLAGS_CLUSTER
)
FAIL
(
"Cluster flag was set"
);
if
(
flags
&
REDISMODULE_CTX_FLAGS_MAXMEMORY
)
FAIL
(
"Maxmemory flag was set"
);
;
RedisModule_Call
(
ctx
,
"config"
,
"ccc"
,
"set"
,
"maxmemory"
,
"100000000"
);
flags
=
RedisModule_GetContextFlags
(
ctx
);
if
(
!
(
flags
&
REDISMODULE_CTX_FLAGS_MAXMEMORY
))
FAIL
(
"Maxmemory flag was not set after config set"
);
FAIL
(
"Maxmemory flag was not set after config set"
);
if
(
flags
&
REDISMODULE_CTX_FLAGS_EVICT
)
FAIL
(
"Eviction flag was set"
);
RedisModule_Call
(
ctx
,
"config"
,
"ccc"
,
"set"
,
"maxmemory-policy"
,
"allkeys-lru"
);
RedisModule_Call
(
ctx
,
"config"
,
"ccc"
,
"set"
,
"maxmemory-policy"
,
"allkeys-lru"
);
flags
=
RedisModule_GetContextFlags
(
ctx
);
if
(
!
(
flags
&
REDISMODULE_CTX_FLAGS_EVICT
))
FAIL
(
"Eviction flag was not set after config set"
);
end:
if
(
!
(
flags
&
REDISMODULE_CTX_FLAGS_EVICT
))
FAIL
(
"Eviction flag was not set after config set"
);
end:
/* Revert config changes */
RedisModule_Call
(
ctx
,
"config"
,
"ccc"
,
"set"
,
"appendonly"
,
"no"
);
RedisModule_Call
(
ctx
,
"config"
,
"ccc"
,
"set"
,
"save"
,
""
);
RedisModule_Call
(
ctx
,
"config"
,
"ccc"
,
"set"
,
"maxmemory"
,
"0"
);
RedisModule_Call
(
ctx
,
"config"
,
"ccc"
,
"set"
,
"maxmemory-policy"
,
"noeviction"
);
if
(
!
ok
)
{
RedisModule_Log
(
ctx
,
"warning"
,
"Failed CTXFLAGS Test. Reason: %s"
,
errString
);
return
RedisModule_ReplyWithSimpleString
(
ctx
,
"ERR"
);
RedisModule_Log
(
ctx
,
"warning"
,
"Failed CTXFLAGS Test. Reason: %s"
,
errString
);
return
RedisModule_ReplyWithSimpleString
(
ctx
,
"ERR"
);
}
return
RedisModule_ReplyWithSimpleString
(
ctx
,
"OK"
);
}
return
RedisModule_ReplyWithSimpleString
(
ctx
,
"OK"
);
}
/* ----------------------------- Test framework ----------------------------- */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录