4 ms·
I'd save the commands to a buffer and apply them at the successful termination of the script. See "batched staging", trying to reverse a data structure already
by sitkack 11y ago
I'd save the commands to a buffer and apply them at the successful termination of the script. See "batched staging", trying to reverse a data structure already mutated will be problematic. This is actually how one should write lua scripts in Redis anyway.
- joeskyyy 11y agoI'd agree to this whole heartedly. At first glance (if I'm understanding your implementation correctly), it appears like you're already going to use up the same amount of space a buffer would anyway. In this case you're just tasking the LUA best practice, but making it a feature within Redis itself. Regardless I think you're really onto something that people want. There's going to be a trade off one way or another, but the Redis community is all about speed, so the faster and more efficient you can do it, the better (:
- DrJosiah 11y agoI agree on the speed side of things... but see my reply to the other comment. TL;DR; Buffer or not, mutations are necessary to be visible as part of script execution, which precludes "only write at the end on success".
- DrJosiah 11y agoThe problem is: when you are mutating the structures as part of the script, and you are accessing the results of those mutations, you can't just "apply them at the successful termination of the script". The successful termination requires that the mutations be visible - aka the mutations already applied. In a relational database this isn't normally a big deal, because the structures themselves (rows and indexes) are already versioned, and most rows are of a relatively-small size. So rows typically work well for intent/write-ahead logs, old/new version logs, etc. But with Redis, operations aren't just on a "row", it's on a structure, and that structure can be gigabytes in size (I had a 30 gigabyte ZSET about 4 1/2 years ago, that was no fun during snapshotting, let me tell you).