最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Redis data fetching error, redis.exceptions.ResponseError: WRONGTYPE Operation against a key holding the wrong kind of

programmeradmin0浏览0评论

I am trying to fetch the redis data, then

at first try this script

pool = redis.ConnectionPool(host='localhost', port=6379, db=0)
self.redis = redis.Redis(connection_pool=pool)
for key in self.redis.keys():
    print ("key:",key)

It shows like this,

key: b'asgi:group:347'
key: b'asgi:group:62'
key: b'asgi:group:344'
key: b'asgi:group:305'
key: b'asgi:group:348'

then I try to check ,

print(self.redis.get("asgi:group:348"))

However it shows the error like this, redis.exceptions.ResponseError: WRONGTYPE Operation against a key holding the wrong kind of value

How can I get the value of table?

I am trying to fetch the redis data, then

at first try this script

pool = redis.ConnectionPool(host='localhost', port=6379, db=0)
self.redis = redis.Redis(connection_pool=pool)
for key in self.redis.keys():
    print ("key:",key)

It shows like this,

key: b'asgi:group:347'
key: b'asgi:group:62'
key: b'asgi:group:344'
key: b'asgi:group:305'
key: b'asgi:group:348'

then I try to check ,

print(self.redis.get("asgi:group:348"))

However it shows the error like this, redis.exceptions.ResponseError: WRONGTYPE Operation against a key holding the wrong kind of value

How can I get the value of table?

Share asked Mar 4 at 5:29 whitebearwhitebear 12.5k29 gold badges149 silver badges299 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Redis supports multiple types of values, and you need to know the type of the value in order to fetch it. get() only works if the value is a string.

For a key you know nothing about try calling self.redis.type(key) to find out the type of value stored with the key. You will then need to use the appropriate getter for that type.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论