Java Code Examples for redis.clients.jedis.Jedis#zrange()

The following examples show how to use redis.clients.jedis.Jedis#zrange() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JedisBlockingQueueStore.java    From vscrawler with Apache License 2.0 6 votes vote down vote up
@Override
public ResourceItem poll(String queueID) {
    Jedis jedis = jedisPool.getResource();
    try {
        Set<String> zrange = jedis.zrange(makePoolQueueKey(queueID), 0, 1);
        if (zrange.size() == 0) {
            return null;
        }
        String key = zrange.iterator().next();
        String data = jedis.hget(makeDataKey(queueID), key);
        if (StringUtils.isBlank(data)) {
            VSCrawlerMonitor.recordOne(queueID + "_find_meta_data_failed");
            return null;
        }
        return JSONObject.toJavaObject(JSON.parseObject(data), ResourceItem.class);
    } finally {
        IOUtils.closeQuietly(jedis);
    }
}
 
Example 2
Source File: JedisBlockingQueueStore.java    From vscrawler with Apache License 2.0 6 votes vote down vote up
@Override
public Set<String> notExisted(String queueID, Set<String> resourceItemKeys) {
    if (!lockQueue(queueID)) {
        return Collections.emptySet();
    }
    Jedis jedis = jedisPool.getResource();
    try {
        final Set<String> keys = jedis.zrange(makePoolQueueKey(queueID), 0, -1);
        return Sets.filter(resourceItemKeys, new Predicate<String>() {
            @Override
            public boolean apply(String input) {
                return !keys.contains(input);
            }
        });
    } finally {
        IOUtils.closeQuietly(jedis);
        unLockQueue(queueID);
    }
}
 
Example 3
Source File: KarmaDB.java    From VileBot with MIT License 6 votes vote down vote up
/**
 * Get nouns from a karma rank, starting with the lowest ranks.
 * 
 * @param lower The lower rank to get the nouns of.
 * @param upper The upper rank to get the nouns of.
 * @return String The noun iff the rank exists, else null.
 */
public static Set<String> getRevRankNouns( long lower, long upper )
{
    Set<String> nouns;

    Jedis jedis = pool.getResource();
    try
    {
        nouns = jedis.zrange( keyOfKarmaSortedSet, lower, upper );
    }
    finally
    {
        pool.returnResource( jedis );
    }

    if ( nouns == null || nouns.size() == 0 )
    {
        return null;
    }

    return nouns;
}
 
Example 4
Source File: JedisUtils.java    From fw-spring-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * 返回有序集 key 中,指定区间内的成员。min=0,max=-1代表所有元素
 * </p>
 *
 * @param key
 * @param min
 * @param max
 * @return 指定区间内的有序集成员的列表。
 */
public Set<String> zrange(String key, long min, long max) {
    Jedis jedis = null;
    try {
        jedis = jedisPool.getResource();
        return jedis.zrange(key, min, max);
    } catch (Exception e) {

        log.error(e.getMessage());
    } finally {
        returnResource(jedisPool, jedis);
    }
    return null;
}
 
Example 5
Source File: ZSetOperUtil.java    From springboot-learn with MIT License 5 votes vote down vote up
public static void oper(Jedis jedis) {

        jedis.zadd("zset", 3, "3");
        jedis.zadd("zset", 4, "5");
        jedis.zadd("zset", 5, "5");
        jedis.zadd("zset", 6, "6");
        Set<String> zset = jedis.zrange("zset", 0, -1);
        System.out.println("zset:" + zset);
        System.out.println("zset type:" + jedis.type("zset"));

    }
 
Example 6
Source File: JedisClientPool.java    From paas with Apache License 2.0 5 votes vote down vote up
@Override
public Set<String> zrange(String key, long start, long end) {
    Jedis jedis = jedisPool.getResource();
    Set<String> result = jedis.zrange(key, start, end);
    jedis.close();
    return result;
}
 
Example 7
Source File: RedisActionHistory.java    From seldon-server with Apache License 2.0 5 votes vote down vote up
@Override
public List<Long> getRecentActions(String clientName, long userId,int numActions) {
	List<Long> res = new ArrayList<Long>();
	JedisPool pool = poolManager.get(clientName);
	if (pool != null)
	{
		Jedis jedis = null;
		try
		{
			jedis = pool.getResource();
			String key = MemCacheKeys.getActionHistory(clientName, userId);
			Set<String> itemSet = jedis.zrange(key, 0, -1);
			for (String item : itemSet)
			{
				item = item.replaceAll("\"", "");
				res.add(0,Long.parseLong(item));// reverse order so last ones are earliest in time
			}
			if (res.size() > numActions)
				res = res.subList(0, numActions);
		}
		finally
		{
		 if (jedis != null) {
			    jedis.close();
			  }
		}
	}
	else
	{
		logger.error("No redis pool found for "+clientName);
	}
	if (logger.isDebugEnabled())
		logger.debug("For user "+userId+" found "+res.size()+" actions:"+res.toString());
	return res;
}
 
Example 8
Source File: RedisActionHistory.java    From seldon-server with Apache License 2.0 5 votes vote down vote up
@Override
public List<Action> getRecentFullActions(String clientName, long userId,int numActions) {
	List<Action> actions = new ArrayList<Action>();
	JedisPool pool = poolManager.get(clientName);
	if (pool != null)
	{
		Jedis jedis = null;
		try
		{
			jedis = pool.getResource();
			String key = MemCacheKeys.getActionFullHistory(clientName, userId);
			Set<String> actionSet = jedis.zrange(key, 0, -1);
			for (String val : actionSet)
			{
                ActionLogEntry ale = mapper.readValue(val, ActionLogEntry.class);
                actions.add(0,ale.toAction());
			}
			if (actions.size() > numActions)
				actions = actions.subList(0, numActions);
		}
		catch (IOException e) {
			logger.error("Failed to convert values to actions ",e);
		}
		finally
		{
		 if (jedis != null) {
			    jedis.close();
			  }
		}
	}
	else
	{
		logger.error("No redis pool found for "+clientName);
	}
	if (logger.isDebugEnabled())
		logger.debug("For user "+userId+" found "+actions.size()+" full actions");
	return actions;
}
 
Example 9
Source File: KarmaDB.java    From VileBot with MIT License 5 votes vote down vote up
public static long getTotalKarma()
{
    Jedis jedis = pool.getResource();
    long totalKarma;
    try
    {
        Set<String> members = jedis.zrange( keyOfKarmaSortedSet, 0, -1 );
        totalKarma = sum( members, jedis );
    }
    finally
    {
        pool.returnResource( jedis );
    }
    return totalKarma;
}
 
Example 10
Source File: ChurchDB.java    From VileBot with MIT License 5 votes vote down vote up
public static long getTotalDonations()
{
    Jedis jedis = pool.getResource();
    long totalKarma;
    try
    {
        Set<String> members = jedis.zrange( keyOfChurchDonorSortedSet, 0, -1 );
        totalKarma = sum( keyOfChurchDonorSortedSet, members, jedis );
    }
    finally
    {
        pool.returnResource( jedis );
    }
    return totalKarma;
}
 
Example 11
Source File: ChurchDB.java    From VileBot with MIT License 5 votes vote down vote up
public static long getTotalNonDonations()
{
    Jedis jedis = pool.getResource();
    long totalKarma;
    try
    {
        Set<String> members = jedis.zrange( keyOfChurchSortedSet, 0, -1 );
        totalKarma = sum( keyOfChurchSortedSet, members, jedis );
    }
    finally
    {
        pool.returnResource( jedis );
    }
    return totalKarma;
}
 
Example 12
Source File: DefaultRedis.java    From craft-atom with MIT License 4 votes vote down vote up
private Set<String> zrange0(Jedis j, String key, long start, long stop) {
	return j.zrange(key, start, stop);
}
 
Example 13
Source File: JedisUtil.java    From BigData with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 返回指定位置的集合元素,0为第一个元素,-1为最后一个元素
 * 
 * @param String
 *            key
 * @param int start 开始位置(包含)
 * @param int end 结束位置(包含)
 * @return Set<String>
 * */
public Set<String> zrange(String key, int start, int end) {
	// ShardedJedis sjedis = getShardedJedis();
	Jedis sjedis = getJedis();
	Set<String> set = sjedis.zrange(key, start, end);
	returnJedis(sjedis);
	return set;
}
 
Example 14
Source File: RedisBackendUtils.java    From pinlater with Apache License 2.0 2 votes vote down vote up
/**
 * Get all the queue names in the given shard. Note that it is the caller's responsibility to
 * close the connection after this method is called.
 *
 * @param conn Jedis connection for the given shard.
 * @param shardName The shard name for the given shard.
 * @return A set of strings, as all the queue names in that shard.
 */
public static Set<String> getQueueNames(Jedis conn, String shardName) {
  String queueNamesRedisKey = RedisBackendUtils.constructQueueNamesRedisKey(shardName);
  // TODO(jiacheng): Consider to do pagination if we get many queues on one shard.
  return conn.zrange(queueNamesRedisKey, 0, -1);
}