python-3.x - FakeRedis 异常 - FakeSocket 没有 fileno() 方法

标签 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 的实例,然后在调用“get”时,代码最终调用“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() 方法,所以不清楚它应该如何工作。

感谢您的帮助。

最佳答案

自然而然地,在调查了两天之后,我提出了这个问题,然后立即找到了答案。 fakeredis 与 redis 版本 3.2 不兼容,降级到 3.0.1 解决了这个问题。

关于python-3.x - FakeRedis 异常 - FakeSocket 没有 fileno() 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55139276/

相关文章:

python - Geektool 不适用于 python3

django - 无法访问位于 http ://127. 0.0.1:8000/的 Django 服务器

python-3.x - 使用 python 读取和打开 dicom 图像

c++ - C++文件加载期间的UTF8加扰

multithreading - 多线程Redis Cluster

python - skimage 在 LAB 色彩空间中为每个 channel 使用什么范围?

windows - 在后台运行批处理文件

c++ - 是否可以从 C++ Windows 服务发送 Windows Toast 通知?

Heroku Spring Redis - SessionDestroyedEvent

transactions - 如果 Redis 在事务中间触发快照怎么办?