Untitled

mail@pastecode.io avatar
unknown
plain_text
20 days ago
747 B
5
Indexable
Never
def unlock(self, key: str) -> str | None:
    if key not in self.db and key not in self.locks:
        return "invalid_request"  # Key doesn't exist in the database and is not locked
    
    if key not in self.locks:
        return None  # Key exists but is not locked
    
    # Release the lock
    self.locks.pop(key)
    
    # Handle the lock queue
    if key in self.lock_queues and self.lock_queues[key]:
        next_user = self.lock_queues[key].popleft()
        self.locks[key] = next_user
        if not self.lock_queues[key]:
            del self.lock_queues[key]
    
    # Clean up if the key was deleted
    if key not in self.db:
        if key in self.lock_queues:
            del self.lock_queues[key]
    
    return "released"
Leave a Comment