Suor / django-cacheops

A slick ORM cache with automatic granular event-driven invalidation.
BSD 3-Clause "New" or "Revised" License
2.12k stars 227 forks source link

INSIDEOUT doesn't work with Elasticache #459

Closed rotten closed 1 year ago

rotten commented 1 year ago

INSIDEOUT doesn't with with Elasticache (AWS managed redis). At least it doesn't work with the versions I've tried.

Using:

It works fine with the redis 7.0.5-bullseye container. But when I deploy to AWS (engine 5.0.6) it fails. Here is a stack trace from when I try to run a migration:

Traceback (most recent call last):
  File "/usr/src/app/manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.10/site-packages/django/core/management/base.py", line 448, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.10/site-packages/django/core/management/base.py", line 96, in wrapped
    res = handle_func(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/django/core/management/commands/migrate.py", line 376, in handle
    emit_post_migrate_signal(
  File "/usr/local/lib/python3.10/site-packages/django/core/management/sql.py", line 52, in emit_post_migrate_signal
    models.signals.post_migrate.send(
  File "/usr/local/lib/python3.10/site-packages/django/dispatch/dispatcher.py", line 176, in send
    return [
  File "/usr/local/lib/python3.10/site-packages/django/dispatch/dispatcher.py", line 177, in <listcomp>
    (receiver, receiver(signal=self, sender=sender, **named))
  File "/usr/src/app/permissions/management/__init__.py", line 102, in add_group_permissions
    permissions_set.validate()
  File "/usr/src/app/permissions/__init__.py", line 105, in validate
    all_perms = set(self._get_qs().values_list('qualname', flat=True))
  File "/usr/local/lib/python3.10/site-packages/django/db/models/query.py", line 394, in __iter__
    self._fetch_all()
  File "/usr/local/lib/python3.10/site-packages/cacheops/query.py", line 261, in _fetch_all
    self._cache_results(cache_key, self._result_cache)
  File "/usr/local/lib/python3.10/site-packages/cacheops/query.py", line 179, in _cache_results
    cache_thing(self._prefix, cache_key, results,
  File "/usr/local/lib/python3.10/site-packages/funcy/decorators.py", line 45, in wrapper
    return deco(call, *dargs, **dkwargs)
  File "/usr/local/lib/python3.10/site-packages/cacheops/redis.py", line 16, in handle_connection_failure
    return call()
  File "/usr/local/lib/python3.10/site-packages/funcy/decorators.py", line 66, in __call__
    return self._func(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.10/site-packages/cacheops/getset.py", line 31, in cache_thing
    return load_script('cache_thing_insideout')(
  File "/usr/local/lib/python3.10/site-packages/redis/commands/core.py", line 5827, in __call__
    return client.evalsha(self.sha, len(keys), *args)
  File "/usr/local/lib/python3.10/site-packages/redis/commands/core.py", line 5214, in evalsha
    return self._evalsha("EVALSHA", sha, numkeys, *keys_and_args)
  File "/usr/local/lib/python3.10/site-packages/redis/commands/core.py", line 5198, in _evalsha
    return self.execute_command(command, sha, numkeys, *keys_and_args)
  File "/usr/local/lib/python3.10/site-packages/elasticapm/instrumentation/packages/base.py", line 205, in call_if_sampling
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/redis/client.py", line 1269, in execute_command
    return conn.retry.call_with_retry(
  File "/usr/local/lib/python3.10/site-packages/redis/retry.py", line 46, in call_with_retry
    return do()
  File "/usr/local/lib/python3.10/site-packages/redis/client.py", line 1270, in <lambda>
    lambda: self._send_command_parse_response(
  File "/usr/local/lib/python3.10/site-packages/redis/client.py", line 1246, in _send_command_parse_response
    return self.parse_response(conn, command_name, **options)
  File "/usr/local/lib/python3.10/site-packages/redis/client.py", line 1286, in parse_response
    response = connection.read_response()
  File "/usr/local/lib/python3.10/site-packages/redis/connection.py", line 897, in read_response
    raise response
redis.exceptions.ResponseError: Error running script (call to f_0ddead8550435c11fe4c969ce05d86595a096d97): @user_script:18: ERR syntax error

Setting INSIDEOUT to False, without changing anything else, works fine.

rotten commented 1 year ago

I see there are newer engine versions available for AWS Elasticache. I'll investigate that and perhaps INSIDEOUT works with the newer versions, in which case there isn't much to do about this issue other than "upgrade your #@$ cloud redis instance".

Suor commented 1 year ago

So, did it work?

rotten commented 1 year ago

We have not been able to schedule the redis/elasticache version upgrade yet. Hopefully sometime this quarter.

rotten commented 1 year ago

We tried INSIDEOUT with Elasticache redis version 7.0.7 and it works. It appears the issue was our Elasticache deployment was just too old. Thanks for holding the issue open while we got the infrastructure upgrade rolled out and could test it.

Suor commented 1 year ago

NP. Glad it worked for you.