redis-js
redis-js copied to clipboard
ioredis' defineCommand similar implementation
Hey,
We're looking into this library to replace ioredis in our code for our firebase functions and gain some speed.
I'm wondering if we could have a similar kind of function like defineCommand in ioredis (https://github.com/luin/ioredis#lua-scripting) which would take care of the script caching logic and execution?
This would save us a lot of time on writing our own implementation and error handling for scripting in redis.
Hey @donaldrevel , I've created a release candidate with this feature npm install @upstash/[email protected]
You can now create a new script instance and then execute it.
import { Redis } from "@upstash/redis";
const redis = Redis.fromEnv()
const script = "return ARGV[1];"
const echo = redis.createScript(script)
const res = await echo.exec([/* Keys go here */], ["value1"])
// res -> "value1"
Under the hood it will calculate the sha1 of the script and try calling EVALSHA
first and if the script is not yet loaded to the server it falls back to EVAL
. Afterwards the script will be on the server and only the sha1 will be sent over the wire.
Does this solve your problem?
Yes that's great @chronark Thanks for this I haven't had the time to look into this yet, I'll get to this next week. I'll provide some feedback then
It's in v1.12.0
Let me know once you have time to check and have some feedback :)