當前位置: 首頁>>代碼示例>>Java>>正文


Java Jedis.hkeys方法代碼示例

本文整理匯總了Java中redis.clients.jedis.Jedis.hkeys方法的典型用法代碼示例。如果您正苦於以下問題:Java Jedis.hkeys方法的具體用法?Java Jedis.hkeys怎麽用?Java Jedis.hkeys使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在redis.clients.jedis.Jedis的用法示例。


在下文中一共展示了Jedis.hkeys方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addBatch

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public void addBatch(String queueID, Set<ResourceItem> resourceItems) {
    if (!lockQueue(queueID)) {
        return;
    }
    final Jedis jedis = jedisPool.getResource();
    final String dataKey = makeDataKey(queueID);
    try {
        final Set<String> hkeys = jedis.hkeys(dataKey);
        Set<ResourceItem> filterSet = Sets.filter(resourceItems, new Predicate<ResourceItem>() {
            @Override
            public boolean apply(ResourceItem input) {
                return !hkeys.contains(input.getKey());
            }
        });

        String poolQueueKey = makePoolQueueKey(queueID);
        for (ResourceItem resourceItem : filterSet) {
            jedis.hset(dataKey, resourceItem.getKey(), JSONObject.toJSONString(resourceItem));
            jedis.rpush(poolQueueKey, resourceItem.getKey());
        }
    } finally {
        IOUtils.closeQuietly(jedis);
        unLockQueue(queueID);
    }
}
 
開發者ID:virjar,項目名稱:vscrawler,代碼行數:27,代碼來源:JedisQueueStore.java

示例2: notExisted

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public Set<String> notExisted(String queueID, Set<String> resourceItemKeys) {
    if (!lockQueue(queueID)) {
        return Collections.emptySet();
    }
    Jedis jedis = jedisPool.getResource();
    try {
        final Set<String> hkeys = jedis.hkeys(makeDataKey(queueID));
        return Sets.filter(resourceItemKeys, new Predicate<String>() {
            @Override
            public boolean apply(String input) {
                return !hkeys.contains(input);
            }
        });
    } finally {
        IOUtils.closeQuietly(jedis);
        unLockQueue(queueID);
    }
}
 
開發者ID:virjar,項目名稱:vscrawler,代碼行數:20,代碼來源:JedisQueueStore.java

示例3: notExisted

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public Set<String> notExisted(String queueID, Set<String> resourceItemKeys) {
    if (!lockQueue(queueID)) {
        return Collections.emptySet();
    }
    @Cleanup Jedis jedis = jedisPool.getResource();
    try {
        final Set<String> existedSet = jedis.hkeys(makeDataKey(queueID));
        return Sets.filter(resourceItemKeys, new Predicate<String>() {
            @Override
            public boolean apply(String input) {
                return !existedSet.contains(input);
            }
        });
    } finally {
        unLockQueue(queueID);
    }
}
 
開發者ID:virjar,項目名稱:vscrawler,代碼行數:19,代碼來源:JedisSegmentQueueStore.java

示例4: doRequest

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
protected int doRequest(Jedis jedis, String redisAddress) {
  Set<byte[]> fields = jedis.hkeys(key.getBytes());
  redisFields[index] = fields;

  if (CollectionUtils.isEmpty(fields)) {
    String verbose = String.format("get fields [%s] from [%s] is empty", key, redisAddress);
    LOGGER.debug(verbose);
    return 1;
  }

  return 0;
}
 
開發者ID:XiaoMi,項目名稱:ECFileCache,代碼行數:14,代碼來源:RedisHKeys.java

示例5: hkeys

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public Set<String> hkeys(String key) {
    Jedis jedis = null;
    Set<String> res = null;
    try {
        jedis = pool.getResource();
        res = jedis.hkeys(key);
    } catch (Exception e) {

        LOGGER.error(e.getMessage());
    } finally {
        returnResource(pool, jedis);
    }
    return res;
}
 
開發者ID:wxiaoqi,項目名稱:ace-cache,代碼行數:16,代碼來源:RedisServiceImpl.java

示例6: addBatch

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public void addBatch(String queueID, Set<ResourceItem> resourceItems) {
    if (!lockQueue(queueID)) {
        return;
    }
    @Cleanup Jedis jedis = jedisPool.getResource();
    final String dataKey = makeDataKey(queueID);
    try {
        final Set<String> hkeys = jedis.hkeys(dataKey);
        Set<ResourceItem> filterSet = Sets.filter(resourceItems, new Predicate<ResourceItem>() {
            @Override
            public boolean apply(ResourceItem input) {
                return !hkeys.contains(input.getKey());
            }
        });
        List<String> sliceQueue = sliceQueue(queueID);
        Set<String> newSlices = Sets.newHashSet();
        long index = size(queueID) + 1;
        String tailSlice = null;
        for (ResourceItem resourceItem : filterSet) {
            jedis.hset(dataKey, resourceItem.getKey(), JSONObject.toJSONString(resourceItem));
            String sliceID = String.valueOf(blockID(index));
            if (sliceID.equals(tailSlice) || sliceQueue.contains(sliceID)) {
                sliceID = sliceQueue.get(sliceQueue.size() - 1);
                tailSlice = sliceID;
            } else if (!newSlices.contains(sliceID)) {
                jedis.rpush(makeSliceQueueKey(queueID), sliceID);
                newSlices.add(sliceID);
            }
            jedis.rpush(makePoolQueueKey(queueID, sliceID), resourceItem.getKey());
            index++;
        }
    } finally {
        unLockQueue(queueID);
    }
}
 
開發者ID:virjar,項目名稱:vscrawler,代碼行數:37,代碼來源:JedisSegmentQueueStore.java

示例7: testJedis

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Test
public void testJedis() {

  String host = "localhost";
  int port = 6379;
  String key = "test_xxx";
  String keyNotExist = "test_not_exist";

  String field = "field_1";
  String value = "value_1";

  String fieldNotExist = "field_not_exist";

  JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
  jedisPoolConfig.setMaxTotal(Config.getInstance().getJedisPoolMax());

  JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, Config.getInstance().getJedisSocketTimeoutMs(), Config.getInstance().getRedisPassword());
  Jedis jedis = jedisPool.getResource();

  jedis.hset(key.getBytes(), field.getBytes(), value.getBytes());

  // hgetAll
  Map<byte[], byte[]> result = jedis.hgetAll(key.getBytes());
  Assert.assertTrue(MapUtils.isNotEmpty(result));

  result = jedis.hgetAll(keyNotExist.getBytes());
  Assert.assertTrue(MapUtils.isEmpty(result));

  // hkeys
  Set<byte[]> redisKeys = jedis.hkeys(key.getBytes());
  Assert.assertTrue(CollectionUtils.isNotEmpty(redisKeys));

  redisKeys = jedis.hkeys(keyNotExist.getBytes());
  Assert.assertTrue(CollectionUtils.isEmpty(redisKeys));


  // hget
  byte[] redisValue = jedis.hget(key.getBytes(), field.getBytes());
  Assert.assertTrue(!ArrayUtils.isEmpty(redisValue));

  redisValue = jedis.hget(key.getBytes(), fieldNotExist.getBytes());
  Assert.assertTrue(ArrayUtils.isEmpty(redisValue));

  redisValue = jedis.hget(keyNotExist.getBytes(), field.getBytes());
  Assert.assertTrue(ArrayUtils.isEmpty(redisValue));

}
 
開發者ID:XiaoMi,項目名稱:ECFileCache,代碼行數:48,代碼來源:RedisAccessTest.java


注:本文中的redis.clients.jedis.Jedis.hkeys方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。