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?
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.
If key does not exist, a new key holding a hash is created. If field already exists in the hash, it is overwritten.
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.
Yes, you can use public Boolean hasKey(K key).
You can just search exists in redisTemplate javadoc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With