Open Jonathan-Landeed opened 10 months ago
Grrr. There's not going to be anything we can do about this.
The PubSub channel layer doesn't use Lua so you could try that.
I'm using the ServerLess Redis Cache from ElastiCache AWS and getting the error.
Exception inside application: Lua scripts without any input keys are not supported. Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/channels/routing.py", line 62, in call return await application(scope, receive, send) File "/usr/local/lib/python3.10/site-packages/channels/routing.py", line 62, in call return await application(scope, receive, send) File "/usr/local/lib/python3.10/site-packages/channels/sessions.py", line 47, in call return await self.inner(dict(scope, cookies=cookies), receive, send) File "/usr/local/lib/python3.10/site-packages/channels/sessions.py", line 263, in call return await self.inner(wrapper.scope, receive, wrapper.send) File "/usr/local/lib/python3.10/site-packages/channels/auth.py", line 185, in call return await super().call(scope, receive, send) File "/usr/local/lib/python3.10/site-packages/channels/middleware.py", line 24, in call return await self.inner(scope, receive, send) File "/usr/local/lib/python3.10/site-packages/channels/routing.py", line 116, in call return await application( File "/usr/local/lib/python3.10/site-packages/channels/consumer.py", line 94, in app return await consumer(scope, receive, send) File "/usr/local/lib/python3.10/site-packages/channels/consumer.py", line 58, in call await await_many_dispatch( File "/usr/local/lib/python3.10/site-packages/channels/utils.py", line 57, in await_many_dispatch await task redis.exceptions.ResponseError: Lua scripts without any input keys are not supported.
Here is the config:
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
'hosts': [{
"address": REDIS_HOST, # "REDIS_TLS_URL"
"ssl_cert_reqs": None,
}],
'expiry': 360,
},
},
}
.env redis host:
REDIS_HOST=rediss://<
For posterity: Confirming I can bypass the Lua issues for Serverless caches (and replication groups) using the pubsub channel layer. (Confirmed on valkey and redis).
Note: on single instances in aws, the endpoints support redis://
but on serverless you must use rediss://
Also worth noting: Not all redis features are supported on serverless caches. Like: keys(), set_many(), delete_many()
. Other features are fairly fragile get_many()
for example requires all items to be in the same hash location in memory (which is not always the case) so it fails sometimes.
Some of this is noted in the AWS docs here: https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/SupportedCommands.html#RestrictedCommandsRedis
I was not able to find other AWS docs on non supported items like Lua (which are supported in single instances but not multi) and directly relevant to this thread.
Some other functions (similar to get_many) that appear to be supported are not quite there yet. The basics seem to work well (get, set, delete ...), so you may just have to write loops for get_many and set_many. Methods like keys
are just outright not supported and probably wont be.
Anyway, here is my connection code. Hope it can help.
## Channels layers
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.pubsub.RedisPubSubChannelLayer',
'CONFIG': {
"hosts": [{
'address': "rediss://" + ebconfig("CACHE_ELASTICACHE_HOSTNAME") + ":6379",
}],
},
},
}
## General Cache support
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.redis.RedisCache",
"LOCATION": "rediss://" + ebconfig("CACHE_ELASTICACHE_HOSTNAME") + ":6379",
# Cache Timeout comes from the development settings
"TIMEOUT": CACHE_TIMEOUT,
}
}
Special shout out / thanks to: @carltongibson for the great pointer.
Works on "design your own cache" redis clusters but not serverless (engine version 7.1 for both).
Running daphne in docker on aws ec2.
Traceback:
Pip freeze: