FakeRedis异常-FakeSocket没有fileno()方法

时间:2019-03-13 10:11:55

标签: python-3.x windows redis

我正在将Python项目从2.7.x切换到3.7.x,并且在Windows 10上运行,并且遇到了FakeRedis的问题。我有一个RedisCache类,看起来像这样:

class RedisCache(object):
    def __init__(self, connection_info, is_testing):
        if is_testing:
            import fakeredis
            self.conn = fakeredis.FakeStrictRedis()
        else:
            self.conn = redis.StrictRedis(host=connection_info['host'], port=connection_info['port'], db=0)

def get(self, key_name, default=None):
    return self.conn.get(key_name)

在运行测试时,将连接创建为FakeStrictRedis的实例,然后在调用“获取”时,代码最终调用“ redis.SelectSelector.check_is_ready_for_command”,然后调用“ select.select”,并传入一个实例。 'fakeredis._server.FakeSocket'。

def check_is_ready_for_command(self, timeout):
    """
    Return True if the socket is ready to send a command,
    otherwise False.
    """
    r, w, e = select.select([self.sock], [self.sock], [self.sock],
                            timeout)
    return bool(w and not r and not e)

然后在对“ select.select”的调用中得到以下调用堆栈:

\core\rediscache.py                         line 41, in get                           s = self.conn.get(key_name)
\env\lib\site-packages\redis\client.py      line 1264, in get                         return self.execute_command(\'GET\', name)
\env\lib\site-packages\redis\client.py      line 772, in execute_command              connection = pool.get_connection(command_name, **options)
\env\lib\site-packages\redis\connection.py  line 999, in get_connection               if not connection.is_ready_for_command():  
\env\lib\site-packages\redis\connection.py  line 632, in is_ready_for_command         return self._selector.is_ready_for_command() 
\env\lib\site-packages\redis\selector.py    line 43, in is_ready_for_command          return self.check_is_ready_for_command(timeout)
\env\lib\site-packages\redis\selector.py    line 104, in check_is_ready_for_command   timeout) 
TypeError: argument must be an int, or have a fileno() method.

问题在于FakeSocket没有fileno()方法,因此尚不清楚它应该如何工作。

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

经过两天的自然调查,我提出了问题,然后立即找到答案。 fakeredis与redis版本3.2不兼容,降级为3.0.1可以解决此问题。