Concept Flow - TYPE command for key type check
Start
Input key name
Check if key exists
Get key type
Return type string
End
The TYPE command checks if a key exists and returns its data type or 'none' if it does not exist.
TYPE mykey TYPE unknownkey
| Step | Command | Key | Key Exists? | Returned Type |
|---|---|---|---|---|
| 1 | TYPE mykey | mykey | Yes | string |
| 2 | TYPE unknownkey | unknownkey | No | none |
| Variable | Start | After Step 1 | After Step 2 |
|---|---|---|---|
| key | undefined | mykey | unknownkey |
| key_exists | undefined | true | false |
| type_result | undefined | string | none |
TYPE key Returns the data type of the key. If key exists, returns type like string, list, set, hash, zset. If key does not exist, returns 'none'. Useful to check key type before operations.
TYPE command do?user:1 in Redis?TYPE keyname, so for key user:1, it is TYPE user:1.SET name "Alice" LPUSH colors "red" SADD tags "new" TYPE name TYPE colors TYPE tags TYPE ageWhat will be the output of the last four TYPE commands respectively?
SET name "Alice" creates a string key.LPUSH colors "red" creates a list.SADD tags "new" creates a set.age key is not set, so it does not exist.TYPE mykey but get an unexpected output. Which of these is a likely cause?TYPE keyname without parentheses. Using TYPE(mykey) causes syntax error or unexpected output.Pass the test and this pattern moves unknown