Redis で Python の辞書を保存する
単純なキーと値のペアだけでなく、dict(辞書)のような、より複雑な Python データ型も保存できます。Redis を使う最後の演習では、Python の redis モジュールを使って、Python の辞書を保存・取得する練習をします。
これまでと同様に、接続オブジェクトは作成済みで、変数 redis_conn に保存されています。がんばってください!
この演習はコースの一部です
NoSQL入門
演習の手順
redis_conn変数を使って、辞書london_weather_mappingをキー"london_weather"に保存してください。redis_conn変数と適切なメソッドを使って、キー"london_weather"のキーと値のペアを取得し、出力してください。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# 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(____.____("____"))