mirror of
https://github.com/fluencelabs/redis
synced 2025-06-13 09:11:20 +00:00
added RM_CreateStringPrintf
This commit is contained in:
25
src/module.c
25
src/module.c
@ -681,13 +681,33 @@ void autoMemoryCollect(RedisModuleCtx *ctx) {
|
||||
*
|
||||
* The string is created by copying the `len` bytes starting
|
||||
* at `ptr`. No reference is retained to the passed buffer. */
|
||||
RedisModuleString *RM_CreateString(RedisModuleCtx *ctx, const char *ptr, size_t len)
|
||||
{
|
||||
RedisModuleString *RM_CreateString(RedisModuleCtx *ctx, const char *ptr, size_t len) {
|
||||
RedisModuleString *o = createStringObject(ptr,len);
|
||||
autoMemoryAdd(ctx,REDISMODULE_AM_STRING,o);
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
/* Create a new module string object from a printf format and arguments.
|
||||
* The returned string must be freed with RedisModule_FreeString(), unless automatic
|
||||
* memory is enabled.
|
||||
*
|
||||
* The string is created using the sds formatter function sdscatvprintf() */
|
||||
RedisModuleString *RM_CreateStringPrintf(RedisModuleCtx *ctx, const char *fmt, ...) {
|
||||
sds s = sdsempty();
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
s = sdscatvprintf(s, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
RedisModuleString *o = createObject(OBJ_STRING, s);
|
||||
autoMemoryAdd(ctx,REDISMODULE_AM_STRING,o);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
/* Like RedisModule_CreatString(), but creates a string starting from a long long
|
||||
* integer instead of taking a buffer and its length.
|
||||
*
|
||||
@ -3194,6 +3214,7 @@ void moduleRegisterCoreAPI(void) {
|
||||
REGISTER_API(CreateString);
|
||||
REGISTER_API(CreateStringFromLongLong);
|
||||
REGISTER_API(CreateStringFromString);
|
||||
REGISTER_API(CreateStringPrintf);
|
||||
REGISTER_API(FreeString);
|
||||
REGISTER_API(StringPtrLen);
|
||||
REGISTER_API(AutoMemory);
|
||||
|
Reference in New Issue
Block a user