redis / redis-py

Redis Python client
MIT License
12.58k stars 2.51k forks source link

Redis-py async, ttl not set up correctly for some keys. #2805

Open wwnbb opened 1 year ago

wwnbb commented 1 year ago

Version: 4.5.4

Platform:

client -> docker image python-3.11.4

redisserver ->

redis_version:6.2.12
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:9de3c1627dd233d
redis_mode:standalone
os:Linux x86_64
arch_bits:64
monotonic_clock:POSIX clock_gettime
multiplexing_api:epoll
atomicvar_api:c11-builtin
gcc_version:0.0.0
process_id:494397
process_supervised:systemd
run_id:f3cca0ae0ef13b44d8f960bc748d849e84854673
tcp_port:6379
server_time_usec:1686933765834796
uptime_in_seconds:4489650
uptime_in_days:51
hz:10
configured_hz:10
lru_clock:9212165
executable:/usr/bin/redis-server
config_file:/etc/redis/redis.conf
io_threads_active:0

Description: I'm using redis to store the number of hits to my api, I expect the ex parameter is always guaranteed to set ttl, but in practice a small number of keys are set without .

https://github.com/wwnbb/fastapi-throttling/blob/master/src/fastapi_throttling/throttle.py#L81

await self.redis.set(
    identifier, 1, ex=self.window
)  # Start a new window
Screenshot 2023-06-16 at 8 41 11 PM

Any ideas why this can happen? Should I check that the tll was set after the set command?

github-actions[bot] commented 3 months ago

This issue is marked stale. It will be closed in 30 days if it is not updated.