miniredis icon indicating copy to clipboard operation
miniredis copied to clipboard

not support setnx with ttl?

Open g10guang opened this issue 2 years ago • 7 comments

g10guang avatar Mar 13 '22 08:03 g10guang

not support setnx with ttl? (Issue #259)

Hi,

thank you for opening an issue.

I don't understand what you're asking. Can you point to the documentation on the redis.io site? Maybe somewhere here: https://redis.io/commands/setnx

Thanks!

alicebob avatar Mar 13 '22 19:03 alicebob

I might understand what @g10guang means. Checking FastForward should be helpful

ChaosNyaruko avatar Jul 07 '22 12:07 ChaosNyaruko

use "github.com/gomodule/redigo/redis exec redis command Do("SET", "key", "value", "PX", int64(expire), "nx")

expire not work. but using a physical Redis server is ok

Playground: https://go.dev/play/p/2VEvoPXkQLc

rentiansheng avatar Sep 06 '22 10:09 rentiansheng

Thanks for the clarification. That's what @ChaosNyaruko was going for, please check https://github.com/alicebob/miniredis#ttls-key-expiration-and-time

alicebob avatar Sep 06 '22 11:09 alicebob

Thanks for the clarification. That's what @ChaosNyaruko was going for, please check https://github.com/alicebob/miniredis#ttls-key-expiration-and-time

go playground code example address: https://go.dev/play/p/gUMLoDvHRU7

I called the function FastForward. TTL is decrease when TTL is equal 0, exec command "Do("SET", "key", "value", "PX", int64(expire), "nx")" miniredis reply is not ok

image

rentiansheng avatar Sep 07 '22 02:09 rentiansheng

Hi,

thanks for your clarification.

You use: redis.FastForward(1), which is 1 nanosecond. It works if you use this:

    // time.Sleep(time.Second * 1)
    mockRedis.FastForward(1 * time.Second)

That gives me:

start
ttl1 1 ttl2 -2

(note that you don't need to call time.Sleep())

alicebob avatar Sep 07 '22 06:09 alicebob

☕️。 thanks

rentiansheng avatar Sep 07 '22 10:09 rentiansheng