我正在尝试使用 aiocache 库在我的端点上实施 Redis。我对 aiocache 进行的第一个测试我使用了@cache,但没有指示任何其他服务并且一切正常。但是当我尝试使用 Redis 时,我看到了这个错误(端点仍然返回请求)
ERROR: Couldn't set [<databases.backends.postgres.Record object at 0x7fb9f01d86a0>, <databases.backends.postgres.Record object at 0x7fb9f01d88b0>, <databases.backends.postgres.Record object at 0x7fb9f01d8a60>] in key app.api.authorget_authors()[], unexpected error
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/aiocache/decorators.py", line 144, in set_in_cache
await self.cache.set(key, value, ttl=self.ttl)
File "/usr/local/lib/python3.8/site-packages/aiocache/base.py", line 61, in _enabled
return await func(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/aiocache/base.py", line 45, in _timeout
return await asyncio.wait_for(func(self, *args, **kwargs), timeout)
File "/usr/local/lib/python3.8/asyncio/tasks.py", line 483, in wait_for
return fut.result()
File "/us/local/lib/python3.8/site-packages/aiocache/base.py", line 75, in _plugins
ret = await func(self, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/aiocache/base.py", line 265, in set
ns_key, dumps(value), ttl=self._get_ttl(ttl), _cas_token=_cas_token, _conn=_conn
File "/usr/local/lib/python3.8/site-packages/aiocache/serializers/serializers.py", line 140, in dumps
return json.dumps(value)
TypeError: <databases.backends.postgres.Record object at 0x7fb9f01d8a60> is not JSON serializable
整个环境基于docker,2个容器,1个FastApi,1个PostgreSQL和1个Redis。
很明显端点返回的对象有问题,所以我问你如何将这么复杂的对象传递给Redis?
按照 aiochace 文档,我尝试了所有存在的序列化程序,但没有成功。
回首忆惘然
斯蒂芬大帝
相关分类