蟒蛇Redis的客户端无法获得使用.hgetall(键)
问题描述:
我遇到了在那里我们的Redis缓存DB2中的demonstrably称为哈希被要求与.hgetall(键)时,冲模,情况已有哈希值。我希望得到一些见解!谢谢。蟒蛇Redis的客户端无法获得使用.hgetall(键)
对,所以......第一,代码条子:导致
def from_cache(self, cachekey):
""" pull oft needed material from our persistent redis memory cache, ensuring of course that we have a connection """
try:
log.debug('trying to get \'%s\' from cache' % cachekey)
return self.redis.hgetall(cachekey)
except Exception, e:
self.connect_to_cache()
return self.redis.get(cachekey)
:
2013-05-21 14:45:26,035 23202 DEBUG trying to get 'fax:1112223333' from cache
2013-05-21 14:45:26,036 23202 DEBUG initializing connection to redis/cache memory localhost, port 6379, db 2...
2013-05-21 14:45:26,039 23202 ERROR stopping with an exception
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/simpledaemon/base.py", line 165, in start
self.run()
File "newgov.py", line 51, in run
if self.ready_for_queue(fax):
File "newgov.py", line 61, in ready_for_queue
if self.too_many_already_queued(fax):
File "newgov.py", line 116, in too_many_already_queued
rules = self.from_cache(key)
File "newgov.py", line 142, in from_cache
return self.redis.get(cachekey)
File "/usr/lib/python2.6/site-packages/redis/client.py", line 588, in get
return self.execute_command('GET', name)
File "/usr/lib/python2.6/site-packages/redis/client.py", line 378, in execute_command
return self.parse_response(connection, command_name, **options)
File "/usr/lib/python2.6/site-packages/redis/client.py", line 388, in parse_response
response = connection.read_response()
File "/usr/lib/python2.6/site-packages/redis/connection.py", line 309, in read_response
raise response
ResponseError: Operation against a key holding the wrong kind of value
这里是什么在Redis的:
$ redis-cli
redis 127.0.0.1:6379> SELECT 2
OK
redis 127.0.0.1:6379[2]> type fax:1112223333
hash
redis 127.0.0.1:6379[2]> hgetall fax:1112223333
1) "delay"
2) "0"
3) "concurrent"
4) "20"
5) "queued"
6) "20"
7) "exclude"
8) ""
答
看在你的Python堆栈跟踪:失败的“回报self.execute_command(‘GET’,名字)”。这意味着:
- 的hgetall命令失败(可能是因为连接未建立之前)
- 异常升高,并夹在你的方法
- Redis的连接建立(我想通过调用connect_to_cache ())
- 那么你尝试,因为cachekey的内容是哈希键(不是字符串运行“self.redis.get(cachekey)”
- 失败当然) (在这里我想你应该使用hgetall代替)
- 的其他引发异常 - Redis的错误(操作针对关键抱着一种错误的值)
随着Redis的CLI,尝试运行“GET传真:1112223333”一类的错误,你会有同样的错误。
+0
确实的确如此;我在发布这个消息后大约10秒钟就看到了第二次尝试的.get();它是重构前的旧“好”的代码,所以我的眼睛不停玻璃了它。 –
答
当您设置和置角有不同类型的数据。在hset中,你的值是哈希映射。而当你尝试获得哈希映射时,你有相同的错误。刚刚尝试hgetall
和Redis的将返回的HashMap,或尝试用hget和cachekey HashMap中设置好的任何键,欣赏
你怎么Redis的实例?你确定要连接到的Redis的同一实例(本地主机,端口6379)和相同的DB(2)在这两种情况下? – Eli