예제 #1
0
파일: lock.py 프로젝트: Vi-l-uc/TeleBot
 def do_release(self, expected_token):
     if not bool(
             self.lua_release(keys=[self.name],
                              args=[expected_token],
                              client=self.redis)):
         raise LockNotOwnedError("Cannot release a lock"
                                 " that's no longer owned")
예제 #2
0
 async def do_reacquire(self) -> bool:
     timeout = int(self.timeout * 1000)
     if not bool(await self.lua_reacquire(keys=[self.name],
                                          args=[self.local.token, timeout],
                                          client=self.redis)):
         raise LockNotOwnedError("Cannot reacquire a lock that's"
                                 " no longer owned")
     return True
예제 #3
0
 def do_extend(self, additional_time):
     additional_time = int(additional_time * 1000)
     if not bool(self.lua_extend(keys=[self.name],
                                 args=[self.local.token, additional_time],
                                 client=self.redis)):
         raise LockNotOwnedError("Cannot extend a lock that's"
                                 " no longer owned")
     return True
예제 #4
0
 async def do_extend(self, additional_time, replace_ttl) -> bool:
     additional_time = int(additional_time * 1000)
     if not bool(
         await self.lua_extend(
             keys=[self.name],
             args=[self.local.token, additional_time, replace_ttl and "1" or "0"],
             client=self.redis,
         )
     ):
         raise LockNotOwnedError("Cannot extend a lock that's" " no longer owned")
     return True
예제 #5
0
 def do_extend(self, additional_time: int, replace_ttl: bool) -> bool:
     additional_time = int(additional_time * 1000)
     if not bool(
             self.lua_extend(
                 keys=[self.name],
                 args=[
                     self.local.token, additional_time,
                     "1" if replace_ttl else "0"
                 ],
                 client=self.redis,
             )):
         raise LockNotOwnedError(
             "Cannot extend a lock that's no longer owned")
     return True