Handling Encoding Issues Using Redis with Python

Pythond์—์„œ Redis ์‚ฌ์šฉ์‹œ encoding issue ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

Problem

:Python ์—์„œ Redis์— ๋ฌธ์ž์—ด์„ publish ํ•˜๋ฉด binary๋ฅผ return ํ•˜๋Š” ๋ฌธ์ œ ๋ฐœ์ƒ

Solution

: Redis Python interface ๊ฐ€ Redis connection class์— ๋Œ€ํ•ด ์ œ๊ณตํ•˜๋Š” decode_responses option์„ ํ™œ์šฉํ•˜์—ฌ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค

ex)

  • ์œ„์˜ ์˜ˆ์‹œ์™€ ๊ฐ™์ด decode_responses option์„ True๋กœ ์„ค์ •ํ•˜๋ฉด, client๋Š” ์„ค์ •ํ•œ encoding option์„ ์ด์šฉํ•˜์—ฌ decodeํ•œ ๊ฒฐ๊ณผ๊ฐ’์„ return ํ•ด์ค€๋‹ค

  • ์˜ˆ์‹œ์—์„œ๋Š” ๋ช…์‹œ์ ์œผ๋กœ **charset="utf-8"**๋กœ ํ‘œํ˜„ํ–ˆ์œผ๋‚˜ encoding default ๊ฐ’์ด utf-8์ด๋ฏ€๋กœ ์ƒ๋žตํ•ด๋„ ๋œ๋‹ค

References

Last updated

Was this helpful?