django / channels_redis

Redis channel layer backend for Django Channels
BSD 3-Clause "New" or "Revised" License
601 stars 197 forks source link

support msgpack.packb kwargs #380

Open mpnowacki-reef opened 10 months ago

mpnowacki-reef commented 10 months ago

The main reason for submitting this PR is to give users the ability to subclass RedisChannelLayer and do sth like:

def default(value):
    if isinstance(value, enum.Enum):
        return value.value
    return value

class ECRedisChannelLayer(RedisChannelLayer):
    """EC stands for "enum-compatible" """
    def _packing_kwargs(self, message):
        return {**super()._packing_kwargs, 'default': default}