Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the nxxx parameter of set() in Jedis exclusive?

Tags:

redis

jedis

In Jedis, I want to set some key and value with expiring time by a single invocation.

I can do this by combination of set() and expire() but it needs two invocations.

I found the following method:

set(final String key, final String value, final String nxxx, final String expx, final long time)

But I have to choose nx (Only set the key if it does not already exist.) or xx (Only set the key if it already exist.).

I want to cover both cases.

Any suggestion? Or any reason to be written like this?

like image 205
Johnny Lim Avatar asked Oct 13 '14 11:10

Johnny Lim


1 Answers

Redis has a SETEX command, which sets the key with an expiry.

jedis.setex(key, expireAfter, value);
like image 169
c.P.u1 Avatar answered Oct 18 '22 05:10

c.P.u1