下午好,
我正在使用 pythomnic3k python 框架和分片 solr、redis 数据库服务器。
以下是我的 api 请求:
http://1.2.3.4:8090/api20/account2/addnewemail?Email=foo@yahoo.com&Token=[redacted]&AccountID=[redacted]
错误:
AttributeError: 'function' object has no attribute 'get'
出现此错误的函数:
def count_maps(r): dt = r.get(Namespace.MAPPINGS + ':count')
r 是 redis 实例和
Namespance.Mappings + ':count' = ytk:map:count
solr schema xml 文件有这些分片实例:
<?xml version="1.0" encoding="UTF-8"?> <mapping> <meta> <date>201-12-13 00:00:00</date> <active>true</active> <static url="0.0.0.0:8983/solr" /> </meta> <map> <shard url="0.0.0.0:8983/solr" start="00000000" end="00009999" readonly="false"> <slave url="0.0.0.0:8983/solr" /> </shard> </map> </mapping>
Redis 实例 r 在 redis_utils.py
def test_redis_obj(r): try: r.ping() return True except ConnectionError: return False def redis_obj(redis_def, timeout = None): if not redis_def: return None return redis.StrictRedis( host = redis_def["ip"], port = redis_def["port"], db = redis_def["db"], socket_timeout = timeout ) def random_redis_obj(timeout = None): return redis_obj(random_redis_def(), timeout) def random_tested_redis_obj(attempts = 3, timeout = 1): for _ in range(attempts): r = random_redis_obj(timeout) if r and test_redis_obj(r): return r raise YtkRedisError("active redis server not found (%d attempts done)" % attempts)
这是
count_maps(r)
在 solr_manager.py 中调用的函数:def get_unique_shards(r, the_map: int = -1): ''' Returns array: [map][shard](0: url; 1: [slaves urls]) with unique shards with their slaves in mappings ''' num = count_maps(r) if the_map >= num: raise IndexError("There aren't map at index " + str(the_map)) if the_map < 0: return _get_all_unique_shards(r, num) else: return _get_unique_shards(r, the_map) def count_maps(r): dt = r.get(Namespace.MAPPING + ':count') if dt is not None: return int(dt) return None
我了解这个 redis 对象尝试计算 solr 实例,对吗?
请帮助我解决我的 redis 对象为 None 的可能原因?我检查了我的日志相同的“获取属性..”错误并且无法调试它。