Acquires a write lock on a specific key.
@param key The key to lock
@param timeout in milliseconds; -1 means wait indefinitely, 0 means no wait.
19162
public void writeLock(EntityKey key, int timeout) {
		ReadWriteLock lock = getLock( key );
		Lock writeLock = lock.writeLock();
		acquireLock( key, timeout, writeLock );
	}
767285
def brpop(self, key, *keys, timeout=0, encoding=_NOTSET):
        
        if not isinstance(timeout, int):
            raise TypeError("timeout argument must be int")
        if timeout < 0:
            raise ValueError("timeout must be greater equal 0")
        args = keys + (timeout,)
        return self.execute(b'BRPOP', key, *args, encoding=encoding)
780989
def raise_or_lock(self, key, timeout):
        
        acquired = Lock(
            self.redis,
            key,
            timeout=timeout,
            blocking=self.blocking,
            blocking_timeout=self.blocking_timeout
        ).acquire()

        if not acquired:
            # Time remaining in milliseconds
            # https://redis.io/commands/pttl
            ttl = self.redis.pttl(key)
            raise AlreadyQueued(ttl / 1000.)
463553
@Override
	public void notifyTimeout(AllocationID key, UUID ticket) {
		checkInit();

		if (slotActions != null) {
			slotActions.timeoutSlot(key, ticket);
		}
	}
884773
@SuppressWarnings("unchecked")
  public final <T> T get(final String key, final long timeout)
      throws TimeoutException, InterruptedException, MemcachedException {
    return (T) this.get(key, timeout, this.transcoder);
  }
911138
public final void set(String key, Object value) {
		try {
			this.mutex.acquire();
			if (value == null) {
				this.valueMap.remove(key);
			} else {
				this.valueMap.put(key, value);
			}
		} finally {
			try {
				this.mutex.release();
			} catch (Exception ignore) {
			}
		}
	}
1043730
private static void wait(Object lock, int timeout)
  {
    try {
      lock.wait(timeout);
    }
    catch(InterruptedException unused) {
      Thread.currentThread().interrupt();
    }
  }
1199810
public function lock($key, $timeout = self::EXPIRE): bool
    {
        $wait = 20000;
        $totalWait = 0;
        $time = $timeout * 1000000;
        $key = self::PREFIX . $key;

        while ($totalWait < $time && false === $this->mem->add($key, 1, $timeout)) {
            usleep($wait);
            $totalWait += $wait;
        }

        if ($totalWait >= $time) {
            throw new \RuntimeException('cannot get lock for waiting ' . $timeout . 's.', __LINE__);
        }

        return true;
    }
573849
public final boolean add(final String key, final int exp, final Object value)
      throws TimeoutException, InterruptedException, MemcachedException {
    return this.add(key, exp, value, this.opTimeout);
  }
882024
def set(self, key, value, timeout=None):
        
        key = self.make_key(key)
        if timeout is None:
            timeout = self.default_timeout

        if self.debug:
            return True

        pickled_value = pickle.dumps(value)
        self.metrics['writes'] += 1
        if timeout:
            return self.database.setex(key, int(timeout), pickled_value)
        else:
            return self.database.set(key, pickled_value)
826812
public void registerTimeout(final K key, final long delay, final TimeUnit unit) {
		Preconditions.checkState(timeoutListener != null, "The " + getClass().getSimpleName() +
			" has not been started.");

		if (timeouts.containsKey(key)) {
			unregisterTimeout(key);
		}

		timeouts.put(key, new Timeout<>(timeoutListener, key, delay, unit, scheduledExecutorService));
	}
787174
public final <T> boolean add(String key, final int exp, final T value,
      final Transcoder<T> transcoder, final long timeout)
      throws TimeoutException, InterruptedException, MemcachedException {
    key = this.preProcessKey(key);
    return this.add0(key, exp, value, transcoder, timeout);
  }
270081
public Long pexpire(Object key, long milliseconds) {
		Jedis jedis = getJedis();
		try {
			return jedis.pexpire(keyToBytes(key), milliseconds);
		}
		finally {close(jedis);}
	}
1065583
public function lock($key, $timeout = self::EXPIRE): bool
    {
        // $startTime = time();
        $file = sprintf('%s/%s.lock', $this->options['tmpDir'], md5(__FILE__ . $key));

        if (!$this->fp = fopen($file, 'wb+')) {
            throw new \RuntimeException('open file failed. FILE: ' . $file);
        }

        // LOCK_SH 取得共享锁定（读取的程序）
        // LOCK_EX 取得独占锁定,排它型锁定（写入的程序）
        // LOCK_UN 释放锁定（无论共享或独占）
        $op = $this->options['single'] ? LOCK_EX + LOCK_NB : LOCK_EX;

        // 如果锁定会堵塞的话（EWOULDBLOCK 错误码情况下），可选的第三个参数会被设置为 TRUE。（Windows 上不支持）
        return flock($this->fp, $op, $this->wouldBlock);
    }
721180
public void setLockTimeout(int timeout, TimeUnit unit) {
        if (timeout < 0 || unit == null) {
            throw new IllegalArgumentException();
        }
        mLockTimeout = timeout;
        mLockTimeoutUnit = unit;
    }
1136856
public Long pexpireAt(Object key, long millisecondsTimestamp) {
		Jedis jedis = getJedis();
		try {
			return jedis.pexpireAt(keyToBytes(key), millisecondsTimestamp);
		}
		finally {close(jedis);}
	}
413065
public static void setWriteTimeout(int seconds) throws AVException {
    if (seconds <= 0) {
      throw new AVException(new IllegalArgumentException("Timeout too small"));
    }
    if (seconds > 60 * 60) {
      throw new AVException(new IllegalArgumentException("Timeout too large"));
    }
    writeTimeout = seconds;
  }