0
0
Redisquery~15 mins

TYPE command for key type check in Redis - Mini Project: Build & Apply

Choose your learning style9 modes available
Using the TYPE Command to Check Key Types in Redis
📖 Scenario: You are managing a Redis database that stores different types of data such as strings, lists, and hashes. To work efficiently, you need to know the type of data stored at each key.
🎯 Goal: Build a small Redis script that sets keys with different data types and uses the TYPE command to check and confirm the type of each key.
📋 What You'll Learn
Create three keys with exact names: user:name, user:emails, and user:profile.
Set user:name as a string with the value "Alice".
Set user:emails as a list with the values "alice@example.com" and "alice.work@example.com".
Set user:profile as a hash with fields age set to 30 and city set to "New York".
Use the TYPE command to check the type of each key exactly as named.
💡 Why This Matters
🌍 Real World
In real applications, Redis stores many types of data. Knowing the type of each key helps avoid errors and manage data correctly.
💼 Career
Database administrators and backend developers often need to check key types in Redis to maintain data integrity and optimize queries.
Progress0 / 4 steps
1
Create keys with different data types
Create three keys in Redis with these exact commands: set user:name to "Alice", create a list user:emails with "alice@example.com" and "alice.work@example.com", and create a hash user:profile with fields age set to 30 and city set to "New York".
Redis
Need a hint?

Use SET for strings, LPUSH for lists, and HSET for hashes.

2
Prepare to check key types
Prepare to check the type of each key by writing the TYPE command for the key user:name.
Redis
Need a hint?

Use TYPE user:name to check the type of the key user:name.

3
Check types of all keys
Add TYPE commands to check the types of the keys user:emails and user:profile exactly as named.
Redis
Need a hint?

Use TYPE user:emails and TYPE user:profile to check their types.

4
Complete the Redis script
Ensure the Redis script includes all commands to set the keys and check their types in this exact order: SET user:name, LPUSH user:emails, HSET user:profile, then TYPE user:name, TYPE user:emails, and TYPE user:profile.
Redis
Need a hint?

Make sure all commands are included and in the correct order.