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

I am trying to fetch the redis data, thenat first try this scriptpool = redis.ConnectionPool(host=�

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745060366a4608929.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信