Hi we use the lua script to set a key expire time after incr like:

local result = redis.call("INCRBY", KEYS[1], ARGV[1])
if(result == 1)
then
redis.call("EXPIREAT", KEYS[1], ARGV[2])
end
return result

But after version 7.0.0, is it better to use the "NX" option to set the expiration time?

local result = redis.call("INCRBY", KEYS[1], ARGV[1])
redis.call("EXPIREAT", KEYS[1], ARGV[2], "NX")
return result

Comment From: zuiderkwast

Both versions seem equivalent to me.

I guess NX is useful if you want to call both commands in a pipeline without Lua.

If you have performance problems you can test which one is faster, but otherwise there is no point changing it IMO.

Comment From: Dmcz

Thanks. We also decided not to change.