(self, resource, lock_identifier, lock_timeout, register_scripts=False)
Lock this instance and set lock expiration time to lock_timeout
        :param resource: redis key to set
        :param lock_identifier: uniquie id of lock
        :param lock_timeout: timeout for lock in seconds
        :raises: LockError if lock is not acquired
Lock this instance and set lock expiration time to lock_timeout
        :param resource: redis key to set
        :param lock_identifier: uniquie id of lock
        :param lock_timeout: timeout for lock in seconds
        :raises: LockError if lock is not acquired
Lock this instance and set lock expiration time to lock_timeout : param resource : redis key to set : param lock_identifier : uniquie id of lock : param lock_timeout : timeout for lock in seconds : raises : LockError if lock is not acquired
async def set_lock(self, resource, lock_identifier, lock_timeout, register_scripts=False):
        """
        Lock this instance and set lock expiration time to lock_timeout
        :param resource: redis key to set
        :param lock_identifier: uniquie id of lock
        :param lock_timeout: timeout for lock in seconds
        :raises: LockError if lock is not acquired
        """

        lock_timeout_ms = int(lock_timeout * 1000)

        try:
            with await self.connect() as redis:
                if register_scripts is True:
                    await self._register_scripts(redis)
                await redis.evalsha(
                    self.set_lock_script_sha1,
                    keys=[resource],
                    args=[lock_identifier, lock_timeout_ms]
                )
        except aioredis.errors.ReplyError as exc:  # script fault
            if exc.args[0].startswith('NOSCRIPT'):
                return await self.set_lock(resource, lock_identifier, lock_timeout, register_scripts=True)
            self.log.debug('Can not set lock "%s" on %s',
                           resource, repr(self))
            raise LockAcquiringError('Can not set lock') from exc
        except (aioredis.errors.RedisError, OSError) as exc:
            self.log.error('Can not set lock "%s" on %s: %s',
                           resource, repr(self), repr(exc))
            raise LockRuntimeError('Can not set lock') from exc
        except asyncio.CancelledError:
            self.log.debug('Lock "%s" is cancelled on %s',
                           resource, repr(self))
            raise
        except Exception:
            self.log.exception('Can not set lock "%s" on %s',
                               resource, repr(self))
            raise
        else:
            self.log.debug('Lock "%s" is set on %s', resource, repr(self))
async def set_lock ( self , resource , lock_identifier , lock_timeout , register_scripts = False ) : lock_timeout_ms = int ( lock_timeout * 1000 ) try : with await self . connect ( ) as redis : if register_scripts is True : await self . _register_scripts ( redis ) await redis . evalsha ( self . set_lock_script_sha1 , keys = [ resource ] , args = [ lock_identifier , lock_timeout_ms ] ) except aioredis . errors . ReplyError as exc : # script fault if exc . args [ 0 ] . startswith ( 'NOSCRIPT' ) : return await self . set_lock ( resource , lock_identifier , lock_timeout , register_scripts = True ) self . log . debug ( 'Can not set lock "%s" on %s' , resource , repr ( self ) ) raise LockAcquiringError ( 'Can not set lock' ) from exc except ( aioredis . errors . RedisError , OSError ) as exc : self . log . error ( 'Can not set lock "%s" on %s: %s' , resource , repr ( self ) , repr ( exc ) ) raise LockRuntimeError ( 'Can not set lock' ) from exc except asyncio . CancelledError : self . log . debug ( 'Lock "%s" is cancelled on %s' , resource , repr ( self ) ) raise except Exception : self . log . exception ( 'Can not set lock "%s" on %s' , resource , repr ( self ) ) raise else : self . log . debug ( 'Lock "%s" is set on %s' , resource , repr ( self ) )