Skip to content

Commit

Permalink
Updated modules examples and tests to use valkey vs redis (valkey-io#349
Browse files Browse the repository at this point in the history
)

Scope of the changes:
- updated example modules to reference Valkey vs Redis in variable names
- updated tests to use valkeymodule.h
- updated vars in tests/modules to use valkey vs redis in variable names

Summary of the testing:
- ran make for all modules, loaded them into valkey-server and tested
commands
- ran make for test/modules
- ran make test for the entire codebase

---------

Signed-off-by: Dmitry Polyakovsky <[email protected]>
Co-authored-by: Dmitry Polyakovsky <[email protected]>
  • Loading branch information
dmitrypol and Dmitry Polyakovsky authored Apr 23, 2024
1 parent 393c8fd commit f0e1edc
Show file tree
Hide file tree
Showing 47 changed files with 5,010 additions and 5,010 deletions.
16 changes: 8 additions & 8 deletions src/modules/helloacl.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static uint64_t global_auth_client_id = 0;

/* HELLOACL.REVOKE
* Synchronously revoke access from a user. */
int RevokeCommand_RedisCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
int RevokeCommand_ValkeyCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
VALKEYMODULE_NOT_USED(argv);
VALKEYMODULE_NOT_USED(argc);

Expand All @@ -55,7 +55,7 @@ int RevokeCommand_RedisCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv,

/* HELLOACL.RESET
* Synchronously delete and re-create a module user. */
int ResetCommand_RedisCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
int ResetCommand_ValkeyCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
VALKEYMODULE_NOT_USED(argv);
VALKEYMODULE_NOT_USED(argc);

Expand All @@ -78,7 +78,7 @@ void HelloACL_UserChanged(uint64_t client_id, void *privdata) {

/* HELLOACL.AUTHGLOBAL
* Synchronously assigns a module user to the current context. */
int AuthGlobalCommand_RedisCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
int AuthGlobalCommand_ValkeyCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
VALKEYMODULE_NOT_USED(argv);
VALKEYMODULE_NOT_USED(argc);

Expand Down Expand Up @@ -135,7 +135,7 @@ void *HelloACL_ThreadMain(void *args) {

/* HELLOACL.AUTHASYNC
* Asynchronously assigns an ACL user to the current context. */
int AuthAsyncCommand_RedisCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
int AuthAsyncCommand_ValkeyCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
if (argc != 2) return ValkeyModule_WrongArity(ctx);

pthread_t tid;
Expand Down Expand Up @@ -164,19 +164,19 @@ int ValkeyModule_OnLoad(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int arg
== VALKEYMODULE_ERR) return VALKEYMODULE_ERR;

if (ValkeyModule_CreateCommand(ctx,"helloacl.reset",
ResetCommand_RedisCommand,"",0,0,0) == VALKEYMODULE_ERR)
ResetCommand_ValkeyCommand,"",0,0,0) == VALKEYMODULE_ERR)
return VALKEYMODULE_ERR;

if (ValkeyModule_CreateCommand(ctx,"helloacl.revoke",
RevokeCommand_RedisCommand,"",0,0,0) == VALKEYMODULE_ERR)
RevokeCommand_ValkeyCommand,"",0,0,0) == VALKEYMODULE_ERR)
return VALKEYMODULE_ERR;

if (ValkeyModule_CreateCommand(ctx,"helloacl.authglobal",
AuthGlobalCommand_RedisCommand,"no-auth",0,0,0) == VALKEYMODULE_ERR)
AuthGlobalCommand_ValkeyCommand,"no-auth",0,0,0) == VALKEYMODULE_ERR)
return VALKEYMODULE_ERR;

if (ValkeyModule_CreateCommand(ctx,"helloacl.authasync",
AuthAsyncCommand_RedisCommand,"no-auth",0,0,0) == VALKEYMODULE_ERR)
AuthAsyncCommand_ValkeyCommand,"no-auth",0,0,0) == VALKEYMODULE_ERR)
return VALKEYMODULE_ERR;

global = ValkeyModule_CreateModuleUser("global");
Expand Down
8 changes: 4 additions & 4 deletions src/modules/helloblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void HelloBlock_Disconnected(ValkeyModuleCtx *ctx, ValkeyModuleBlockedClient *bc
/* HELLO.BLOCK <delay> <timeout> -- Block for <count> seconds, then reply with
* a random number. Timeout is the command timeout, so that you can test
* what happens when the delay is greater than the timeout. */
int HelloBlock_RedisCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
int HelloBlock_ValkeyCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
if (argc != 3) return ValkeyModule_WrongArity(ctx);
long long delay;
long long timeout;
Expand Down Expand Up @@ -177,7 +177,7 @@ void *HelloKeys_ThreadMain(void *arg) {
* the server. The keys do not represent a point-in-time state so only the keys
* that were in the database from the start to the end are guaranteed to be
* there. */
int HelloKeys_RedisCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
int HelloKeys_ValkeyCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
VALKEYMODULE_NOT_USED(argv);
if (argc != 1) return ValkeyModule_WrongArity(ctx);

Expand Down Expand Up @@ -208,10 +208,10 @@ int ValkeyModule_OnLoad(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int arg
== VALKEYMODULE_ERR) return VALKEYMODULE_ERR;

if (ValkeyModule_CreateCommand(ctx,"hello.block",
HelloBlock_RedisCommand,"",0,0,0) == VALKEYMODULE_ERR)
HelloBlock_ValkeyCommand,"",0,0,0) == VALKEYMODULE_ERR)
return VALKEYMODULE_ERR;
if (ValkeyModule_CreateCommand(ctx,"hello.keys",
HelloKeys_RedisCommand,"",0,0,0) == VALKEYMODULE_ERR)
HelloKeys_ValkeyCommand,"",0,0,0) == VALKEYMODULE_ERR)
return VALKEYMODULE_ERR;

return VALKEYMODULE_OK;
Expand Down
8 changes: 4 additions & 4 deletions src/modules/hellocluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#define MSGTYPE_PONG 2

/* HELLOCLUSTER.PINGALL */
int PingallCommand_RedisCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
int PingallCommand_ValkeyCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
VALKEYMODULE_NOT_USED(argv);
VALKEYMODULE_NOT_USED(argc);

Expand All @@ -49,7 +49,7 @@ int PingallCommand_RedisCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv,
}

/* HELLOCLUSTER.LIST */
int ListCommand_RedisCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
int ListCommand_ValkeyCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
VALKEYMODULE_NOT_USED(argv);
VALKEYMODULE_NOT_USED(argc);

Expand Down Expand Up @@ -96,11 +96,11 @@ int ValkeyModule_OnLoad(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int arg
== VALKEYMODULE_ERR) return VALKEYMODULE_ERR;

if (ValkeyModule_CreateCommand(ctx,"hellocluster.pingall",
PingallCommand_RedisCommand,"readonly",0,0,0) == VALKEYMODULE_ERR)
PingallCommand_ValkeyCommand,"readonly",0,0,0) == VALKEYMODULE_ERR)
return VALKEYMODULE_ERR;

if (ValkeyModule_CreateCommand(ctx,"hellocluster.list",
ListCommand_RedisCommand,"readonly",0,0,0) == VALKEYMODULE_ERR)
ListCommand_ValkeyCommand,"readonly",0,0,0) == VALKEYMODULE_ERR)
return VALKEYMODULE_ERR;

/* Disable Cluster sharding and redirections. This way every node
Expand Down
4 changes: 2 additions & 2 deletions src/modules/hellotimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void timerHandler(ValkeyModuleCtx *ctx, void *data) {
}

/* HELLOTIMER.TIMER*/
int TimerCommand_RedisCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
int TimerCommand_ValkeyCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
VALKEYMODULE_NOT_USED(argv);
VALKEYMODULE_NOT_USED(argc);

Expand All @@ -68,7 +68,7 @@ int ValkeyModule_OnLoad(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int arg
== VALKEYMODULE_ERR) return VALKEYMODULE_ERR;

if (ValkeyModule_CreateCommand(ctx,"hellotimer.timer",
TimerCommand_RedisCommand,"readonly",0,0,0) == VALKEYMODULE_ERR)
TimerCommand_ValkeyCommand,"readonly",0,0,0) == VALKEYMODULE_ERR)
return VALKEYMODULE_ERR;

return VALKEYMODULE_OK;
Expand Down
20 changes: 10 additions & 10 deletions src/modules/hellotype.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void HelloTypeReleaseObject(struct HelloTypeObject *o) {
/* ========================= "hellotype" type commands ======================= */

/* HELLOTYPE.INSERT key value */
int HelloTypeInsert_RedisCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
int HelloTypeInsert_ValkeyCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
ValkeyModule_AutoMemory(ctx); /* Use automatic memory management. */

if (argc != 3) return ValkeyModule_WrongArity(ctx);
Expand Down Expand Up @@ -137,7 +137,7 @@ int HelloTypeInsert_RedisCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv
}

/* HELLOTYPE.RANGE key first count */
int HelloTypeRange_RedisCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
int HelloTypeRange_ValkeyCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
ValkeyModule_AutoMemory(ctx); /* Use automatic memory management. */

if (argc != 4) return ValkeyModule_WrongArity(ctx);
Expand Down Expand Up @@ -173,7 +173,7 @@ int HelloTypeRange_RedisCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv,
}

/* HELLOTYPE.LEN key */
int HelloTypeLen_RedisCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
int HelloTypeLen_ValkeyCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
ValkeyModule_AutoMemory(ctx); /* Use automatic memory management. */

if (argc != 2) return ValkeyModule_WrongArity(ctx);
Expand Down Expand Up @@ -213,7 +213,7 @@ int HelloBlock_Reply(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc)
/* In case the key is able to serve our blocked client, let's directly
* use our original command implementation to make this example simpler. */
ValkeyModule_CloseKey(key);
return HelloTypeRange_RedisCommand(ctx,argv,argc-1);
return HelloTypeRange_ValkeyCommand(ctx,argv,argc-1);
}

/* Timeout callback for blocking command HELLOTYPE.BRANGE */
Expand All @@ -232,7 +232,7 @@ void HelloBlock_FreeData(ValkeyModuleCtx *ctx, void *privdata) {
/* HELLOTYPE.BRANGE key first count timeout -- This is a blocking version of
* the RANGE operation, in order to show how to use the API
* ValkeyModule_BlockClientOnKeys(). */
int HelloTypeBRange_RedisCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
int HelloTypeBRange_ValkeyCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) {
if (argc != 5) return ValkeyModule_WrongArity(ctx);
ValkeyModule_AutoMemory(ctx); /* Use automatic memory management. */
ValkeyModuleKey *key = ValkeyModule_OpenKey(ctx,argv[1],
Expand All @@ -254,7 +254,7 @@ int HelloTypeBRange_RedisCommand(ValkeyModuleCtx *ctx, ValkeyModuleString **argv

/* Can we serve the reply synchronously? */
if (type != VALKEYMODULE_KEYTYPE_EMPTY) {
return HelloTypeRange_RedisCommand(ctx,argv,argc-1);
return HelloTypeRange_ValkeyCommand(ctx,argv,argc-1);
}

/* Otherwise let's block on the key. */
Expand Down Expand Up @@ -343,19 +343,19 @@ int ValkeyModule_OnLoad(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int arg
if (HelloType == NULL) return VALKEYMODULE_ERR;

if (ValkeyModule_CreateCommand(ctx,"hellotype.insert",
HelloTypeInsert_RedisCommand,"write deny-oom",1,1,1) == VALKEYMODULE_ERR)
HelloTypeInsert_ValkeyCommand,"write deny-oom",1,1,1) == VALKEYMODULE_ERR)
return VALKEYMODULE_ERR;

if (ValkeyModule_CreateCommand(ctx,"hellotype.range",
HelloTypeRange_RedisCommand,"readonly",1,1,1) == VALKEYMODULE_ERR)
HelloTypeRange_ValkeyCommand,"readonly",1,1,1) == VALKEYMODULE_ERR)
return VALKEYMODULE_ERR;

if (ValkeyModule_CreateCommand(ctx,"hellotype.len",
HelloTypeLen_RedisCommand,"readonly",1,1,1) == VALKEYMODULE_ERR)
HelloTypeLen_ValkeyCommand,"readonly",1,1,1) == VALKEYMODULE_ERR)
return VALKEYMODULE_ERR;

if (ValkeyModule_CreateCommand(ctx,"hellotype.brange",
HelloTypeBRange_RedisCommand,"readonly",1,1,1) == VALKEYMODULE_ERR)
HelloTypeBRange_ValkeyCommand,"readonly",1,1,1) == VALKEYMODULE_ERR)
return VALKEYMODULE_ERR;

return VALKEYMODULE_OK;
Expand Down
Loading

0 comments on commit f0e1edc

Please sign in to comment.