Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
1ed2ff55
Commit
1ed2ff55
authored
May 03, 2017
by
antirez
Browse files
Modules TSC: HELLO.KEYS example draft finished.
parent
7127f15e
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/modules/helloblock.c
View file @
1ed2ff55
...
@@ -106,15 +106,44 @@ int HelloBlock_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int a
...
@@ -106,15 +106,44 @@ int HelloBlock_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int a
}
}
/* The thread entry point that actually executes the blocking part
/* The thread entry point that actually executes the blocking part
* of the command HELLO.KEYS. */
* of the command HELLO.KEYS.
*
* Note: this implementation is very simple on purpose, so no duplicated
* keys (returned by SCAN) are filtered. However adding such a functionality
* would be trivial just using any data structure implementing a dictionary
* in order to filter the duplicated items. */
void
*
HelloKeys_ThreadMain
(
void
*
arg
)
{
void
*
HelloKeys_ThreadMain
(
void
*
arg
)
{
RedisModuleBlockedClient
*
bc
=
arg
;
RedisModuleBlockedClient
*
bc
=
arg
;
RedisModuleCtx
*
ctx
=
RedisModule_GetThreadSafeContext
(
bc
);
RedisModuleCtx
*
ctx
=
RedisModule_GetThreadSafeContext
(
bc
);
long
long
cursor
=
1
;
RedisModule_ThreadSafeContextLock
(
ctx
);
size_t
replylen
=
0
;
RedisModule_ReplyWithLongLong
(
ctx
,
1234
);
RedisModule_ThreadSafeContextUnlock
(
ctx
);
RedisModule_ReplyWithArray
(
ctx
,
REDISMODULE_POSTPONED_ARRAY_LEN
);
do
{
RedisModule_ThreadSafeContextLock
(
ctx
);
RedisModuleCallReply
*
reply
=
RedisModule_Call
(
ctx
,
"SCAN"
,
"l"
,(
long
long
)
cursor
);
RedisModule_ThreadSafeContextUnlock
(
ctx
);
size_t
items
=
RedisModule_CallReplyLength
(
reply
);
size_t
j
;
for
(
j
=
0
;
j
<
items
;
j
++
)
{
RedisModuleCallReply
*
ele
=
RedisModule_CallReplyArrayElement
(
reply
,
j
);
if
(
j
==
0
)
{
RedisModuleString
*
s
=
RedisModule_CreateStringFromCallReply
(
ele
);
RedisModule_StringToLongLong
(
s
,
&
cursor
);
RedisModule_FreeString
(
ctx
,
s
);
}
else
{
RedisModule_ReplyWithCallReply
(
ctx
,
ele
);
replylen
++
;
}
}
RedisModule_FreeCallReply
(
reply
);
}
while
(
cursor
!=
0
);
RedisModule_ReplySetArrayLength
(
ctx
,
replylen
);
RedisModule_FreeThreadSafeContext
(
ctx
);
RedisModule_UnblockClient
(
bc
,
NULL
);
RedisModule_UnblockClient
(
bc
,
NULL
);
return
NULL
;
return
NULL
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment