def METHOD_NAME(
    self, key: KEY_TYPE, events: List[Any], client: Optional[Redis] = None
) -> int:
    start_index = -self.max_size
    events_data = [self.encode(event) for event in events[start_index:]]
    if client is None:
        client = self.client
    client.lpush(key, *events_data)
    client.ltrim(key, 0, max(0, self.max_size - 1))
    client.expire(key, self.timeout)
    return max(0, len(events) - self.max_size)