Menu

1 / 2

Redis 8.4's digest-based SET option cuts a 1MB compare-and-set from 4.3ms to 1.6ms

DEV Community: redis·Alex Georgiev·about 18 hours ago
#f46oXzSG
#devtoredis#devto#dev#ifeq#digest
Reading 0:00
15s threshold

I keep a cached object in Redis that several workers read and occasionally rewrite. Before writing, each worker has to check that nobody else changed the object since it was last read, or the write clobbers someone else's update. Redis never had one command for that. You used WATCH / MULTI / EXEC , or a Lua script that reads and compares server-side, or you accepted the race and moved on.

Redis 8.4 adds four conditions to SET : IFEQ , IFNE , IFDEQ and IFDNE . The first two compare against a literal value. The last two compare against a digest, a 16-character hex hash the server computes with DIGEST . I pulled redis:8.4 and ran all four against the patterns they replace.

The headline number

The point of a digest is that you don't send the value you're comparing against, you send its hash. For a small string that saves nothing.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.