Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redis Connection Pooling Across Decorators #552

Closed
cancan101 opened this issue Nov 23, 2021 · 2 comments
Closed

Redis Connection Pooling Across Decorators #552

cancan101 opened this issue Nov 23, 2021 · 2 comments

Comments

@cancan101
Copy link

I think the answer to this is no, but if I have multiple functions that are decoratored with cached and using the redis backend, will they share the same connection pool? ie if I have pool_max_size=N on each of the M decorators will there be up to M*N connections to my redis server? This is important as various PaaS providers (e.g. Heroku) limit the number of connections to the redis service.

@Krukov
Copy link

Krukov commented Dec 12, 2021

Hello, I could be wrong but as I understand - it's depends
If you using aliases with decorators - it should be one pool per alias. But if you pass redis connections parameters for each decorator you will have connection pool for each decorator
So I suggest you should use aliases

from aiocache import caches, cached

caches.set_config({
    'redis_alt': {
        'cache': "aiocache.RedisCache",
        'endpoint': "127.0.0.1",
        'port': 6379,
        'timeout': 1,
        'serializer': {
            'class': "aiocache.serializers.PickleSerializer"
        },
        'plugins': [
        ]
    }
})

@cached(ttl=10, key="key", alias="redis_alt")
async def cached_call():
    print("Sleeping for three seconds zzzz.....")
    await asyncio.sleep(3)
    return Result("content", 200)

Another suggestion with ads - use my library https://github.com/Krukov/cashews - like aiocache, but with batteries

@Dreamsorcerer
Copy link
Member

This should become irrelevant once #609 is solved. You'll likely need to pass a cache instance to the decorator explicitly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants