Redis EXISTS
Redis EXISTS Command
The Redis EXISTS command is used to check whether key exists in redis or not.
Since Redis 3.0.3 it is possible to specify multiple keys instead of a single one. In such a case, it returns the total number of keys existing. Note that returning 1 or 0 for a single key is just a special case of the variadic usage, so the command is completely backward compatible.
If the same existing key is mentioned in the arguments multiple times, it will be counted multiple times.
Here are some common uses and scenarios for the "EXISTS" command:
- Presence Check: Verify the existence of a key before performing operations.
- Conditional Logic: Implement logic based on whether certain keys exist.
- Data Validation: Ensure required data is present in the database.
- Key Management: Manage and monitor the existence of keys in the database.
Syntax:
EXISTS KEY_NAME
Available since
1.0.0.
Return Value
-
Integer value . Specifically
- 1, if the key exists.
- 0, if the key does not exist.
Return Value Type
Integer
Example: Redis EXISTS
First, create a key in redis and set some value in it and check for the existence of it.
127.0.0.1:6379> SET key "Good" OK 127.0.0.1:6379> EXISTS key (integer) 1 127.0.0.1:6379> EXISTS KEY (integer) 0
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/redis/redis-exists-key.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics