redis队列操作

来源:互联网 发布:国税总局网络 编辑:程序博客网 时间:2024/05/22 03:47

jedis-2.7.0.jar
添加

/**   * Add the string value to the head (LPUSH) or tail (RPUSH) of the list stored at key. If the key   * does not exist an empty list is created just before the append operation. If the key exists but   * is not a List an error is returned.   * <p>   * Time complexity: O(1)   * @param key   * @param strings   * @return Integer reply, specifically, the number of elements inside the list after the push   *         operation.   */  public Long rpush(final String key, final String... strings) {    checkIsInMulti();    client.rpush(key, strings);    return client.getIntegerReply();  }  /**   * Add the string value to the head (LPUSH) or tail (RPUSH) of the list stored at key. If the key   * does not exist an empty list is created just before the append operation. If the key exists but   * is not a List an error is returned.   * <p>   * Time complexity: O(1)   * @param key   * @param strings   * @return Integer reply, specifically, the number of elements inside the list after the push   *         operation.   */  public Long lpush(final String key, final String... strings) {    checkIsInMulti();    client.lpush(key, strings);    return client.getIntegerReply();  }

弹出

/**   * Atomically return and remove the first (LPOP) or last (RPOP) element of the list. For example   * if the list contains the elements "a","b","c" LPOP will return "a" and the list will become   * "b","c".   * <p>   * If the key does not exist or the list is already empty the special value 'nil' is returned.   * @see #rpop(String)   * @param key   * @return Bulk reply   */  public String lpop(final String key) {    checkIsInMulti();    client.lpop(key);    return client.getBulkReply();  }  /**   * Atomically return and remove the first (LPOP) or last (RPOP) element of the list. For example   * if the list contains the elements "a","b","c" RPOP will return "c" and the list will become   * "a","b".   * <p>   * If the key does not exist or the list is already empty the special value 'nil' is returned.   * @see #lpop(String)   * @param key   * @return Bulk reply   */  public String rpop(final String key) {    checkIsInMulti();    client.rpop(key);    return client.getBulkReply();  }
原创粉丝点击