Redis append command efficiently appends a value to an existing string. I think when an application needs the append command, it probably needs to un-append as well.
So a proposed truncate key n will remove the last n bytes of string key. To have O(1) amortized time complexity, it should only reallocate the memory if a constant portion of the memory (e.g. half) can be freed.
Comment From: itamarhaber
I can grok the logic. If we get a consensus, it may happen.
Comment From: halaei
Thanks @itamarhaber .
There already exists a module API for that, RedisModule_StringTruncate(), so I assume the implementation will be super-easy with minimum added-complexity to the code. However, currently I find no way to call truncate on a key in a Redis Module :(
Comment From: halaei
Oh I was wrong. RedisModule_StringTruncate() accepts key :)
Comment From: itamarhaber
Yep - totally doable w/ a module.
Comment From: neomantra
If you use function RedisModule_StringTruncate, be aware of issue #3717.
You can also check out the CHOP pull request for the rxstrings module.