EXISTS command in redis

EXISTS key

This command tests if the specified key exists. The command returns "1" if the key exists, otherwise "0" is returned. Note that even keys set with an empty string as the value will return "1".

TIME COMPLEXITY: O(1)

RETURN VALUE:

1 if the key exists.

0 if the key does not exist.

Syntax:

EXISTS KEY_NAME

Example 1: When the key is present

redis:6379> EXISTS  redisKey
(integer) 1

Output

1


Example 2: When the key is not present

redis:6379> EXISTs rediKey
(integer) 0

Output

0

No comments:

Post a Comment