我已经安装了最新的 docker 容器:
redis latest 31f08b90668e 117MB
docker run --name redis -d -p 6379:6379 redis
$ redis-cli
127.0.0.1:6379> set "test" "testing"
OK
127.0.0.1:6379> get "test"
"testing"
127.0.0.1:6379>
我安装redis:
$ pip list | grep redis
redis 4.5.4
我在我的 FastAPI 项目中创建了一个 redis 实例:
from redis.asyncio import Redis
redis: Redis = Redis()
rsp: bool = await redis.ping()
if not rsp:
raise Exception('redis startup failed')
ping 有效。我应该可以走了,对吧?!
我什至可以在这一点上设置/获取密钥。
但是,后来我尝试设置一个键,但它爆炸了。
File "/myproject/backend/service/sesson_service_impl.py", line 51, in create_from_id_token
rsp: str = await self._redis.set(f'session/{session.id}', session, ex=self._session_idle_sec)
File "/myproject/venv/lib/python3.10/site-packages/redis/commands/core.py", line 2302, in set
return self.execute_command("SET", *pieces, **options)
File "/myproject/venv/lib/python3.10/site-packages/redis/client.py", line 1255, in execute_command
conn = self.connection or pool.get_connection(command_name, **options)
File "/myproject/venv/lib/python3.10/site-packages/redis/connection.py", line 1442, in get_connection
connection.connect()
File "/myproject/venv/lib/python3.10/site-packages/redis/connection.py", line 710, in connect
self.on_connect()
File "/myproject/venv/lib/python3.10/site-packages/redis/connection.py", line 748, in on_connect
auth_args = cred_provider.get_credentials()
File "/myproject/venv/lib/python3.10/site-packages/redis/credentials.py", line 10, in get_credentials
raise NotImplementedError("get_credentials must be implemented")
NotImplementedError: get_credentials must be implemented
我注意到的一件事是不再使用异步连接。我试过设置自己的异步连接池,但它似乎被同步连接池取代了。