def listen(self):
        """
        Listen for incoming control messages.

        If the 'redis.shard_hint' configuration is set, its value will
        be passed to the pubsub() method when setting up the
        subscription.  The control channel to subscribe to is
        specified by the 'redis.control_channel' configuration
        ('control' by default).
        """

        # Use a specific database handle, with override.  This allows
        # the long-lived listen thread to be configured to use a
        # different database or different database options.
        db = self.config.get_database('control')

        # Need a pub-sub object
        kwargs = {}
        if 'shard_hint' in self.config['control']:
            kwargs['shard_hint'] = self.config['control']['shard_hint']
        pubsub = db.pubsub(**kwargs)

        # Subscribe to the right channel(s)...
        channel = self.config['control'].get('channel', 'control')
        pubsub.subscribe(channel)

        # Now we listen...
        for msg in pubsub.listen():
            # Only interested in messages to our reload channel
            if (msg['type'] in ('pmessage', 'message') and
                    msg['channel'] == channel):
                # Figure out what kind of message this is
                command, _sep, args = msg['data'].partition(':')

                # We must have some command...
                if not command:
                    continue

                # Don't do anything with internal commands
                if command[0] == '_':
                    LOG.error("Cannot call internal command %r" % command)
                    continue

                # Look up the command
                if command in self._commands:
                    func = self._commands[command]
                else:
                    # Try an entrypoint
                    func = utils.find_entrypoint('turnstile.command', command,
                                                 compat=False)
                    self._commands[command] = func

                # Don't do anything with missing commands
                if not func:
                    LOG.error("No such command %r" % command)
                    continue

                # Execute the desired command
                arglist = args.split(':') if args else []
                try:
                    func(self, *arglist)
                except Exception:
                    LOG.exception("Failed to execute command %r arguments %r" %
                                  (command, arglist))
                    continue
def listen ( self ) : db = self . config . get_database ( 'control' ) kwargs = { } if 'shard_hint' in self . config [ 'control' ] : kwargs [ 'shard_hint' ] = self . config [ 'control' ] [ 'shard_hint' ] pubsub = db . pubsub ( ** kwargs ) channel = self . config [ 'control' ] . get ( 'channel' , 'control' ) pubsub . subscribe ( channel ) for msg in pubsub . listen ( ) : if ( msg [ 'type' ] in ( 'pmessage' , 'message' ) and msg [ 'channel' ] == channel ) : command , _sep , args = msg [ 'data' ] . partition ( ':' ) if not command : continue if command [ 0 ] == '_' : LOG . error ( "Cannot call internal command %r" % command ) continue if command in self . _commands : func = self . _commands [ command ] else : func = utils . find_entrypoint ( 'turnstile.command' , command , compat = False ) self . _commands [ command ] = func if not func : LOG . error ( "No such command %r" % command ) continue arglist = args . split ( ':' ) if args else [ ] try : func ( self , * arglist ) except Exception : LOG . exception ( "Failed to execute command %r arguments %r" % ( command , arglist ) ) continue
Listen for incoming control messages.

        If the 'redis.shard_hint' configuration is set, its value will
        be passed to the pubsub() method when setting up the
        subscription.  The control channel to subscribe to is
        specified by the 'redis.control_channel' configuration
        ('control' by default).