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
20f04796
Commit
20f04796
authored
Sep 27, 2018
by
antirez
Browse files
Modules: hellodict example WIP #1: GET command.
parent
880ca077
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/modules/hellodict.c
View file @
20f04796
...
@@ -54,6 +54,20 @@ int cmd_SET(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
...
@@ -54,6 +54,20 @@ int cmd_SET(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
return
RedisModule_ReplyWithSimpleString
(
ctx
,
"OK"
);
return
RedisModule_ReplyWithSimpleString
(
ctx
,
"OK"
);
}
}
/* HELLODICT.GET <key>
*
* Return the value of the specified key, or a null reply if the key
* is not defined. */
int
cmd_GET
(
RedisModuleCtx
*
ctx
,
RedisModuleString
**
argv
,
int
argc
)
{
if
(
argc
!=
2
)
return
RedisModule_WrongArity
(
ctx
);
RedisModuleString
*
val
=
RedisModule_DictGet
(
Keyspace
,
argv
[
1
],
NULL
);
if
(
val
==
NULL
)
{
return
RedisModule_ReplyWithNull
(
ctx
);
}
else
{
return
RedisModule_ReplyWithString
(
ctx
,
val
);
}
}
/* This function must be present on each Redis module. It is used in order to
/* This function must be present on each Redis module. It is used in order to
* register the commands into the Redis server. */
* register the commands into the Redis server. */
int
RedisModule_OnLoad
(
RedisModuleCtx
*
ctx
,
RedisModuleString
**
argv
,
int
argc
)
{
int
RedisModule_OnLoad
(
RedisModuleCtx
*
ctx
,
RedisModuleString
**
argv
,
int
argc
)
{
...
@@ -67,6 +81,10 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
...
@@ -67,6 +81,10 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
cmd_SET
,
"write deny-oom"
,
1
,
1
,
0
)
==
REDISMODULE_ERR
)
cmd_SET
,
"write deny-oom"
,
1
,
1
,
0
)
==
REDISMODULE_ERR
)
return
REDISMODULE_ERR
;
return
REDISMODULE_ERR
;
if
(
RedisModule_CreateCommand
(
ctx
,
"hellodict.get"
,
cmd_GET
,
"readonly"
,
1
,
1
,
0
)
==
REDISMODULE_ERR
)
return
REDISMODULE_ERR
;
/* Create our global dictionray. Here we'll set our keys and values. */
/* Create our global dictionray. Here we'll set our keys and values. */
Keyspace
=
RedisModule_CreateDict
(
NULL
);
Keyspace
=
RedisModule_CreateDict
(
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