Skip to content

Commit e08fe1f

Browse files
authored
DX-2002: use eval instead of scriptload and evalsha (#137)
* fix: use eval instead of scriptload and evalsha old version uses two commands while it is possible with a single command. also, I think script load doesn't increment ryw counter so it's possible to try to use evalsha on a script which hasn't actually loaded in a read replica * fix: test
1 parent 1e57ef1 commit e08fe1f

File tree

2 files changed

+2
-12
lines changed

2 files changed

+2
-12
lines changed

src/cache.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ test("ephemeral cache", async () => {
3838
}
3939

4040
expect(passes).toBeLessThanOrEqual(10);
41-
expect(metrics.evalsha).toBe(12);
41+
expect(metrics.evalsha).toBe(11);
4242
expect(reasons).toContain("cacheBlock")
4343

4444
await new Promise((r) => setTimeout(r, 5000));

src/hash.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,7 @@ export const safeEval = async (
2222
return await ctx.redis.evalsha(script.hash, keys, args)
2323
} catch (error) {
2424
if (`${error}`.includes("NOSCRIPT")) {
25-
const hash = await ctx.redis.scriptLoad(script.script)
26-
27-
if (hash !== script.hash) {
28-
console.warn(
29-
"Upstash Ratelimit: Expected hash and the hash received from Redis"
30-
+ " are different. Ratelimit will work as usual but performance will"
31-
+ " be reduced."
32-
);
33-
}
34-
35-
return await ctx.redis.evalsha(hash, keys, args)
25+
return await ctx.redis.eval(script.script, keys, args)
3626
}
3727
throw error;
3828
}

0 commit comments

Comments
 (0)