当使用jedis的set api时,同一个key在被set两次后,通过get得到的还是第一次set的值,查看api说明,原因是参数nxxx的设置问题。set的api说明:

String redis.clients.jedis.Jedis.set(String key, String value, String nxxx, String expx, long time)

Set the string value as value of the key. The string can't be longer than 1073741824 bytes (1 GB).

Parameters:

  • key :key值
  • value :value值
  • nxxx: NX|XX,NX=Only set the key if it does not already exist;XX=Only set the key if it already exist.
  • expx: EX|PX,expire time units: EX = seconds; PX = milliseconds
  • time: expire time in the units of {@param #expx}

Returns:

Status code reply