Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any ways to check whether a key exists with RedisTemplate?

Are there any ways to check whether a key exists with RedisTemplate? or in other words, are there any equivalent of Redis exists command in RedisTemplate API?

like image 669
Lily Avatar asked Aug 23 '17 03:08

Lily


People also ask

How check value exist in Redis list?

To check for a key existence, use HEXISTS for a specific field which returns 0 if the specified member does not exist. You could also use the HGET command. It returns a nil answer if the specified member does not exist.

What if key is not present in Redis?

If key does not exist, a new key holding a hash is created. If field already exists in the hash, it is overwritten.

Is exist in Redis?

The EXISTS command in Redis allows us to determine if a specified key exists in the database. The command will take the provided keys and check how many exist within the selected database. For example, the previous command returns (integer) 1 since only one key exists in the database.


1 Answers

Yes, you can use public Boolean hasKey(K key).

You can just search exists in redisTemplate javadoc

like image 181
Mobility Avatar answered Oct 13 '22 13:10

Mobility