Process the 'reload' control message.

    :param daemon: The control daemon; used to get at the
                   configuration and call the actual reload.
    :param load_type: Optional type of reload.  If given as
                      'immediate', reload is triggered
                      immediately.  If given as 'spread', reload
                      is triggered after a random period of time
                      in the interval (0.0, spread).  Otherwise,
                      reload will be as configured.
    :param spread: Optional argument for 'spread' load_type.  Must
                   be a float giving the maximum length of the
                   interval, in seconds, over which the reload
                   should be scheduled.  If not provided, falls
                   back to configuration.

    If a recognized load_type is not given, or is given as
    'spread' but the spread parameter is not a valid float, the
    configuration will be checked for the 'redis.reload_spread'
    value.  If that is a valid value, the reload will be randomly
    scheduled for some time within the interval (0.0,
    redis.reload_spread).

def reload(daemon, load_type=None, spread=None):
    """
    Process the 'reload' control message.

    :param daemon: The control daemon; used to get at the
                   configuration and call the actual reload.
    :param load_type: Optional type of reload.  If given as
                      'immediate', reload is triggered
                      immediately.  If given as 'spread', reload
                      is triggered after a random period of time
                      in the interval (0.0, spread).  Otherwise,
                      reload will be as configured.
    :param spread: Optional argument for 'spread' load_type.  Must
                   be a float giving the maximum length of the
                   interval, in seconds, over which the reload
                   should be scheduled.  If not provided, falls
                   back to configuration.

    If a recognized load_type is not given, or is given as
    'spread' but the spread parameter is not a valid float, the
    configuration will be checked for the 'redis.reload_spread'
    value.  If that is a valid value, the reload will be randomly
    scheduled for some time within the interval (0.0,
    redis.reload_spread).
    """

    # Figure out what type of reload this needs to be
    if load_type == 'immediate':
        spread = None
    elif load_type == 'spread':
        try:
            spread = float(spread)
        except (TypeError, ValueError):
            # Not a valid float; use the configured spread value
            load_type = None
    else:
        load_type = None

    if load_type is None:
        # Use configured set-up; see if we have a spread
        # configured
        try:
            spread = float(daemon.config['control']['reload_spread'])
        except (TypeError, ValueError, KeyError):
            # No valid configuration
            spread = None

    if spread:
        # Apply a randomization to spread the load around
        eventlet.spawn_after(random.random() * spread, daemon.reload)
    else:
        # Spawn in immediate mode
        eventlet.spawn_n(daemon.reload)