Exemple #1
0
    def on_connect(self):
        "Initialize the connection, authenticate and select a database"
        self._parser.on_connect(self)

        # if a password is specified, authenticate
        if self.password:
            self.send_command('AUTH', self.password)
            if nativestr(self.read_response()) != 'OK':
                logs.error("Invalid Password")
                raise AuthenticationError('Invalid Password')

        # if a database is specified, switch to it
        if self.db >= 0:  # 密码为空,切换db判断是否需要认证
            self.send_command('SELECT', self.db)
            if nativestr(self.read_response()) != 'OK':
                raise ConnectionError('Invalid Database')
    def on_connect(self):
        "Initialize the connection, authenticate and select a database"
        self._parser.on_connect(self)  # 初始化协议解析

        # 接下来是账号密码
        # if a password is specified, authenticate
        if self.password:
            self.send_command('AUTH', self.password)
            if nativestr(self.read_response()) != 'OK':
                raise AuthenticationError('Invalid Password')

        # if a database is specified, switch to it
        if self.db:
            self.send_command('SELECT', self.db)
            if nativestr(self.read_response()) != 'OK':
                raise ConnectionError('Invalid Database')
Exemple #3
0
    def on_connect(self):
        "Initialize the connection, authenticate and select a database"
        self._parser.on_connect(self)

        # if a password is specified, authenticate
        if self.password:
            # avoid checking health here -- PING will fail if we try
            # to check the health prior to the AUTH
            self.send_command('AUTH', self.password, check_health=False)
            if nativestr(self.read_response()) != 'OK':
                raise AuthenticationError('Invalid Password')

        # if a database is specified, switch to it
        if self.db:
            self.send_command('SELECT', self.db)
            if nativestr(self.read_response()) != 'OK':
                raise ConnectionError('Invalid Database')
Exemple #4
0
    def on_connect(self):
        "Initialize the connection, authenticate and select a database"
        self._parser.on_connect(self)
        self.stream.set_close_callback(self._parser.on_disconnect)

        # if a password is specified, authenticate
        if self.password:
            self.send_command('AUTH', self.password)
            response = self.read_response()
            if response != 'OK':
                raise AuthenticationError('Invalid Password')

        # if a database is specified, switch to it
        if self.db:
            self.send_command('SELECT', self.db)
            response = self.read_response()
            if response != 'OK':
                raise ConnectionError('Invalid Database')
Exemple #5
0
    def on_connect(self):
        "Initialize the connection, authenticate and select a database"
        self._parser.on_connect(self)

        # if a password is specified, authenticate
        if self.password:
            self.send_command('AUTH', self.password)
            if nativestr(self.read_response()) != 'OK':
                raise AuthenticationError('Invalid Password')

        if self._client_name:
            self.send_command('CLIENT', 'SETNAME', self._client_name)
            if nativestr(self.read_response()) != 'OK':
                raise ConnectionError('Error setting client name')

        # if a database is specified, switch to it
        if self.db:
            self.send_command('SELECT', self.db)
            if nativestr(self.read_response()) != 'OK':
                raise ConnectionError('Invalid Database')