forked from valkey-io/valkey
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix module / script call CLUSTER SLOTS / SHARDS fake client check cra…
…sh (valkey-io#1063) The reason is VM_Call will use a fake client without connection, so we also need to check if c->conn is NULL. This also affects scripts. If they are called in the script, the server will crash. Injecting commands into AOF will also cause startup failure. Fixes valkey-io#1054. Signed-off-by: Binbin <[email protected]> Signed-off-by: naglera <[email protected]>
- Loading branch information
1 parent
6031623
commit 0e54f14
Showing
11 changed files
with
120 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "valkeymodule.h" | ||
|
||
#define UNUSED(x) (void)(x) | ||
|
||
int test_cluster_slots(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) { | ||
UNUSED(argv); | ||
|
||
if (argc != 1) return ValkeyModule_WrongArity(ctx); | ||
|
||
ValkeyModuleCallReply *rep = ValkeyModule_Call(ctx, "CLUSTER", "c", "SLOTS"); | ||
if (!rep) { | ||
ValkeyModule_ReplyWithError(ctx, "ERR NULL reply returned"); | ||
} else { | ||
ValkeyModule_ReplyWithCallReply(ctx, rep); | ||
ValkeyModule_FreeCallReply(rep); | ||
} | ||
|
||
return VALKEYMODULE_OK; | ||
} | ||
|
||
int test_cluster_shards(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) { | ||
UNUSED(argv); | ||
|
||
if (argc != 1) return ValkeyModule_WrongArity(ctx); | ||
|
||
ValkeyModuleCallReply *rep = ValkeyModule_Call(ctx, "CLUSTER", "c", "SHARDS"); | ||
if (!rep) { | ||
ValkeyModule_ReplyWithError(ctx, "ERR NULL reply returned"); | ||
} else { | ||
ValkeyModule_ReplyWithCallReply(ctx, rep); | ||
ValkeyModule_FreeCallReply(rep); | ||
} | ||
|
||
return VALKEYMODULE_OK; | ||
} | ||
|
||
int ValkeyModule_OnLoad(ValkeyModuleCtx *ctx, ValkeyModuleString **argv, int argc) { | ||
VALKEYMODULE_NOT_USED(argv); | ||
VALKEYMODULE_NOT_USED(argc); | ||
|
||
if (ValkeyModule_Init(ctx, "cluster", 1, VALKEYMODULE_APIVER_1)== VALKEYMODULE_ERR) | ||
return VALKEYMODULE_ERR; | ||
|
||
if (ValkeyModule_CreateCommand(ctx, "test.cluster_slots", test_cluster_slots, "", 0, 0, 0) == VALKEYMODULE_ERR) | ||
return VALKEYMODULE_ERR; | ||
|
||
if (ValkeyModule_CreateCommand(ctx, "test.cluster_shards", test_cluster_shards, "", 0, 0, 0) == VALKEYMODULE_ERR) | ||
return VALKEYMODULE_ERR; | ||
|
||
return VALKEYMODULE_OK; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters