redis.clients.jedis.Jedis.lindex()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(150)

本文整理了Java中redis.clients.jedis.Jedis.lindex()方法的一些代码示例,展示了Jedis.lindex()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jedis.lindex()方法的具体详情如下:
包路径:redis.clients.jedis.Jedis
类名称:Jedis
方法名:lindex

Jedis.lindex介绍

[英]Return the specified element of the list stored at the specified key. 0 is the first element, 1 the second and so on. Negative indexes are supported, for example -1 is the last element, -2 the penultimate and so on.

If the value stored at key is not of list type an error is returned. If the index is out of range a 'nil' reply is returned.

Note that even if the average time complexity is O(n) asking for the first or the last element of the list is O(1).

Time complexity: O(n) (with n being the length of the list)
[中]返回存储在指定键处的列表的指定元素。0是第一个元素,1是第二个元素,依此类推。支持负索引,例如-1是最后一个元素,-2是倒数第二个元素,依此类推。
如果键上存储的值不是列表类型,则返回错误。如果索引超出范围,则返回“nil”答复。
注意,即使平均时间复杂度为O(n),请求列表的第一个或最后一个元素也是O(1)。
时间复杂度:O(n)(n为列表的长度)

代码示例

代码示例来源:origin: sohutv/cachecloud

@Override
 public byte[] execute(Jedis connection) {
  return connection.lindex(key, index);
 }
}.runBinary(key);

代码示例来源:origin: sohutv/cachecloud

@Override
 public String execute(Jedis connection) {
  return connection.lindex(key, index);
 }
}.run(key);

代码示例来源:origin: sohutv/cachecloud

public byte[] execute(Jedis connection) {
    return connection.lindex(keyByte, index);
  }
}.runBinary(keyByte);

代码示例来源:origin: sohutv/cachecloud

@Override
public byte[] lindex(byte[] key, long index) {
 Jedis j = getShard(key);
 return j.lindex(key, index);
}

代码示例来源:origin: sohutv/cachecloud

@Override
public String lindex(String key, long index) {
 Jedis j = getShard(key);
 return j.lindex(key, index);
}

代码示例来源:origin: Netflix/conductor

@Override
public String lindex(String key, long index) {
 Jedis jedis = null;
  try {
   jedis = jedisPool.getResource();
   return jedis.lindex(key, index);
  } finally {
   if (jedis != null)
    jedis.close();
  }
}

代码示例来源:origin: jfinal/jfinal

/**
 * 返回列表 key 中,下标为 index 的元素。
 * 下标(index)参数 start 和 stop 都以 0 为底,也就是说,以 0 表示列表的第一个元素,以 1 表示列表的第二个元素,以此类推。
 * 你也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推。
 * 如果 key 不是列表类型,返回一个错误。
 */
@SuppressWarnings("unchecked")

/**
 * 返回列表 key 中,下标为 index 的元素。
 * 下标(index)参数 start 和 stop 都以 0 为底,也就是说,以 0 表示列表的第一个元素,
 * 以 1 表示列表的第二个元素,以此类推。
 * 你也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推。
 * 如果 key 不是列表类型,返回一个错误。
 */
public <T> T lindex(Object key, long index) {
  Jedis jedis = getJedis();
  try {
    return (T)valueFromBytes(jedis.lindex(keyToBytes(key), index));
  }
  finally {close(jedis);}
}

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public byte[] lIndex(byte[] key, long index) {
  Assert.notNull(key, "Key must not be null!");
  try {
    if (isPipelined()) {
      pipeline(connection.newJedisResult(connection.getRequiredPipeline().lindex(key, index)));
      return null;
    }
    if (isQueueing()) {
      transaction(connection.newJedisResult(connection.getRequiredTransaction().lindex(key, index)));
      return null;
    }
    return connection.getJedis().lindex(key, index);
  } catch (Exception ex) {
    throw convertJedisAccessException(ex);
  }
}

代码示例来源:origin: jwpttcg66/NettyGameServer

public String lindex(String key) {
  Jedis jedis = null;
  boolean sucess = true;
  String ret = null;
  try {
    jedis = jedisPool.getResource();
    ret = jedis.lindex(key, 0);
  } catch (Exception e) {
    sucess = false;
    returnBrokenResource(jedis, "lpop key:"+key, e);
  } finally {
    if (sucess && jedis != null) {
      returnResource(jedis);
    }
  }
  return ret;
}

代码示例来源:origin: yrain/smart-cache

@Override
  byte[] doInJedis(Jedis jedis) {
    return jedis.lindex(key, index);
  }
});

代码示例来源:origin: io.leopard/leopard-redis

@Override
  public Object execute(Jedis jedis) {
    return jedis.lindex(key, index);
  }
});

代码示例来源:origin: tangyanbo/springmore

@Override
  public String action(Jedis jedis) {
    return jedis.lindex(key, index);
  }
});

代码示例来源:origin: apache/servicemix-bundles

@Override
 public byte[] execute(Jedis connection) {
  return connection.lindex(key, index);
 }
}.runBinary(key);

代码示例来源:origin: com.netflix.spinnaker.kork/kork-jedis

@Override
public String lindex(String key, long index) {
 String command = "lindex";
 return instrumented(command, () -> delegated.lindex(key, index));
}

代码示例来源:origin: org.tinygroup/org.tinygroup.jedis

public String lindex(String key, long index) {
  Jedis j = getReadShard(key);
  return j.lindex(key, index);
}

代码示例来源:origin: apache/servicemix-bundles

@Override
public String lindex(final String key, final long index) {
 Jedis j = getShard(key);
 return j.lindex(key, index);
}

代码示例来源:origin: com.netflix.conductor/conductor-redis-persistence

@Override
public String lindex(String key, long index) {
 Jedis jedis = null;
  try {
   jedis = jedisPool.getResource();
   return jedis.lindex(key, index);
  } finally {
   if (jedis != null)
    jedis.close();
  }
}

代码示例来源:origin: xiancloud/xian

@Override
public void execute(UnitRequest msg, Handler<UnitResponse> handler) throws Exception {
  String key = msg.getArgMap().get("key").toString();
  Long index = msg.getArgMap().get("index") != null ? Long.parseLong(msg.getArgMap().get("index").toString()) : 0;
  CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
  String element;
  element = Redis.call(cacheConfigBean, (jedis) -> jedis.lindex(key, index));
  if (element != null && element.equals("nil"))
    element = null;
  handler.handle(UnitResponse.createSuccess(element));
}

代码示例来源:origin: com.github.yamingd.argo/argo-redis

public T execute(final Jedis conn) throws Exception {
    byte[] bs = conn.lindex(SafeEncoder.encode(key), index);
    if (bs == null){
      return null;
    }
    return getRedisBuffer().read(bs, clazz);
  }
});

代码示例来源:origin: xetorthio/johm

public String lindex(int index) {
  Jedis jedis = getResource();
  String lindex = jedis.lindex(key(), index);
  returnResource(jedis);
  return lindex;
}

相关文章

微信公众号

最新文章

更多

Jedis类方法