Storing Python dictionaries with Redis
In addition to storing simple key-value pairs, you can store more complex Python data types, such as dict
ionaries. In this final exercise with Redis, you'll practice storing and retrieving Python dictionaries with the help of the redis
module in Python.
Similar to before, a connection object has been created and stored in the variable redis_conn
. Good luck!
This is a part of the course
“Introduction to NoSQL”
Exercise instructions
- Using the
redis_conn
variable, store the dictionarylondon_weather_mapping
to the"london_weather"
key. - Retrieve and print the
"london_weather"
key-value pair using theredis_conn
variable and the appropriate method.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create a dictionary containing weather data
london_weather_mapping = {
"temperature": 42,
"humidity": 88,
"visibility": "low"
}
# Store the london_weather key-value pair
____.____(
"____",
mapping=____
)
# Retrieve and print the london_weather key-value pair
print(____.____("____"))
This exercise is part of the course
Introduction to NoSQL
Conquer NoSQL and supercharge data workflows. Learn Snowflake to work with big data, Postgres JSON for handling document data, and Redis for key-value data.
Take your NoSQL skills to the next level by mastering the fundamentals of key-value databases. Explore common use-cases for key-value data, and learn how to use Redis and Python to read and write data. Wrap up with a basic overview of graph databases, and their place in the modern data stack.
Exercise 1: Introduction to key-value databasesExercise 2: Key-value databasesExercise 3: Key-value vs. document databasesExercise 4: Connecting to a Redis clusterExercise 5: Storing and retrieving key-value dataExercise 6: Storing key-value data with RedisExercise 7: Retrieving key-value data with RedisExercise 8: Storing Python dictionaries with RedisExercise 9: Graph databasesExercise 10: Understanding graph databasesExercise 11: Graph database providersExercise 12: Using graph databasesExercise 13: Wrapping up!What is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.