시작하기무료로 시작하기

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(____.____("____"))
코드 편집 및 실행