開始使用免費開始

使用 Redis 儲存鍵值資料

Redis 是一款強大的工具,用來儲存鍵值對,在網頁應用中特別常見。這個範例中,你是開發者,要建立一個小工具,為應用的使用者顯示即時天氣,並利用 Redis 來快取這些資訊。

為了幫你快速開始,我們已建立連線到 Redis 叢集,並放在變數 redis_conn 中。加油!

本練習屬於課程

NoSQL 入門

檢視課程

練習說明

  • 將值 "London" 儲存在鍵 "city"
  • 使用鍵 "sunshine",儲存值 7
  • 取回儲存在 "city""sunshine" 這兩個鍵的值,並查看 print 出來的結果。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Store the city key-value pair
redis_conn.____("____", "London")

# Store the sunshine key-value pair
____.____("____", "____")

# Retrieve values stored at the city and sunshine keys
city = redis_conn.____("____")
sunshine = ____.____("____")

print(city)
print(sunshine)
編輯並執行程式碼