Home > Back-end >  StringRedisTemplate opsForValue (.) setIfAbsent () method if there is a bug? The return value is nul
StringRedisTemplate opsForValue (.) setIfAbsent () method if there is a bug? The return value is nul

Time:11-29

When I tried to use redis. Learning to write distributed lock found stringRedisTemplate opsForValue () setIfAbsent (lockKey, clientId, 30, TimeUnit. SECONDS); The return value is null
API shows the return value to a Boolean result in I can't for the following logic
Is this the official bug? The eldest brother have to know is how to return a responsibility?
Attach the test code
 
The @autowired
Private StringRedisTemplate StringRedisTemplate;
@ Test
Void contextLoads () {
//here should return true or false but returned to the null effect and set the
Boolean aBoolean=stringRedisTemplate
OpsForValue ()
SetIfAbsent (" key ", "value", 100, TimeUnit. SECONDS);
System. The out. Println (aBoolean);

//a Boolean key=stringRedisTemplate. Expire (" key ", 10, TimeUnit. SECONDS);
//System. Out. Println (key);
}

CodePudding user response:


I tried once, no problem, the same code, I insert returns true on success

CodePudding user response:

reference 1st floor life god reply:

I tried once, no problem, the same code, I insert return true success

Because the import different jars?

CodePudding user response:

Well know why

Introduces redisson rely on return null to remove this good don't know why

CodePudding user response:

If the two are used to, can't get rid of
  • Related