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

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

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

Jedis.mget介绍

[英]Get the values of all the specified keys. If one or more keys don't exist or is not of type String, a 'nil' value is returned instead of the value of the specified key, but the operation never fails.

Time complexity: O(1) for every key
[中]获取所有指定键的值。如果一个或多个键不存在或不是String类型,则返回一个“nil”值,而不是指定键的值,但操作从未失败。
时间复杂度:每个密钥为O(1)

代码示例

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

@Override
 public List<byte[]> execute(Jedis connection) {
  return connection.mget(keys);
 }
}.runBinary(keys.length, keys);

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

@Override
 public List<String> execute(Jedis connection) {
  return connection.mget(keys);
 }
}.run(keys.length, keys);

代码示例来源:origin: apache/incubator-druid

@Override
public Map<NamedKey, byte[]> getBulk(Iterable<NamedKey> keys)
{
 totalRequestCount.incrementAndGet();
 Map<NamedKey, byte[]> results = new HashMap<>();
 try (Jedis jedis = pool.getResource()) {
  List<NamedKey> namedKeys = Lists.newArrayList(keys);
  List<byte[]> byteKeys = Lists.transform(namedKeys, NamedKey::toByteArray);
  List<byte[]> byteValues = jedis.mget(byteKeys.toArray(new byte[0][]));
  for (int i = 0; i < byteValues.size(); ++i) {
   if (byteValues.get(i) != null) {
    results.put(namedKeys.get(i), byteValues.get(i));
   }
  }
  hitCount.addAndGet(results.size());
  missCount.addAndGet(namedKeys.size() - results.size());
 }
 catch (JedisException e) {
  if (e.getMessage().contains("Read timed out")) {
   timeoutCount.incrementAndGet();
  } else {
   errorCount.incrementAndGet();
  }
  log.warn(e, "Exception pulling items from cache");
 }
 return results;
}

代码示例来源:origin: apache/storm

/**
   * {@inheritDoc}
   */
  @Override
  protected List<String> retrieveValuesFromRedis(RedisState state, List<String> keys) {
    Jedis jedis = null;
    try {
      jedis = state.getJedis();
      List<String> redisVals;

      String[] keysForRedis = keys.toArray(new String[keys.size()]);
      switch (dataType) {
        case STRING:
          redisVals = jedis.mget(keysForRedis);
          break;
        case HASH:
          redisVals = jedis.hmget(additionalKey, keysForRedis);
          break;
        default:
          throw new IllegalArgumentException("Cannot process such data type: " + dataType);
      }

      return redisVals;
    } finally {
      if (jedis != null) {
        state.returnJedis(jedis);
      }
    }
  }
}

代码示例来源:origin: apache/storm

/**
 * {@inheritDoc}
 */
@Override
protected List<String> retrieveValuesFromRedis(List<String> keys) {
  String[] stringKeys = keys.toArray(new String[keys.size()]);
  Jedis jedis = null;
  try {
    jedis = jedisPool.getResource();
    RedisDataTypeDescription description = this.options.dataTypeDescription;
    switch (description.getDataType()) {
      case STRING:
        return jedis.mget(stringKeys);
      case HASH:
        return jedis.hmget(description.getAdditionalKey(), stringKeys);
      default:
        throw new IllegalArgumentException("Cannot process such data type: " + description.getDataType());
    }
  } finally {
    if (jedis != null) {
      jedis.close();
    }
  }
}

代码示例来源:origin: alibaba/jetcache

List mgetResults = jedis.mget(newKeys);
for (int i = 0; i < mgetResults.size(); i++) {
  Object value = mgetResults.get(i);

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

/**
 * 返回所有(一个或多个)给定 key 的值。
 * 如果给定的 key 里面,有某个 key 不存在,那么这个 key 返回特殊值 nil 。因此,该命令永不失败。
 */
@SuppressWarnings("rawtypes")
public List mget(Object... keys) {
  Jedis jedis = getJedis();
  try {
    byte[][] keysBytesArray = keysToBytesArray(keys);
    List<byte[]> data = jedis.mget(keysBytesArray);
    return valueListFromBytesList(data);
  }
  finally {close(jedis);}
}

代码示例来源:origin: apache/ignite

/**
   * @throws Exception If failed.
   */
  @Test
  public void testMGet() throws Exception {
    try (Jedis jedis = pool.getResource()) {
      jcache().put("getKey1", "getVal1");
      jcache().put("getKey2", 0);

      List<String> res = jedis.mget("getKey1", "getKey2", "wrongKey");

      Assert.assertTrue(res.contains("getVal1"));
      Assert.assertTrue(res.contains("0"));

//            not supported.
//            fail("Incompatible! getAll() does not return null values!");
//            Assert.assertTrue(result.contains("nil"));
    }
  }

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

@Override
public List<byte[]> mGet(byte[]... keys) {
  Assert.notNull(keys, "Keys must not be null!");
  Assert.noNullElements(keys, "Keys must not contain null elements!");
  try {
    if (isPipelined()) {
      pipeline(connection.newJedisResult(connection.getRequiredPipeline().mget(keys)));
      return null;
    }
    if (isQueueing()) {
      transaction(connection.newJedisResult(connection.getRequiredTransaction().mget(keys)));
      return null;
    }
    return connection.getJedis().mget(keys);
  } catch (Exception ex) {
    throw convertJedisAccessException(ex);
  }
}

代码示例来源:origin: javahongxi/whatsmars

public List<String> mget(String... keys) {
  Jedis jedis = fetchResource(true);
  try {
    return jedis.mget(keys);
  } finally {
    if (jedis != null) {
      jedis.close();
    }
  }
}

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

for(int i=0;i<page;i++){
  tmp.addAll(PageUtils.getSubListPage(keys, i * GlobalConstants.RedisKeyConfig.MGET_MAX_KEY, GlobalConstants.RedisKeyConfig.MGET_MAX_KEY));
  rt.addAll(jedis.mget(tmp.toArray(new String[0])));
  tmp.clear();
rt = jedis.mget(keys2);

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

@Override
 public List<String> execute(Jedis connection) {
  return connection.mget(keys);
 }
}.run(keys.length, keys);

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

@Override
public List<String> mget(String... keys) {
  return jedis.mget(keys);
}

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

@Override
  public Object execute(Jedis jedis) {
    return jedis.mget(keys);
  }
});

代码示例来源:origin: com.github.sogyf/goja-mvt

@Override
  public List<String> action(Jedis jedis) {
    return jedis.mget(keys);
  }
});

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

@Override
  public List<String> action(Jedis jedis) {
    return jedis.mget(keys);
  }
});

代码示例来源:origin: biezhi/java-library-examples

public static void main(String[] args) {
  try (Jedis jedis = JedisUtil.getInstance().getJedis()) {
    jedis.rpush("ids", "aa");
    jedis.rpush("ids", "bb");
    jedis.rpush("ids", "cc");
    List<String> ids = jedis.lrange("ids", 0, -1);
    jedis.set("aa", "{'name':'zhoujie','age':20}");
    jedis.set("bb", "{'name':'yilin','age':28}");
    jedis.set("cc", "{'name':'lucy','age':21}");
    List<String> list = jedis.mget(ids.toArray(new String[ids.size()]));
    System.out.println(list);
  }
}

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-redis

/**
 * @since 9.10
 */
protected List<byte[]> getValuesForKeys(Collection<String> keys) {
  byte[][] byteKeys = new byte[keys.size()][];
  int i = 0;
  for (String key : keys) {
    byteKeys[i++] = getBytes(namespace + key);
  }
  RedisExecutor redisExecutor = Framework.getService(RedisExecutor.class);
  return redisExecutor.execute(jedis -> jedis.mget(byteKeys));
}

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

public List<T> execute(final Jedis conn) throws Exception {
    List<byte[]> bytes = conn.mget(SafeEncoder.encodeMany(keys));
    return getRedisBuffer().read(bytes, clazz);
  }
});

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

default List<String> mget(String... keys) {
 return this.run((jedis, serializer) ->
  EnoaRedisConvert.with(serializer).convertList(jedis.mget(EnoaRedisConvert.with(serializer).toBytesKeys(keys))));
}

相关文章

Jedis类方法