"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/module.c" between
redis-6.2.4.tar.gz and redis-6.2.5.tar.gz

About: redis is an advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

module.c  (redis-6.2.4):module.c  (redis-6.2.5)
skipping to change at line 2541 skipping to change at line 2541
genericSetKey(key->ctx->client,key->db,key->key,o,0,0); genericSetKey(key->ctx->client,key->db,key->key,o,0,0);
key->value = o; key->value = o;
decrRefCount(o); decrRefCount(o);
} else { } else {
/* Unshare and resize. */ /* Unshare and resize. */
key->value = dbUnshareStringValue(key->db, key->key, key->value); key->value = dbUnshareStringValue(key->db, key->key, key->value);
size_t curlen = sdslen(key->value->ptr); size_t curlen = sdslen(key->value->ptr);
if (newlen > curlen) { if (newlen > curlen) {
key->value->ptr = sdsgrowzero(key->value->ptr,newlen); key->value->ptr = sdsgrowzero(key->value->ptr,newlen);
} else if (newlen < curlen) { } else if (newlen < curlen) {
sdsrange(key->value->ptr,0,newlen-1); sdssubstr(key->value->ptr,0,newlen);
/* If the string is too wasteful, reallocate it. */ /* If the string is too wasteful, reallocate it. */
if (sdslen(key->value->ptr) < sdsavail(key->value->ptr)) if (sdslen(key->value->ptr) < sdsavail(key->value->ptr))
key->value->ptr = sdsRemoveFreeSpace(key->value->ptr); key->value->ptr = sdsRemoveFreeSpace(key->value->ptr);
} }
} }
return REDISMODULE_OK; return REDISMODULE_OK;
} }
/* -------------------------------------------------------------------------- /* --------------------------------------------------------------------------
* ## Key API for List type * ## Key API for List type
skipping to change at line 5361 skipping to change at line 5361
/* Block a client in the context of a blocking command, returning an handle /* Block a client in the context of a blocking command, returning an handle
* which will be used, later, in order to unblock the client with a call to * which will be used, later, in order to unblock the client with a call to
* RedisModule_UnblockClient(). The arguments specify callback functions * RedisModule_UnblockClient(). The arguments specify callback functions
* and a timeout after which the client is unblocked. * and a timeout after which the client is unblocked.
* *
* The callbacks are called in the following contexts: * The callbacks are called in the following contexts:
* *
* reply_callback: called after a successful RedisModule_UnblockClient() * reply_callback: called after a successful RedisModule_UnblockClient()
* call in order to reply to the client and unblock it. * call in order to reply to the client and unblock it.
* *
* timeout_callback: called when the timeout is reached in order to send an * timeout_callback: called when the timeout is reached or if `CLIENT UNBLOC
* error to the client. K`
* is invoked, in order to send an error to the client.
* *
* free_privdata: called in order to free the private data that is passed * free_privdata: called in order to free the private data that is passed
* by RedisModule_UnblockClient() call. * by RedisModule_UnblockClient() call.
* *
* Note: RedisModule_UnblockClient should be called for every blocked client, * Note: RedisModule_UnblockClient should be called for every blocked client,
* even if client was killed, timed-out or disconnected. Failing to do so * even if client was killed, timed-out or disconnected. Failing to do so
* will result in memory leaks. * will result in memory leaks.
* *
* There are some cases where RedisModule_BlockClient() cannot be used: * There are some cases where RedisModule_BlockClient() cannot be used:
* *
* 1. If the client is a Lua script. * 1. If the client is a Lua script.
* 2. If the client is executing a MULTI block. * 2. If the client is executing a MULTI block.
* *
* In these cases, a call to RedisModule_BlockClient() will **not** block the * In these cases, a call to RedisModule_BlockClient() will **not** block the
* client, but instead produce a specific error reply. * client, but instead produce a specific error reply.
* *
* A module that registers a timeout_callback function can also be unblocked
* using the `CLIENT UNBLOCK` command, which will trigger the timeout callback.
* If a callback function is not registered, then the blocked client will be
* treated as if it is not in a blocked state and `CLIENT UNBLOCK` will return
* a zero value.
*
* Measuring background time: By default the time spent in the blocked command * Measuring background time: By default the time spent in the blocked command
* is not account for the total command duration. To include such time you shoul d * is not account for the total command duration. To include such time you shoul d
* use RM_BlockedClientMeasureTimeStart() and RM_BlockedClientMeasureTimeEnd() o ne, * use RM_BlockedClientMeasureTimeStart() and RM_BlockedClientMeasureTimeEnd() o ne,
* or multiple times within the blocking command background work. * or multiple times within the blocking command background work.
*/ */
RedisModuleBlockedClient *RM_BlockClient(RedisModuleCtx *ctx, RedisModuleCmdFunc reply_callback, RedisModuleCmdFunc timeout_callback, void (*free_privdata)(Redi sModuleCtx*,void*), long long timeout_ms) { RedisModuleBlockedClient *RM_BlockClient(RedisModuleCtx *ctx, RedisModuleCmdFunc reply_callback, RedisModuleCmdFunc timeout_callback, void (*free_privdata)(Redi sModuleCtx*,void*), long long timeout_ms) {
return moduleBlockClient(ctx,reply_callback,timeout_callback,free_privdata,t imeout_ms, NULL,0,NULL); return moduleBlockClient(ctx,reply_callback,timeout_callback,free_privdata,t imeout_ms, NULL,0,NULL);
} }
/* This call is similar to RedisModule_BlockClient(), however in this case we /* This call is similar to RedisModule_BlockClient(), however in this case we
skipping to change at line 5648 skipping to change at line 5654
* when calling unblockClient(). */ * when calling unblockClient(). */
bc->module->blocked_clients--; bc->module->blocked_clients--;
zfree(bc); zfree(bc);
/* Lock again before to iterate the loop. */ /* Lock again before to iterate the loop. */
pthread_mutex_lock(&moduleUnblockedClientsMutex); pthread_mutex_lock(&moduleUnblockedClientsMutex);
} }
pthread_mutex_unlock(&moduleUnblockedClientsMutex); pthread_mutex_unlock(&moduleUnblockedClientsMutex);
} }
/* Check if the specified client can be safely timed out using
* moduleBlockedClientTimedOut().
*/
int moduleBlockedClientMayTimeout(client *c) {
if (c->btype != BLOCKED_MODULE)
return 1;
RedisModuleBlockedClient *bc = c->bpop.module_blocked_handle;
return (bc && bc->timeout_callback != NULL);
}
/* Called when our client timed out. After this function unblockClient() /* Called when our client timed out. After this function unblockClient()
* is called, and it will invalidate the blocked client. So this function * is called, and it will invalidate the blocked client. So this function
* does not need to do any cleanup. Eventually the module will call the * does not need to do any cleanup. Eventually the module will call the
* API to unblock the client and the memory will be released. */ * API to unblock the client and the memory will be released. */
void moduleBlockedClientTimedOut(client *c) { void moduleBlockedClientTimedOut(client *c) {
RedisModuleBlockedClient *bc = c->bpop.module_blocked_handle; RedisModuleBlockedClient *bc = c->bpop.module_blocked_handle;
/* Protect against re-processing: don't serve clients that are already /* Protect against re-processing: don't serve clients that are already
* in the unblocking list for any reason (including RM_UnblockClient() * in the unblocking list for any reason (including RM_UnblockClient()
* explicit call). See #6798. */ * explicit call). See #6798. */
skipping to change at line 8671 skipping to change at line 8688
/* Helper for genModulesInfoString(): given a list of modules, return /* Helper for genModulesInfoString(): given a list of modules, return
* am SDS string in the form "[modulename|modulename2|...]" */ * am SDS string in the form "[modulename|modulename2|...]" */
sds genModulesInfoStringRenderModulesList(list *l) { sds genModulesInfoStringRenderModulesList(list *l) {
listIter li; listIter li;
listNode *ln; listNode *ln;
listRewind(l,&li); listRewind(l,&li);
sds output = sdsnew("["); sds output = sdsnew("[");
while((ln = listNext(&li))) { while((ln = listNext(&li))) {
RedisModule *module = ln->value; RedisModule *module = ln->value;
output = sdscat(output,module->name); output = sdscat(output,module->name);
if (ln != listLast(l))
output = sdscat(output,"|");
} }
output = sdstrim(output,"|");
output = sdscat(output,"]"); output = sdscat(output,"]");
return output; return output;
} }
/* Helper for genModulesInfoString(): render module options as an SDS string. */ /* Helper for genModulesInfoString(): render module options as an SDS string. */
sds genModulesInfoStringRenderModuleOptions(struct RedisModule *module) { sds genModulesInfoStringRenderModuleOptions(struct RedisModule *module) {
sds output = sdsnew("["); sds output = sdsnew("[");
if (module->options & REDISMODULE_OPTIONS_HANDLE_IO_ERRORS) if (module->options & REDISMODULE_OPTIONS_HANDLE_IO_ERRORS)
output = sdscat(output,"handle-io-errors|"); output = sdscat(output,"handle-io-errors|");
output = sdstrim(output,"|"); output = sdstrim(output,"|");
skipping to change at line 8997 skipping to change at line 9015
/* We return the heap based array and intentionally avoid calling /* We return the heap based array and intentionally avoid calling
* getKeysFreeResult() here, as it is the caller's responsibility * getKeysFreeResult() here, as it is the caller's responsibility
* to free this array. * to free this array.
*/ */
res = result.keys; res = result.keys;
} }
return res; return res;
} }
/* Return the name of the command currently running */
const char *RM_GetCurrentCommandName(RedisModuleCtx *ctx) {
if (!ctx || !ctx->client || !ctx->client->cmd)
return NULL;
return (const char*)ctx->client->cmd->name;
}
/* -------------------------------------------------------------------------- /* --------------------------------------------------------------------------
* ## Defrag API * ## Defrag API
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
/* The defrag context, used to manage state during calls to the data type /* The defrag context, used to manage state during calls to the data type
* defrag callback. * defrag callback.
*/ */
typedef struct RedisModuleDefragCtx { typedef struct RedisModuleDefragCtx {
long defragged; long defragged;
long long int endtime; long long int endtime;
skipping to change at line 9457 skipping to change at line 9483
REGISTER_API(FreeModuleUser); REGISTER_API(FreeModuleUser);
REGISTER_API(DeauthenticateAndCloseClient); REGISTER_API(DeauthenticateAndCloseClient);
REGISTER_API(AuthenticateClientWithACLUser); REGISTER_API(AuthenticateClientWithACLUser);
REGISTER_API(AuthenticateClientWithUser); REGISTER_API(AuthenticateClientWithUser);
REGISTER_API(GetContextFlagsAll); REGISTER_API(GetContextFlagsAll);
REGISTER_API(GetKeyspaceNotificationFlagsAll); REGISTER_API(GetKeyspaceNotificationFlagsAll);
REGISTER_API(IsSubEventSupported); REGISTER_API(IsSubEventSupported);
REGISTER_API(GetServerVersion); REGISTER_API(GetServerVersion);
REGISTER_API(GetClientCertificate); REGISTER_API(GetClientCertificate);
REGISTER_API(GetCommandKeys); REGISTER_API(GetCommandKeys);
REGISTER_API(GetCurrentCommandName);
REGISTER_API(GetTypeMethodVersion); REGISTER_API(GetTypeMethodVersion);
REGISTER_API(RegisterDefragFunc); REGISTER_API(RegisterDefragFunc);
REGISTER_API(DefragAlloc); REGISTER_API(DefragAlloc);
REGISTER_API(DefragRedisModuleString); REGISTER_API(DefragRedisModuleString);
REGISTER_API(DefragShouldStop); REGISTER_API(DefragShouldStop);
REGISTER_API(DefragCursorSet); REGISTER_API(DefragCursorSet);
REGISTER_API(DefragCursorGet); REGISTER_API(DefragCursorGet);
} }
 End of changes. 8 change blocks. 
4 lines changed or deleted 32 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)