updated docs and header

master
Dvir Volk 9 years ago
parent 9425602b23
commit 7e80e8b648

@ -261,33 +261,38 @@ int RedisModule_CreateCommand(RedisModuleCtx *ctx, const char *name, RedisModule
be passed as a C string compoesd of space separated words, like for
example "write deny-oom". The set of flags are:
* **"write"**: The command may modify the data set (it may also read from it).
* **"write"**: The command may modify the data set (it may also read
from it).
* **"readonly"**: The command returns data from keys but never writes.
* **"admin"**: The command is an administrative command (may change replication
or perform similar tasks).
* **"deny-oom"**: The command may use additional memory and should be denied during
out of memory conditions.
* **"admin"**: The command is an administrative command (may change
replication or perform similar tasks).
* **"deny-oom"**: The command may use additional memory and should be
denied during out of memory conditions.
* **"deny-script"**: Don't allow this command in Lua scripts.
* **"allow-loading"**: Allow this command while the server is loading data. Only
commands not interacting with the data set should be allowed
to run in this mode. If not sure don't use this flag.
* **"allow-loading"**: Allow this command while the server is loading data.
Only commands not interacting with the data set
should be allowed to run in this mode. If not sure
don't use this flag.
* **"pubsub"**: The command publishes things on Pub/Sub channels.
* **"random"**: The command may have different outputs even starting from the
same input arguments and key values.
* **"allow-stale"**: The command is allowed to run on slaves that don't serve stale
data. Don't use if you don't know what this means.
* **"no-monitor"**: Don't propoagate the command on monitor. Use this if the command
has sensible data among the arguments.
* **"fast"**: The command time complexity is not greater than O(log(N)) where
N is the size of the collection or anything else representing
the normal scalability issue with the command.
* **"getkeys-api"**: The command implements the interface to return the arguments
that are keys. Used when start/stop/step is not enough because
of the command syntax.
* **"no-cluster"**: The command should not register in Redis Cluster since is not
designed to work with it because, for example, is unable to
report the position of the keys, programmatically creates key
names, or any other reason.
* **"random"**: The command may have different outputs even starting
from the same input arguments and key values.
* **"allow-stale"**: The command is allowed to run on slaves that don't
serve stale data. Don't use if you don't know what
this means.
* **"no-monitor"**: Don't propoagate the command on monitor. Use this if
the command has sensible data among the arguments.
* **"fast"**: The command time complexity is not greater
than O(log(N)) where N is the size of the collection or
anything else representing the normal scalability
issue with the command.
* **"getkeys-api"**: The command implements the interface to return
the arguments that are keys. Used when start/stop/step
is not enough because of the command syntax.
* **"no-cluster"**: The command should not register in Redis Cluster
since is not designed to work with it because, for
example, is unable to report the position of the
keys, programmatically creates key names, or any
other reason.
### RedisModule_SetModuleAttribs
@ -1226,7 +1231,7 @@ void RMUtil_StringToUpper(RedisModuleString *s);
### Vector_Get
```
int Vector_Get(Vector *v, int pos, void *ptr);
int Vector_Get(Vector *v, size_t pos, void *ptr);
```
get the element at index pos. The value is copied in to ptr. If pos is outside
the vector capacity, we return 0
@ -1235,7 +1240,7 @@ int Vector_Get(Vector *v, int pos, void *ptr);
### Vector_Resize
```
int Vector_Resize(Vector *v, int newcap);
int Vector_Resize(Vector *v, size_t newcap);
```
resize capacity of v

@ -25,14 +25,14 @@ int ParseCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
RedisModule_ReplyWithLongLong(ctx, x + y);
return REDISMODULE_OK;
}
// If we got PROD - return the product of 2 consecutive arguments
if (RMUtil_ParseArgsAfter("PROD", argv, argc, "ll", &x, &y) ==
REDISMODULE_OK) {
RedisModule_ReplyWithLongLong(ctx, x * y);
return REDISMODULE_ERR;
}
// something is fishy...
RedisModule_ReplyWithError(ctx, "Invalid arguments");
@ -98,16 +98,17 @@ int testParse(RedisModuleCtx *ctx) {
}
// test the HGETSET command
int testHgetSet(RedisModuleCtx *ctx) {
RedisModuleCallReply *r = RedisModule_Call(ctx, "example.hgetset", "ccc", "foo", "bar", "baz");
RMUtil_Assert(RedisModule_CallReplyType(r) != REDISMODULE_REPLY_ERROR);
r = RedisModule_Call(ctx, "example.hgetset", "ccc", "foo", "bar", "bag");
RMUtil_Assert(RedisModule_CallReplyType(r) == REDISMODULE_REPLY_STRING);
RMUtil_AssertReplyEquals(r, "baz");
r = RedisModule_Call(ctx, "example.hgetset", "ccc", "foo", "bar", "bang");
RMUtil_AssertReplyEquals(r, "bag");
return 0;
int testHgetSet(RedisModuleCtx *ctx) {
RedisModuleCallReply *r =
RedisModule_Call(ctx, "example.hgetset", "ccc", "foo", "bar", "baz");
RMUtil_Assert(RedisModule_CallReplyType(r) != REDISMODULE_REPLY_ERROR);
r = RedisModule_Call(ctx, "example.hgetset", "ccc", "foo", "bar", "bag");
RMUtil_Assert(RedisModule_CallReplyType(r) == REDISMODULE_REPLY_STRING);
RMUtil_AssertReplyEquals(r, "baz");
r = RedisModule_Call(ctx, "example.hgetset", "ccc", "foo", "bar", "bang");
RMUtil_AssertReplyEquals(r, "bag");
return 0;
}
// Unit test entry point for the module
@ -128,7 +129,7 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx) {
REDISMODULE_ERR) {
return REDISMODULE_ERR;
}
// register example.parse - the default registration syntax
if (RedisModule_CreateCommand(ctx, "example.parse", ParseCommand, "readonly",
1, 1, 1) == REDISMODULE_ERR) {
@ -137,7 +138,7 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx) {
// register example.hgetset - using the shortened utility registration macro
RMUtil_RegisterWriteCmd(ctx, "example.hgetset", HGetSetCommand);
// register the unit test
RMUtil_RegisterWriteCmd(ctx, "example.test", TestModule);

@ -150,6 +150,7 @@ int REDISMODULE_API_FUNC(RedisModule_HashGet)(RedisModuleKey *key, int flags, ..
int REDISMODULE_API_FUNC(RedisModule_IsKeysPositionRequest)(RedisModuleCtx *ctx);
void REDISMODULE_API_FUNC(RedisModule_KeyAtPos)(RedisModuleCtx *ctx, int pos);
unsigned long long REDISMODULE_API_FUNC(RedisModule_GetClientId)(RedisModuleCtx *ctx);
void *REDISMODULE_API_FUNC(RedisModule_PoolAlloc)(RedisModuleCtx *ctx, size_t bytes);
/* This is included inline inside each Redis module. */
static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int apiver) {
@ -219,6 +220,7 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
REDISMODULE_GET_API(IsKeysPositionRequest);
REDISMODULE_GET_API(KeyAtPos);
REDISMODULE_GET_API(GetClientId);
REDISMODULE_GET_API(PoolAlloc);
RedisModule_SetModuleAttribs(ctx,name,ver,apiver);
return REDISMODULE_OK;

Loading…
Cancel
Save