mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-21 23:58:51 -05:00
tests/modules: fix remaining redis => redict cases
Non-API impacting renames. Signed-off-by: Drew DeVault <sir@cmpwn.com>
This commit is contained in:
parent
03d144a452
commit
cdd60793d5
@ -204,14 +204,14 @@ int commandBlockCheck(RedictModuleCtx *ctx, RedictModuleString **argv, int argc)
|
||||
|
||||
result = RedictModule_AddACLCategory(ctx,"blockedcategory");
|
||||
response_ok |= (result == REDICTMODULE_OK);
|
||||
|
||||
|
||||
RedictModuleCommand *parent = RedictModule_GetCommand(ctx,"block.commands.outside.onload");
|
||||
result = RedictModule_SetCommandACLCategories(parent, "write");
|
||||
response_ok |= (result == REDICTMODULE_OK);
|
||||
|
||||
result = RedictModule_CreateSubcommand(parent,"subcommand.that.should.fail",module_test_acl_category,"",0,0,0);
|
||||
response_ok |= (result == REDICTMODULE_OK);
|
||||
|
||||
|
||||
/* This validates that it's not possible to create commands or add
|
||||
* a new ACL Category outside OnLoad function.
|
||||
* thus returns an error if they succeed. */
|
||||
@ -229,9 +229,9 @@ int RedictModule_OnLoad(RedictModuleCtx *ctx, RedictModuleString **argv, int arg
|
||||
return REDICTMODULE_ERR;
|
||||
|
||||
if (argc > 1) return RedictModule_WrongArity(ctx);
|
||||
|
||||
|
||||
/* When that flag is passed, we try to create too many categories,
|
||||
* and the test expects this to fail. In this case redis returns REDICTMODULE_ERR
|
||||
* and the test expects this to fail. In this case redict returns REDICTMODULE_ERR
|
||||
* and set errno to ENOMEM*/
|
||||
if (argc == 1) {
|
||||
long long fail_flag = 0;
|
||||
@ -294,28 +294,28 @@ int RedictModule_OnLoad(RedictModuleCtx *ctx, RedictModuleString **argv, int arg
|
||||
return REDICTMODULE_ERR;
|
||||
|
||||
/* This validates that, when module tries to add a category with invalid characters,
|
||||
* redis returns REDICTMODULE_ERR and set errno to `EINVAL` */
|
||||
* redict returns REDICTMODULE_ERR and set errno to `EINVAL` */
|
||||
if (RedictModule_AddACLCategory(ctx,"!nval!dch@r@cter$") == REDICTMODULE_ERR)
|
||||
RedictModule_Assert(errno == EINVAL);
|
||||
else
|
||||
else
|
||||
return REDICTMODULE_ERR;
|
||||
|
||||
|
||||
/* This validates that, when module tries to add a category that already exists,
|
||||
* redis returns REDICTMODULE_ERR and set errno to `EBUSY` */
|
||||
* redict returns REDICTMODULE_ERR and set errno to `EBUSY` */
|
||||
if (RedictModule_AddACLCategory(ctx,"write") == REDICTMODULE_ERR)
|
||||
RedictModule_Assert(errno == EBUSY);
|
||||
else
|
||||
else
|
||||
return REDICTMODULE_ERR;
|
||||
|
||||
|
||||
if (RedictModule_AddACLCategory(ctx,"foocategory") == REDICTMODULE_ERR)
|
||||
return REDICTMODULE_ERR;
|
||||
|
||||
|
||||
if (RedictModule_CreateCommand(ctx,"aclcheck.module.command.test.add.new.aclcategories", module_test_acl_category,"",0,0,0) == REDICTMODULE_ERR)
|
||||
return REDICTMODULE_ERR;
|
||||
RedictModuleCommand *test_add_new_aclcategories = RedictModule_GetCommand(ctx,"aclcheck.module.command.test.add.new.aclcategories");
|
||||
|
||||
if (RedictModule_SetCommandACLCategories(test_add_new_aclcategories, "foocategory") == REDICTMODULE_ERR)
|
||||
return REDICTMODULE_ERR;
|
||||
|
||||
|
||||
return REDICTMODULE_OK;
|
||||
}
|
||||
|
@ -60,9 +60,9 @@ int Auth_AuthRealUser(RedictModuleCtx *ctx, RedictModuleString **argv, int argc)
|
||||
RedictModuleString *user_string = argv[1];
|
||||
const char *name = RedictModule_StringPtrLen(user_string, &length);
|
||||
|
||||
if (RedictModule_AuthenticateClientWithACLUser(ctx, name, length,
|
||||
if (RedictModule_AuthenticateClientWithACLUser(ctx, name, length,
|
||||
UserChangedCallback, NULL, &client_id) == REDICTMODULE_ERR) {
|
||||
return RedictModule_ReplyWithError(ctx, "Invalid user");
|
||||
return RedictModule_ReplyWithError(ctx, "Invalid user");
|
||||
}
|
||||
|
||||
return RedictModule_ReplyWithLongLong(ctx, (uint64_t) client_id);
|
||||
@ -75,7 +75,7 @@ int Auth_RedactedAPI(RedictModuleCtx *ctx, RedictModuleString **argv, int argc)
|
||||
int result = RedictModule_RedactClientCommandArgument(ctx, i);
|
||||
RedictModule_Assert(result == REDICTMODULE_OK);
|
||||
}
|
||||
return RedictModule_ReplyWithSimpleString(ctx, "OK");
|
||||
return RedictModule_ReplyWithSimpleString(ctx, "OK");
|
||||
}
|
||||
|
||||
int Auth_ChangeCount(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
@ -226,8 +226,8 @@ int test_rm_register_blocking_auth_cb(RedictModuleCtx *ctx, RedictModuleString *
|
||||
return REDICTMODULE_OK;
|
||||
}
|
||||
|
||||
/* This function must be present on each Redis module. It is used in order to
|
||||
* register the commands into the Redis server. */
|
||||
/* This function must be present on each Redict module. It is used in order to
|
||||
* register the commands into the Redict server. */
|
||||
int RedictModule_OnLoad(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
REDICTMODULE_NOT_USED(argv);
|
||||
REDICTMODULE_NOT_USED(argc);
|
||||
|
@ -22,7 +22,7 @@ static volatile int g_slow_bg_operation = 0;
|
||||
static volatile int g_is_in_slow_bg_operation = 0;
|
||||
|
||||
void *sub_worker(void *arg) {
|
||||
// Get Redis module context
|
||||
// Get Redict module context
|
||||
RedictModuleCtx *ctx = (RedictModuleCtx *)arg;
|
||||
|
||||
// Try acquiring GIL
|
||||
@ -38,7 +38,7 @@ void *worker(void *arg) {
|
||||
// Retrieve blocked client
|
||||
RedictModuleBlockedClient *bc = (RedictModuleBlockedClient *)arg;
|
||||
|
||||
// Get Redis module context
|
||||
// Get Redict module context
|
||||
RedictModuleCtx *ctx = RedictModule_GetThreadSafeContext(bc);
|
||||
|
||||
// Acquire GIL
|
||||
@ -61,7 +61,7 @@ void *worker(void *arg) {
|
||||
// Unblock client
|
||||
RedictModule_UnblockClient(bc, NULL);
|
||||
|
||||
// Free the Redis module context
|
||||
// Free the Redict module context
|
||||
RedictModule_FreeThreadSafeContext(ctx);
|
||||
|
||||
return NULL;
|
||||
@ -110,7 +110,7 @@ void *bg_call_worker(void *arg) {
|
||||
bg_call_data *bg = arg;
|
||||
RedictModuleBlockedClient *bc = bg->bc;
|
||||
|
||||
// Get Redis module context
|
||||
// Get Redict module context
|
||||
RedictModuleCtx *ctx = RedictModule_GetThreadSafeContext(bg->bc);
|
||||
|
||||
// Acquire GIL
|
||||
@ -129,18 +129,18 @@ void *bg_call_worker(void *arg) {
|
||||
// Call the command
|
||||
const char *module_cmd = RedictModule_StringPtrLen(bg->argv[0], NULL);
|
||||
int cmd_pos = 1;
|
||||
RedictModuleString *format_redis_str = RedictModule_CreateString(NULL, "v", 1);
|
||||
RedictModuleString *format_redict_str = RedictModule_CreateString(NULL, "v", 1);
|
||||
if (!strcasecmp(module_cmd, "do_bg_rm_call_format")) {
|
||||
cmd_pos = 2;
|
||||
size_t format_len;
|
||||
const char *format = RedictModule_StringPtrLen(bg->argv[1], &format_len);
|
||||
RedictModule_StringAppendBuffer(NULL, format_redis_str, format, format_len);
|
||||
RedictModule_StringAppendBuffer(NULL, format_redis_str, "E", 1);
|
||||
RedictModule_StringAppendBuffer(NULL, format_redict_str, format, format_len);
|
||||
RedictModule_StringAppendBuffer(NULL, format_redict_str, "E", 1);
|
||||
}
|
||||
const char *format = RedictModule_StringPtrLen(format_redis_str, NULL);
|
||||
const char *format = RedictModule_StringPtrLen(format_redict_str, NULL);
|
||||
const char *cmd = RedictModule_StringPtrLen(bg->argv[cmd_pos], NULL);
|
||||
RedictModuleCallReply *rep = RedictModule_Call(ctx, cmd, format, bg->argv + cmd_pos + 1, bg->argc - cmd_pos - 1);
|
||||
RedictModule_FreeString(NULL, format_redis_str);
|
||||
RedictModule_FreeString(NULL, format_redict_str);
|
||||
|
||||
/* Free the arguments within GIL to prevent simultaneous freeing in main thread. */
|
||||
for (int i=0; i<bg->argc; i++)
|
||||
@ -162,7 +162,7 @@ void *bg_call_worker(void *arg) {
|
||||
// Unblock client
|
||||
RedictModule_UnblockClient(bc, NULL);
|
||||
|
||||
// Free the Redis module context
|
||||
// Free the Redict module context
|
||||
RedictModule_FreeThreadSafeContext(ctx);
|
||||
|
||||
return NULL;
|
||||
@ -622,7 +622,7 @@ static void timer_callback(RedictModuleCtx *ctx, void *data)
|
||||
|
||||
RedictModuleBlockedClient *bc = data;
|
||||
|
||||
// Get Redis module context
|
||||
// Get Redict module context
|
||||
RedictModuleCtx *reply_ctx = RedictModule_GetThreadSafeContext(bc);
|
||||
|
||||
// Reply to client
|
||||
@ -631,7 +631,7 @@ static void timer_callback(RedictModuleCtx *ctx, void *data)
|
||||
// Unblock client
|
||||
RedictModule_UnblockClient(bc, NULL);
|
||||
|
||||
// Free the Redis module context
|
||||
// Free the Redict module context
|
||||
RedictModule_FreeThreadSafeContext(reply_ctx);
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,7 @@ void HelloBlock_Disconnected(RedictModuleCtx *ctx, RedictModuleBlockedClient *bc
|
||||
/* BLOCK.DEBUG <delay_ms> <timeout_ms> -- Block for <count> milliseconds, 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(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
int HelloBlock_RedictCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
if (argc != 3) return RedictModule_WrongArity(ctx);
|
||||
long long delay;
|
||||
long long timeout;
|
||||
@ -172,7 +172,7 @@ int HelloBlock_RedisCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int
|
||||
* a random number. Timeout is the command timeout, so that you can test
|
||||
* what happens when the delay is greater than the timeout.
|
||||
* this command does not track background time so the background time should no appear in stats*/
|
||||
int HelloBlockNoTracking_RedisCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
int HelloBlockNoTracking_RedictCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
if (argc != 3) return RedictModule_WrongArity(ctx);
|
||||
long long delay;
|
||||
long long timeout;
|
||||
@ -214,7 +214,7 @@ int HelloBlockNoTracking_RedisCommand(RedictModuleCtx *ctx, RedictModuleString *
|
||||
* then reply with a random number.
|
||||
* This command is used to test multiple calls to RedictModule_BlockedClientMeasureTimeStart()
|
||||
* and RedictModule_BlockedClientMeasureTimeEnd() within the same execution. */
|
||||
int HelloDoubleBlock_RedisCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
int HelloDoubleBlock_RedictCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
if (argc != 2) return RedictModule_WrongArity(ctx);
|
||||
long long delay;
|
||||
|
||||
@ -246,7 +246,7 @@ RedictModuleBlockedClient *blocked_client = NULL;
|
||||
* or TIMEOUT seconds. If TIMEOUT is zero, no timeout function is
|
||||
* registered.
|
||||
*/
|
||||
int Block_RedisCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
int Block_RedictCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
if (RedictModule_IsBlockedReplyRequest(ctx)) {
|
||||
RedictModuleString *r = RedictModule_GetBlockedClientPrivateData(ctx);
|
||||
return RedictModule_ReplyWithString(ctx, r);
|
||||
@ -269,14 +269,14 @@ int Block_RedisCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc
|
||||
/* Block client. We use this function as both a reply and optional timeout
|
||||
* callback and differentiate the different code flows above.
|
||||
*/
|
||||
blocked_client = RedictModule_BlockClient(ctx, Block_RedisCommand,
|
||||
timeout > 0 ? Block_RedisCommand : NULL, HelloBlock_FreeStringData, timeout);
|
||||
blocked_client = RedictModule_BlockClient(ctx, Block_RedictCommand,
|
||||
timeout > 0 ? Block_RedictCommand : NULL, HelloBlock_FreeStringData, timeout);
|
||||
return REDICTMODULE_OK;
|
||||
}
|
||||
|
||||
/* BLOCK.IS_BLOCKED -- Returns 1 if we have a blocked client, or 0 otherwise.
|
||||
*/
|
||||
int IsBlocked_RedisCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
int IsBlocked_RedictCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
UNUSED(argv);
|
||||
UNUSED(argc);
|
||||
RedictModule_ReplyWithLongLong(ctx, blocked_client ? 1 : 0);
|
||||
@ -285,7 +285,7 @@ int IsBlocked_RedisCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int
|
||||
|
||||
/* BLOCK.RELEASE [reply] -- Releases the blocked client and produce the specified reply.
|
||||
*/
|
||||
int Release_RedisCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
int Release_RedictCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
if (argc != 2) return RedictModule_WrongArity(ctx);
|
||||
if (!blocked_client) {
|
||||
return RedictModule_ReplyWithError(ctx, "ERR No blocked client");
|
||||
@ -309,27 +309,27 @@ int RedictModule_OnLoad(RedictModuleCtx *ctx, RedictModuleString **argv, int arg
|
||||
== REDICTMODULE_ERR) return REDICTMODULE_ERR;
|
||||
|
||||
if (RedictModule_CreateCommand(ctx,"block.debug",
|
||||
HelloBlock_RedisCommand,"",0,0,0) == REDICTMODULE_ERR)
|
||||
HelloBlock_RedictCommand,"",0,0,0) == REDICTMODULE_ERR)
|
||||
return REDICTMODULE_ERR;
|
||||
|
||||
if (RedictModule_CreateCommand(ctx,"block.double_debug",
|
||||
HelloDoubleBlock_RedisCommand,"",0,0,0) == REDICTMODULE_ERR)
|
||||
HelloDoubleBlock_RedictCommand,"",0,0,0) == REDICTMODULE_ERR)
|
||||
return REDICTMODULE_ERR;
|
||||
|
||||
if (RedictModule_CreateCommand(ctx,"block.debug_no_track",
|
||||
HelloBlockNoTracking_RedisCommand,"",0,0,0) == REDICTMODULE_ERR)
|
||||
HelloBlockNoTracking_RedictCommand,"",0,0,0) == REDICTMODULE_ERR)
|
||||
return REDICTMODULE_ERR;
|
||||
|
||||
if (RedictModule_CreateCommand(ctx, "block.block",
|
||||
Block_RedisCommand, "", 0, 0, 0) == REDICTMODULE_ERR)
|
||||
Block_RedictCommand, "", 0, 0, 0) == REDICTMODULE_ERR)
|
||||
return REDICTMODULE_ERR;
|
||||
|
||||
if (RedictModule_CreateCommand(ctx,"block.is_blocked",
|
||||
IsBlocked_RedisCommand,"",0,0,0) == REDICTMODULE_ERR)
|
||||
IsBlocked_RedictCommand,"",0,0,0) == REDICTMODULE_ERR)
|
||||
return REDICTMODULE_ERR;
|
||||
|
||||
if (RedictModule_CreateCommand(ctx,"block.release",
|
||||
Release_RedisCommand,"",0,0,0) == REDICTMODULE_ERR)
|
||||
Release_RedictCommand,"",0,0,0) == REDICTMODULE_ERR)
|
||||
return REDICTMODULE_ERR;
|
||||
|
||||
return REDICTMODULE_OK;
|
||||
|
@ -16,7 +16,7 @@
|
||||
#define LIST_SIZE 1024
|
||||
|
||||
/* The FSL (Fixed-Size List) data type is a low-budget imitation of the
|
||||
* native Redis list, in order to test list-like commands implemented
|
||||
* native Redict list, in order to test list-like commands implemented
|
||||
* by a module.
|
||||
* Examples: FSL.PUSH, FSL.BPOP, etc. */
|
||||
|
||||
|
@ -35,7 +35,7 @@ int RedictModule_OnLoad(RedictModuleCtx *ctx, RedictModuleString **argv, int arg
|
||||
.tips = "nondeterministic_output",
|
||||
.history = (RedictModuleCommandHistoryEntry[]){
|
||||
/* NOTE: All versions specified should be the module's versions, not
|
||||
* Redis'! We use Redis versions in this example for the purpose of
|
||||
* Redict'! We use Redict versions in this example for the purpose of
|
||||
* testing (comparing the output with the output of the vanilla
|
||||
* XADD). */
|
||||
{"6.2.0", "Added the `NOMKSTREAM` option, `MINID` trimming strategy and the `LIMIT` option."},
|
||||
|
@ -8,19 +8,19 @@
|
||||
* about keys in global memory, and relies on the enhanced data type callbacks to
|
||||
* get key name and dbid on various operations.
|
||||
*
|
||||
* it simulates a simple memory allocator. The smallest allocation unit of
|
||||
* the allocator is a mem block with a size of 4KB. Multiple mem blocks are combined
|
||||
* it simulates a simple memory allocator. The smallest allocation unit of
|
||||
* the allocator is a mem block with a size of 4KB. Multiple mem blocks are combined
|
||||
* using a linked list. These linked lists are placed in a global dict named 'mem_pool'.
|
||||
* Each db has a 'mem_pool'. You can use the 'mem.alloc' command to allocate a specified
|
||||
* Each db has a 'mem_pool'. You can use the 'mem.alloc' command to allocate a specified
|
||||
* number of mem blocks, and use 'mem.free' to release the memory. Use 'mem.write', 'mem.read'
|
||||
* to write and read the specified mem block (note that each mem block can only be written once).
|
||||
* Use 'mem.usage' to get the memory usage under different dbs, and it will return the size
|
||||
* Use 'mem.usage' to get the memory usage under different dbs, and it will return the size
|
||||
* mem blocks and used mem blocks under the db.
|
||||
* The specific structure diagram is as follows:
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* Global variables of the module:
|
||||
*
|
||||
*
|
||||
* mem blocks link
|
||||
* ┌─────┬─────┐
|
||||
* │ │ │ ┌───┐ ┌───┐ ┌───┐
|
||||
@ -49,10 +49,10 @@
|
||||
* │ │ │ └───┘ └───┘
|
||||
* └─────┴─────┘
|
||||
* dict
|
||||
*
|
||||
*
|
||||
* Keys in redis database:
|
||||
*
|
||||
*
|
||||
*
|
||||
* Keys in redict database:
|
||||
*
|
||||
* ┌───────┐
|
||||
* │ size │
|
||||
* ┌───────────►│ used │
|
||||
@ -70,7 +70,7 @@
|
||||
* │ k3 │ ───┼─┐ │ k2 │ ───┼─┐
|
||||
* │ │ │ │ │ │ │ │
|
||||
* └─────┴─────┘ │ ┌───────┐ └─────┴─────┘ │ ┌───────┐
|
||||
* redis db[0] │ │ size │ redis db[1] │ │ size │
|
||||
* redict db[0] │ │ size │ redict db[1]│ │ size │
|
||||
* └───────────►│ used │ └───────────►│ used │
|
||||
* │ mask │ │ mask │
|
||||
* └───────┘ └───────┘
|
||||
@ -242,8 +242,8 @@ void flushdbCallback(RedictModuleCtx *ctx, RedictModuleEvent e, uint64_t sub, vo
|
||||
/*---------------------------- command implementation ------------------------------------*/
|
||||
|
||||
/* MEM.ALLOC key block_num */
|
||||
int MemAlloc_RedisCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
RedictModule_AutoMemory(ctx);
|
||||
int MemAlloc_RedictCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
RedictModule_AutoMemory(ctx);
|
||||
|
||||
if (argc != 3) {
|
||||
return RedictModule_WrongArity(ctx);
|
||||
@ -281,8 +281,8 @@ int MemAlloc_RedisCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int a
|
||||
}
|
||||
|
||||
/* MEM.FREE key */
|
||||
int MemFree_RedisCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
RedictModule_AutoMemory(ctx);
|
||||
int MemFree_RedictCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
RedictModule_AutoMemory(ctx);
|
||||
|
||||
if (argc != 2) {
|
||||
return RedictModule_WrongArity(ctx);
|
||||
@ -320,8 +320,8 @@ int MemFree_RedisCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int ar
|
||||
}
|
||||
|
||||
/* MEM.WRITE key block_index data */
|
||||
int MemWrite_RedisCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
RedictModule_AutoMemory(ctx);
|
||||
int MemWrite_RedictCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
RedictModule_AutoMemory(ctx);
|
||||
|
||||
if (argc != 4) {
|
||||
return RedictModule_WrongArity(ctx);
|
||||
@ -366,8 +366,8 @@ int MemWrite_RedisCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int a
|
||||
}
|
||||
|
||||
/* MEM.READ key block_index */
|
||||
int MemRead_RedisCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
RedictModule_AutoMemory(ctx);
|
||||
int MemRead_RedictCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
RedictModule_AutoMemory(ctx);
|
||||
|
||||
if (argc != 3) {
|
||||
return RedictModule_WrongArity(ctx);
|
||||
@ -398,18 +398,18 @@ int MemRead_RedisCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int ar
|
||||
int nokey;
|
||||
struct MemBlock *mem = (struct MemBlock *)RedictModule_DictGet(mem_pool[RedictModule_GetSelectedDb(ctx)], argv[1], &nokey);
|
||||
RedictModule_Assert(nokey == 0 && mem != NULL);
|
||||
|
||||
|
||||
char buf[BLOCK_SIZE];
|
||||
MemBlockRead(mem, block_index, buf, sizeof(buf));
|
||||
|
||||
|
||||
/* Assuming that the contents are all c-style strings */
|
||||
RedictModule_ReplyWithStringBuffer(ctx, buf, strlen(buf));
|
||||
return REDICTMODULE_OK;
|
||||
}
|
||||
|
||||
/* MEM.USAGE dbid */
|
||||
int MemUsage_RedisCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
RedictModule_AutoMemory(ctx);
|
||||
int MemUsage_RedictCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
RedictModule_AutoMemory(ctx);
|
||||
|
||||
if (argc != 2) {
|
||||
return RedictModule_WrongArity(ctx);
|
||||
@ -453,8 +453,8 @@ int MemUsage_RedisCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int a
|
||||
}
|
||||
|
||||
/* MEM.ALLOCANDWRITE key block_num block_index data block_index data ... */
|
||||
int MemAllocAndWrite_RedisCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
RedictModule_AutoMemory(ctx);
|
||||
int MemAllocAndWrite_RedictCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
RedictModule_AutoMemory(ctx);
|
||||
|
||||
if (argc < 3) {
|
||||
return RedictModule_WrongArity(ctx);
|
||||
@ -538,7 +538,7 @@ void *MemAllocRdbLoad(RedictModuleIO *rdb, int encver) {
|
||||
|
||||
RedictModule_DictSet(mem_pool[dbid], (RedictModuleString *)key, head);
|
||||
}
|
||||
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
@ -556,7 +556,7 @@ void MemAllocRdbSave(RedictModuleIO *rdb, void *value) {
|
||||
struct MemBlock *mem = (struct MemBlock *)RedictModule_DictGet(mem_pool[dbid], (RedictModuleString *)key, &nokey);
|
||||
RedictModule_Assert(nokey == 0 && mem != NULL);
|
||||
|
||||
struct MemBlock *block = mem;
|
||||
struct MemBlock *block = mem;
|
||||
while (block) {
|
||||
RedictModule_SaveStringBuffer(rdb, block->block, BLOCK_SIZE);
|
||||
block = block->next;
|
||||
@ -608,7 +608,7 @@ void MemAllocUnlink2(RedictModuleKeyOptCtx *ctx, const void *value) {
|
||||
|
||||
const RedictModuleString *key = RedictModule_GetKeyNameFromOptCtx(ctx);
|
||||
int dbid = RedictModule_GetDbIdFromOptCtx(ctx);
|
||||
|
||||
|
||||
if (o->size) {
|
||||
void *oldval;
|
||||
RedictModule_DictDel(mem_pool[dbid], (RedictModuleString *)key, &oldval);
|
||||
@ -625,7 +625,7 @@ void MemAllocDigest(RedictModuleDigest *md, void *value) {
|
||||
|
||||
int dbid = RedictModule_GetDbIdFromDigest(md);
|
||||
const RedictModuleString *key = RedictModule_GetKeyNameFromDigest(md);
|
||||
|
||||
|
||||
if (o->size) {
|
||||
int nokey;
|
||||
struct MemBlock *mem = (struct MemBlock *)RedictModule_DictGet(mem_pool[dbid], (RedictModuleString *)key, &nokey);
|
||||
@ -658,7 +658,7 @@ void *MemAllocCopy2(RedictModuleKeyOptCtx *ctx, const void *value) {
|
||||
struct MemBlock *newmem = MemBlockClone(oldmem);
|
||||
RedictModule_Assert(newmem != NULL);
|
||||
RedictModule_DictSet(mem_pool[to_dbid], (RedictModuleString *)tokey, newmem);
|
||||
}
|
||||
}
|
||||
|
||||
return new;
|
||||
}
|
||||
@ -709,28 +709,28 @@ int RedictModule_OnLoad(RedictModuleCtx *ctx, RedictModuleString **argv, int arg
|
||||
return REDICTMODULE_ERR;
|
||||
}
|
||||
|
||||
if (RedictModule_CreateCommand(ctx, "mem.alloc", MemAlloc_RedisCommand, "write deny-oom", 1, 1, 1) == REDICTMODULE_ERR) {
|
||||
if (RedictModule_CreateCommand(ctx, "mem.alloc", MemAlloc_RedictCommand, "write deny-oom", 1, 1, 1) == REDICTMODULE_ERR) {
|
||||
return REDICTMODULE_ERR;
|
||||
}
|
||||
|
||||
if (RedictModule_CreateCommand(ctx, "mem.free", MemFree_RedisCommand, "write deny-oom", 1, 1, 1) == REDICTMODULE_ERR) {
|
||||
if (RedictModule_CreateCommand(ctx, "mem.free", MemFree_RedictCommand, "write deny-oom", 1, 1, 1) == REDICTMODULE_ERR) {
|
||||
return REDICTMODULE_ERR;
|
||||
}
|
||||
|
||||
if (RedictModule_CreateCommand(ctx, "mem.write", MemWrite_RedisCommand, "write deny-oom", 1, 1, 1) == REDICTMODULE_ERR) {
|
||||
if (RedictModule_CreateCommand(ctx, "mem.write", MemWrite_RedictCommand, "write deny-oom", 1, 1, 1) == REDICTMODULE_ERR) {
|
||||
return REDICTMODULE_ERR;
|
||||
}
|
||||
|
||||
if (RedictModule_CreateCommand(ctx, "mem.read", MemRead_RedisCommand, "readonly", 1, 1, 1) == REDICTMODULE_ERR) {
|
||||
if (RedictModule_CreateCommand(ctx, "mem.read", MemRead_RedictCommand, "readonly", 1, 1, 1) == REDICTMODULE_ERR) {
|
||||
return REDICTMODULE_ERR;
|
||||
}
|
||||
|
||||
if (RedictModule_CreateCommand(ctx, "mem.usage", MemUsage_RedisCommand, "readonly", 1, 1, 1) == REDICTMODULE_ERR) {
|
||||
if (RedictModule_CreateCommand(ctx, "mem.usage", MemUsage_RedictCommand, "readonly", 1, 1, 1) == REDICTMODULE_ERR) {
|
||||
return REDICTMODULE_ERR;
|
||||
}
|
||||
|
||||
/* used for internal aof rewrite */
|
||||
if (RedictModule_CreateCommand(ctx, "mem.allocandwrite", MemAllocAndWrite_RedisCommand, "write deny-oom", 1, 1, 1) == REDICTMODULE_ERR) {
|
||||
if (RedictModule_CreateCommand(ctx, "mem.allocandwrite", MemAllocAndWrite_RedictCommand, "write deny-oom", 1, 1, 1) == REDICTMODULE_ERR) {
|
||||
return REDICTMODULE_ERR;
|
||||
}
|
||||
|
||||
@ -740,6 +740,6 @@ int RedictModule_OnLoad(RedictModuleCtx *ctx, RedictModuleString **argv, int arg
|
||||
|
||||
RedictModule_SubscribeToServerEvent(ctx, RedictModuleEvent_FlushDB, flushdbCallback);
|
||||
RedictModule_SubscribeToServerEvent(ctx, RedictModuleEvent_SwapDB, swapDbCallback);
|
||||
|
||||
|
||||
return REDICTMODULE_OK;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ int fork_create(RedictModuleCtx *ctx, RedictModuleString **argv, int argc)
|
||||
}
|
||||
|
||||
if(!RMAPI_FUNC_SUPPORTED(RedictModule_Fork)){
|
||||
RedictModule_ReplyWithError(ctx, "Fork api is not supported in the current redis version");
|
||||
RedictModule_ReplyWithError(ctx, "Fork api is not supported in the current redict version");
|
||||
return REDICTMODULE_OK;
|
||||
}
|
||||
|
||||
|
@ -180,7 +180,7 @@ void persistenceCallback(RedictModuleCtx *ctx, RedictModuleEvent e, uint64_t sub
|
||||
/* modifying the keyspace from the fork child is not an option, using log instead */
|
||||
RedictModule_Log(ctx, "warning", "module-event-%s", keyname);
|
||||
if (sub == REDICTMODULE_SUBEVENT_PERSISTENCE_SYNC_RDB_START ||
|
||||
sub == REDICTMODULE_SUBEVENT_PERSISTENCE_SYNC_AOF_START)
|
||||
sub == REDICTMODULE_SUBEVENT_PERSISTENCE_SYNC_AOF_START)
|
||||
{
|
||||
LogNumericEvent(ctx, keyname, 0);
|
||||
}
|
||||
@ -375,8 +375,8 @@ static int cmdKeyExpiry(RedictModuleCtx *ctx, RedictModuleString **argv, int arg
|
||||
return REDICTMODULE_OK;
|
||||
}
|
||||
|
||||
/* This function must be present on each Redis module. It is used in order to
|
||||
* register the commands into the Redis server. */
|
||||
/* This function must be present on each Redict module. It is used in order to
|
||||
* register the commands into the Redict server. */
|
||||
int RedictModule_OnLoad(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
#define VerifySubEventSupported(e, s) \
|
||||
if (!RedictModule_IsSubEventSupported(e, s)) { \
|
||||
|
@ -110,16 +110,16 @@ static int KeySpace_NotificationModuleKeyMiss(RedictModuleCtx *ctx, int type, co
|
||||
static int KeySpace_NotificationModuleString(RedictModuleCtx *ctx, int type, const char *event, RedictModuleString *key) {
|
||||
REDICTMODULE_NOT_USED(type);
|
||||
REDICTMODULE_NOT_USED(event);
|
||||
RedictModuleKey *redis_key = RedictModule_OpenKey(ctx, key, REDICTMODULE_READ);
|
||||
RedictModuleKey *redict_key = RedictModule_OpenKey(ctx, key, REDICTMODULE_READ);
|
||||
|
||||
size_t len = 0;
|
||||
/* RedictModule_StringDMA could change the data format and cause the old robj to be freed.
|
||||
* This code verifies that such format change will not cause any crashes.*/
|
||||
char *data = RedictModule_StringDMA(redis_key, &len, REDICTMODULE_READ);
|
||||
char *data = RedictModule_StringDMA(redict_key, &len, REDICTMODULE_READ);
|
||||
int res = strncmp(data, "dummy", 5);
|
||||
REDICTMODULE_NOT_USED(res);
|
||||
|
||||
RedictModule_CloseKey(redis_key);
|
||||
RedictModule_CloseKey(redict_key);
|
||||
|
||||
return REDICTMODULE_OK;
|
||||
}
|
||||
@ -291,8 +291,8 @@ static int cmdGetDels(RedictModuleCtx *ctx, RedictModuleString **argv, int argc)
|
||||
return RedictModule_ReplyWithLongLong(ctx, dels);
|
||||
}
|
||||
|
||||
/* This function must be present on each Redis module. It is used in order to
|
||||
* register the commands into the Redis server. */
|
||||
/* This function must be present on each Redict module. It is used in order to
|
||||
* register the commands into the Redict server. */
|
||||
int RedictModule_OnLoad(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
if (RedictModule_Init(ctx,"testkeyspace",1,REDICTMODULE_APIVER_1) == REDICTMODULE_ERR){
|
||||
return REDICTMODULE_ERR;
|
||||
@ -352,17 +352,17 @@ int RedictModule_OnLoad(RedictModuleCtx *ctx, RedictModuleString **argv, int arg
|
||||
"write", 0, 0, 0) == REDICTMODULE_ERR){
|
||||
return REDICTMODULE_ERR;
|
||||
}
|
||||
|
||||
|
||||
if (RedictModule_CreateCommand(ctx, "keyspace.incr_case1", cmdIncrCase1,
|
||||
"write", 0, 0, 0) == REDICTMODULE_ERR){
|
||||
return REDICTMODULE_ERR;
|
||||
}
|
||||
|
||||
|
||||
if (RedictModule_CreateCommand(ctx, "keyspace.incr_case2", cmdIncrCase2,
|
||||
"write", 0, 0, 0) == REDICTMODULE_ERR){
|
||||
return REDICTMODULE_ERR;
|
||||
}
|
||||
|
||||
|
||||
if (RedictModule_CreateCommand(ctx, "keyspace.incr_case3", cmdIncrCase3,
|
||||
"write", 0, 0, 0) == REDICTMODULE_ERR){
|
||||
return REDICTMODULE_ERR;
|
||||
|
@ -219,8 +219,8 @@ static void KeySpace_ServerEventCallback(RedictModuleCtx *ctx, RedictModuleEvent
|
||||
if (res == REDICTMODULE_ERR) KeySpace_ServerEventPostNotificationFree(pn_ctx);
|
||||
}
|
||||
|
||||
/* This function must be present on each Redis module. It is used in order to
|
||||
* register the commands into the Redis server. */
|
||||
/* This function must be present on each Redict module. It is used in order to
|
||||
* register the commands into the Redict server. */
|
||||
int RedictModule_OnLoad(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
REDICTMODULE_NOT_USED(argv);
|
||||
REDICTMODULE_NOT_USED(argc);
|
||||
|
@ -127,7 +127,7 @@ void timerHandlerEval(RedictModuleCtx *ctx, void *data) {
|
||||
|
||||
RedictModuleCallReply *reply = RedictModule_Call(ctx,"INCRBY","cc!","timer-eval-start","1");
|
||||
RedictModule_FreeCallReply(reply);
|
||||
reply = RedictModule_Call(ctx, "EVAL", "cccc!", "redis.call('set',KEYS[1],ARGV[1])", "1", "foo", "bar");
|
||||
reply = RedictModule_Call(ctx, "EVAL", "cccc!", "redict.call('set',KEYS[1],ARGV[1])", "1", "foo", "bar");
|
||||
RedictModule_FreeCallReply(reply);
|
||||
|
||||
RedictModule_Replicate(ctx, "INCR", "c", "timer-eval-middle");
|
||||
|
@ -64,7 +64,7 @@ void LazyFreeLinkReleaseObject(struct LazyFreeLinkObject *o) {
|
||||
}
|
||||
|
||||
/* LAZYFREELINK.INSERT key value */
|
||||
int LazyFreeLinkInsert_RedisCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
int LazyFreeLinkInsert_RedictCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
RedictModule_AutoMemory(ctx); /* Use automatic memory management. */
|
||||
|
||||
if (argc != 3) return RedictModule_WrongArity(ctx);
|
||||
@ -99,7 +99,7 @@ int LazyFreeLinkInsert_RedisCommand(RedictModuleCtx *ctx, RedictModuleString **a
|
||||
}
|
||||
|
||||
/* LAZYFREELINK.LEN key */
|
||||
int LazyFreeLinkLen_RedisCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
int LazyFreeLinkLen_RedictCommand(RedictModuleCtx *ctx, RedictModuleString **argv, int argc) {
|
||||
RedictModule_AutoMemory(ctx); /* Use automatic memory management. */
|
||||
|
||||
if (argc != 2) return RedictModule_WrongArity(ctx);
|
||||
@ -172,7 +172,7 @@ int RedictModule_OnLoad(RedictModuleCtx *ctx, RedictModuleString **argv, int arg
|
||||
if (RedictModule_Init(ctx,"lazyfreetest",1,REDICTMODULE_APIVER_1)
|
||||
== REDICTMODULE_ERR) return REDICTMODULE_ERR;
|
||||
|
||||
/* We only allow our module to be loaded when the redis core version is greater than the version of my module */
|
||||
/* We only allow our module to be loaded when the Redict core version is greater than the version of my module */
|
||||
if (RedictModule_GetTypeMethodVersion() < REDICTMODULE_TYPE_METHOD_VERSION) {
|
||||
return REDICTMODULE_ERR;
|
||||
}
|
||||
@ -191,11 +191,11 @@ int RedictModule_OnLoad(RedictModuleCtx *ctx, RedictModuleString **argv, int arg
|
||||
if (LazyFreeLinkType == NULL) return REDICTMODULE_ERR;
|
||||
|
||||
if (RedictModule_CreateCommand(ctx,"lazyfreelink.insert",
|
||||
LazyFreeLinkInsert_RedisCommand,"write deny-oom",1,1,1) == REDICTMODULE_ERR)
|
||||
LazyFreeLinkInsert_RedictCommand,"write deny-oom",1,1,1) == REDICTMODULE_ERR)
|
||||
return REDICTMODULE_ERR;
|
||||
|
||||
if (RedictModule_CreateCommand(ctx,"lazyfreelink.len",
|
||||
LazyFreeLinkLen_RedisCommand,"readonly",1,1,1) == REDICTMODULE_ERR)
|
||||
LazyFreeLinkLen_RedictCommand,"readonly",1,1,1) == REDICTMODULE_ERR)
|
||||
return REDICTMODULE_ERR;
|
||||
|
||||
return REDICTMODULE_OK;
|
||||
|
@ -123,7 +123,7 @@ void *bg_call_worker(void *arg) {
|
||||
bg_call_data *bg = arg;
|
||||
RedictModuleBlockedClient *bc = bg->bc;
|
||||
|
||||
// Get Redis module context
|
||||
// Get Redict module context
|
||||
RedictModuleCtx *ctx = RedictModule_GetThreadSafeContext(bg->bc);
|
||||
|
||||
// Acquire GIL
|
||||
@ -134,14 +134,14 @@ void *bg_call_worker(void *arg) {
|
||||
|
||||
// Call the command
|
||||
size_t format_len;
|
||||
RedictModuleString *format_redis_str = RedictModule_CreateString(NULL, "v", 1);
|
||||
RedictModuleString *format_redict_str = RedictModule_CreateString(NULL, "v", 1);
|
||||
const char *format = RedictModule_StringPtrLen(bg->argv[1], &format_len);
|
||||
RedictModule_StringAppendBuffer(NULL, format_redis_str, format, format_len);
|
||||
RedictModule_StringAppendBuffer(NULL, format_redis_str, "E", 1);
|
||||
format = RedictModule_StringPtrLen(format_redis_str, NULL);
|
||||
RedictModule_StringAppendBuffer(NULL, format_redict_str, format, format_len);
|
||||
RedictModule_StringAppendBuffer(NULL, format_redict_str, "E", 1);
|
||||
format = RedictModule_StringPtrLen(format_redict_str, NULL);
|
||||
const char *cmd = RedictModule_StringPtrLen(bg->argv[2], NULL);
|
||||
RedictModuleCallReply *rep = RedictModule_Call(ctx, cmd, format, bg->argv + 3, bg->argc - 3);
|
||||
RedictModule_FreeString(NULL, format_redis_str);
|
||||
RedictModule_FreeString(NULL, format_redict_str);
|
||||
|
||||
/* Free the arguments within GIL to prevent simultaneous freeing in main thread. */
|
||||
for (int i=0; i<bg->argc; i++)
|
||||
@ -163,7 +163,7 @@ void *bg_call_worker(void *arg) {
|
||||
// Unblock client
|
||||
RedictModule_UnblockClient(bc, NULL);
|
||||
|
||||
// Free the Redis module context
|
||||
// Free the Redict module context
|
||||
RedictModule_FreeThreadSafeContext(ctx);
|
||||
|
||||
return NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user