EXISTS
The Redis EXISTS command is used to check if given keys exist.
Redis Native Command Syntax
Section titled “Redis Native Command Syntax”EXISTS key [key ...]Parameter Description
- key: The key(s) to check for existence, multiple keys can be specified
Detailed Explanation
Section titled “Detailed Explanation”The EXISTS command checks if one or more keys exist. Starting from Redis 3.0.3, multiple keys can be specified.
If a single key is specified, the command returns 1 if the key exists, 0 if the key does not exist. If multiple keys are specified, the command returns the number of keys that exist.
Redisun Usage
Section titled “Redisun Usage”In redisun, the EXISTS command is implemented through the ExistsCommand class and the exists method in the Redisun class.
Synchronous Mode
Section titled “Synchronous Mode”// Check if a single key existsint exists = redisun.exists("mykey");
// Check if multiple keys existint exists = redisun.exists("mykey1", "mykey2", "mykey3");Asynchronous Mode
Section titled “Asynchronous Mode”// Check if a single key existsCompletableFuture<Integer> future = redisun.asyncExists("mykey");
// Check if multiple keys existCompletableFuture<Integer> future = redisun.asyncExists("mykey1", "mykey2", "mykey3");- The time complexity of the
EXISTScommand is O(1). - This command is applicable to all types of keys, including strings, hashes, lists, sets, and sorted sets.
- If a key has expired and been deleted, the
EXISTScommand will return 0. - Starting from Redis 3.0.3, multiple keys can be checked at once, returning the number of keys that exist.