+1
−0
lib/labkit/redis.rb
0 → 100644
+8
−0
lib/labkit/redis/script.rb
0 → 100644
+43
−0
Loading
The Evaluator's EVALSHA-with-NOSCRIPT-fallback dispatch is a generic Lua
primitive that has no rate-limit-specific knowledge. Pull it out into
Labkit::Redis::Script so:
- Other Labkit callers can reuse the pattern (the monolith currently
has unguarded eval/evalsha call sites that could benefit).
- EVALSHA-vs-EVAL dispatch correctness can be tested in isolation,
via a spy connection that counts calls — the previous coverage in
evaluator_spec could only observe \"didn't raise\", which doesn't
distinguish a cached hit from a NOSCRIPT recovery.
Behavior is unchanged: the Lua body, the SHA1 digest, the NOSCRIPT
detection on Redis::CommandError.message, and the EVAL fallback shape
all carry over verbatim. The Evaluator keeps a single Script instance
on the class as INCR_SCRIPT (per-process), and the per-call eval just
threads the checked-out connection through to Script#eval.
The new spec covers happy path + SCRIPT FLUSH recovery against real
Redis, plus EVALSHA/EVAL dispatch counts and WRONGTYPE propagation via
a spy conn. The two equivalent tests in evaluator_spec drop in favor
of one wiring-smoke test that the Evaluator still survives a flush.
Addresses !291 review threads
5e1f3e92 and 3058e1cd.