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

The following examples show how to use redis.clients.jedis.Jedis#rpop() . 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: SingleRedis.java    From ns4_frame with Apache License 2.0 6 votes vote down vote up
@Override
public byte[] rpop(String queueName) throws MQRedisException {
    Jedis jedis = this.jedisPool.getResource();
    byte[] result = null;
    try {
        result = jedis.rpop(SafeEncoder.encode(queueName));
    } catch (Exception e) {
        commandLog.error("mq rpop error", e);
        throw new MQRedisException(e);
    } finally {
        if (jedis != null) {
            jedis.close();
        }
    }
    return result;
}
 
Example 2
Source File: JedisUtils.java    From fw-spring-cloud with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * 通过key从list尾部删除一个value,并返回该元素
 * </p>
 *
 * @param key
 * @return
 */
synchronized public String rpop(String key, int indexdb) {
    Jedis jedis = null;
    String res = null;
    try {
        jedis = jedisPool.getResource();
        jedis.select(indexdb);
        res = jedis.rpop(key);
    } catch (Exception e) {

        log.error(e.getMessage());
    } finally {
        returnResource(jedisPool, jedis);
    }
    return res;
}
 
Example 3
Source File: JedisUtil.java    From newblog with Apache License 2.0 6 votes vote down vote up
public String rpop(String key) {
    Jedis jedis = null;
    try {
        jedis = getJedis();
        if (jedis == null) {
            logger.error("get jedis failed.");
            return null;
        }
        return jedis.rpop(key);
    } catch (JedisConnectionException e) {
        if (jedis != null) {
            jedis.close();
            jedis = null;
        }
        logger.error("increame connect error:", e);
    } finally {
        returnJedisResource(jedis);
    }
    return null;
}
 
Example 4
Source File: JedisSegmentScoredQueueStore.java    From vscrawler with Apache License 2.0 6 votes vote down vote up
@Override
public boolean addLast(String queueID, ResourceItem e) {
    if (!lockQueue(queueID)) {
        return false;
    }
    @Cleanup Jedis jedis = jedisPool.getResource();
    try {
        remove(queueID, e.getKey());
        jedis.hset(makeDataKey(queueID), e.getKey(), JSONObject.toJSONString(e));
        String sliceID = jedis.rpop(makeSliceQueueKey(queueID));
        if (isNil(sliceID)) {
            sliceID = "1";
        }
        jedis.rpush(makeSliceQueueKey(queueID), sliceID);
        jedis.rpush(makePoolQueueKey(queueID, sliceID), e.getKey());
    } finally {
        unLockQueue(queueID);
    }
    return true;
}
 
Example 5
Source File: RedisLockCoordinator.java    From jeesuite-libs with Apache License 2.0 6 votes vote down vote up
public void notifyNext(Jedis pubClient,String lockName){
	long currentTimeMillis = System.currentTimeMillis();
	
	String nextEventId;
	while(true){
		nextEventId = pubClient.rpop(lockName);
		if(StringUtils.isBlank(nextEventId)){
			return;
		}
		if(activeNodeIds.contains(nextEventId.substring(0,8)) 
				&& currentTimeMillis - Long.parseLong(nextEventId.substring(8,21)) < CLEAN_TIME){
			break;
		}
	}
	pubClient.publish(channelName, lockName + SPLIT_STR + nextEventId);
}
 
Example 6
Source File: RedisClient.java    From apollo with GNU General Public License v2.0 6 votes vote down vote up
public Object rpop(String key, Class<?> cls) throws Exception {
    byte[] data = null;
    Jedis jedis = null;
    try {
        jedis = this.jedisPool.getResource();
        // long begin = System.currentTimeMillis();
        data = jedis.rpop(SafeEncoder.encode(key));
        // long end = System.currentTimeMillis();
        // LOG.info("getValueFromCache spends: " + (end - begin) + " millionseconds.");
    } catch (Exception e) {
        // do jedis.quit() and jedis.disconnect()
        this.jedisPool.returnBrokenResource(jedis);
        throw e;
    } finally {
        if (jedis != null) {
            this.jedisPool.returnResource(jedis);
        }
    }

    return this.jsonDeserialize(data, cls);
}
 
Example 7
Source File: JedisUtil.java    From Project with Apache License 2.0 5 votes vote down vote up
/**
 * 将List中最后第一条记录移出List
 * 
 * @param  key
 * @return 移出的记录
 */
public String rpop(String key) {
	Jedis jedis = getJedis();
	String value = jedis.rpop(key);
	jedis.close();
	return value;
}
 
Example 8
Source File: RedisServiceImpl.java    From ace-cache with Apache License 2.0 5 votes vote down vote up
@Override
synchronized public String rpop(String key) {
    Jedis jedis = null;
    String res = null;
    try {
        jedis = pool.getResource();
        res = jedis.rpop(key);
    } catch (Exception e) {

        LOGGER.error(e.getMessage());
    } finally {
        returnResource(pool, jedis);
    }
    return res;
}
 
Example 9
Source File: JedisUtil.java    From BigData with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 将List中最后第一条记录移出List
 * 
 * @param byte[] key
 * @return 移出的记录
 * */
public String rpop(String key) {
	Jedis jedis = getJedis();
	String value = jedis.rpop(key);
	returnJedis(jedis);
	return value;
}
 
Example 10
Source File: RedisResourceIT.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Test
public void testResourceCanSendAndRecieve() throws ResourceInitializationException {

  SharedRedisResource resource = new SharedRedisResource();
  final CustomResourceSpecifier_impl resourceSpecifier = new CustomResourceSpecifier_impl();
  final Parameter[] configParams =
      new Parameter[] {
        new Parameter_impl(SharedRedisResource.PARAM_HOST, redis.getContainerIpAddress()),
        new Parameter_impl(
            SharedRedisResource.PARAM_PORT, Integer.toString(redis.getMappedPort(REDIS_PORT)))
      };
  resourceSpecifier.setParameters(configParams);
  final Map<String, Object> config = Maps.newHashMap();
  resource.initialize(resourceSpecifier, config);

  Jedis jedis = resource.getJedis();
  String key = "key";
  String value = "value";
  jedis.lpush(key, new String[] {value});
  String result = jedis.rpop(key);
  assertEquals(value, result);

  jedis.lpush(key, new String[] {value});
  List<String> bresult = jedis.brpop(new String[] {key, "0"});
  assertEquals(key, bresult.get(0));
  assertEquals(value, bresult.get(1));
}
 
Example 11
Source File: Spider.java    From BigData with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 启动爬虫
 */
public static void start() {
	final Spider spider = new Spider();
	spider.setDownLoadInter(new DownLoadImpl());
	spider.setProcessInter(new ProcessImpl());
	spider.setStoreIn(new StoreImpl());
	System.out.println("请输入一个要爬取的知乎话题:");
	// 获取话题
	@SuppressWarnings("resource")
	Scanner scanner = new Scanner(System.in);
	String topic = scanner.nextLine();// 话题
	String url = "https://www.zhihu.com/search?type=topic&q=" + topic;
	logger.info("爬虫开始运行...");
	// 下载话题精华问题页
	final Page page = spider.download(url);
	// 解析话题精华问题页
	spider.process(page);

	while (true) {
		// 读取Redis中的url
		Jedis jedis = JedisUtil.getJedis();
		final String userUrl = jedis.rpop(JedisUtil.urlkey);
		JedisUtil.returnResource(jedis);
		if (userUrl != null) {
			threadPool.execute(new Runnable() {
				public void run() {
					if (userUrl.endsWith("following") || userUrl.endsWith("follower")) {
						UserUtil.processFollow(userUrl);
					} else {
						User user = UserUtil.processUser(userUrl);
						if (user != null) {
							spider.store(user);// 存储
						}else{
							logger.info("很奇怪,user为null");
						}
					}
				}// end run
			});

		} else {
			logger.info("没有url了,休息一会...");
			ThreadUtil.sleep(5);
		} // end if else

	} // end while

}
 
Example 12
Source File: AbstractRedisClient.java    From slime with MIT License 4 votes vote down vote up
protected static String RPOP(String key, Jedis jedis) throws Exception {
	String str = jedis.rpop(key);
	return str;
}
 
Example 13
Source File: DefaultRedis.java    From craft-atom with MIT License 4 votes vote down vote up
private String rpop0(Jedis j, String key) {
	return j.rpop(key);
}