django-cacheops icon indicating copy to clipboard operation
django-cacheops copied to clipboard

AWS Elasticache Redis Serverless Implementation is raising AttributeError

Open saanpritom opened this issue 2 years ago • 2 comments

Hi, Recently I was trying to implement this library with one of my current Django project. For caching I have used Redis. This project was running before with this library enabled and it was showing no errors and working fine. Because the project was deployed in Kubernetes and the Redis instance was also deployed inside Kubernetes as a pod. The connection protocol was HTTP and it was working fine.

But for some reason I had to move from Kubernetes to a different system. Now for caching I am using AWS Elasticache Redis Serverless. The connection protocol is now HTTPs. This is not an issue and can be implemented though there is no particular documentation about it. However, when the library is trying to check the version of the Redis an AttributeError has thrown. You will get the details of the error in the below attached screenshot.

After digging down I found that the script is trying to split the version numbers. This works because the return value was in String format but for some reason it seems like the AWS Elasticache Redis Serverless is returning the value in Float format thus causing the script to fail.

cacheops_bug

saanpritom avatar Jan 30 '24 05:01 saanpritom

That's weird how one returns "7.2.4" as float?

As a temporary solution you can either:

  • downgrade to cacheops 7.0, which does not have this version check. Downgrade further if cacheops tries something that their redis doesn't support.
  • monkey patch this check:
from funcy import memoize
import cacheops.redis


@memoize
def is_redis_7():
    redis_version = redis_client.info('server')['redis_version']
    if isinstance(redis_version, float):
        return redis_version >= 7
    return int(redis_version.split('.')[0]) >= 7


cacheops.redis.is_redis_7 = is_redis_7

Suor avatar Jan 30 '24 09:01 Suor

May also check the version of redis-py you are using, converting response types is a part of its job. Maybe it's a bug in there and should be filed and fixed there too.

Suor avatar Jan 30 '24 09:01 Suor

Hi @Suor sorry for my late reply. Yeah your monkey patch worked. But this is a problem with the new AWS Elasticache Serverless edition. The normal Elasticsche is fine and works seamlessly with both Single Instance mode and Cluster Mode. I am using this library in a Django application where django-redis is also installed and configured. I am not sure if that is causing an issue or not.

saanpritom avatar Feb 16 '24 03:02 saanpritom

Hi @Suor sorry for my late reply. Yeah your monkey patch worked. But this is a problem with the new AWS Elasticache Serverless edition. The normal Elasticsche is fine and works seamlessly with both Single Instance mode and Cluster Mode. I am using this library in a Django application where django-redis is also installed and configured. I am not sure if that is causing an issue or not.

Hi @saanpritom - did you get CacheOps working with Elasticache serverless? I'm trying to do the same and although i've overcome the is_redis_7 issue by monkeypatching it, i now receive "ResponseError: CROSSSLOT Keys in request don't hash to the same slot" style errors, which i suspect refer to the fact that out of the box cacheops doesnt know how to deal with clusters.

Did you solve this with by creating a custom redis client? If you're able to share any tips or code i'd be hugely grateful.

benjamindell avatar Apr 04 '24 17:04 benjamindell

Hi @benjamindell later I moved on to standard Elasticache. I was also facing the CROSSLOT problem on Serverless but didn't dive deeply there. On a Standard Elasticache it works fine.

saanpritom avatar Apr 05 '24 06:04 saanpritom

Thanks @saanpritom - I would love to find a way to get it to work with serverless / cluster setups. So far not having much luck (:

benjamindell avatar Apr 05 '24 11:04 benjamindell