Closed Tomerva closed 6 months ago
looks like you are using redis in cluster mode.
maybe you can try resolve the problem following this tutorial here?
https://hackernoon.com/resolving-the-crossslot-keys-error-with-redis-cluster-mode-enabled
still cant get it to work
redis_db = Redis(host='MYHOST', port=6379, ssl=True, ssl_cert_reqs="none")
bucket = RedisBucket.init([Rate(1, Duration.SECOND.value)], redis_db, '{ratelimit}:abc')
limiter = Limiter(bucket, max_delay=Duration.HOUR)
deco = limiter.as_decorator()
@deco(lambda _: ('{ratelimit}:abc',1))
def sync_func(i):
print(i)
@vutran1710 i created new redis with cluster mode disabled but having an issue with rate limiting async requests when using "regular" redis it just sends all the request at once when using async redis it fails due to bucket full even though i set long max_delay
from redis.asyncio import Redis as AsyncRedis
async def create_limiter(*rates: Rate, identity):
redis_db = AsyncRedis(host=endpoint, port=6379, ssl=True, ssl_cert_reqs="none")
bucket_init_method = lambda: RedisBucket.init(rates, redis_db, identity)
bucket = await RedisBucket.init(rates, redis_db, identity)
limiter = Limiter(bucket, max_delay=Duration.HOUR)
deco = limiter.as_decorator()
return deco(lambda _: (identity,1))
async def main():
mylimiter = await create_limiter(Rate(1, 1), identity='myident', bucket_class=BucketClass.ASYNC_REDIS)
@mylimiter
async def async_func(i):
print(i)
tasks = [asyncio.create_task(async_func(i)) for i in range(5)]
await asyncio.gather(*tasks)
asyncio.run(main())
getting this:
pyrate_limiter.exceptions.BucketFullException: Bucket for item=myident with Rate limit=1/1.0s is already full
interesting. ill take a look at this soon
@vutran1710 any news on this issue?
I opened a PR that fixed the issue for me: https://github.com/vutran1710/PyrateLimiter/pull/151
I have a fairly simple code that keeps getting this exception
the exception: