本文整理匯總了Java中redis.clients.jedis.Jedis.lpop方法的典型用法代碼示例。如果您正苦於以下問題:Java Jedis.lpop方法的具體用法?Java Jedis.lpop怎麽用?Java Jedis.lpop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類redis.clients.jedis.Jedis
的用法示例。
在下文中一共展示了Jedis.lpop方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doPoll
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public Request doPoll(Task task) {
Jedis jedis = jedisPool.getResource();
try {
String content = null;
Set<String> contents = jedis.zrevrange(RedisKeys.getZsetPlusPriorityKey(task), 0, 0);
if (contents != null && !contents.isEmpty()) {
content = contents.toArray(new String[0])[0];
jedis.zrem(RedisKeys.getZsetPlusPriorityKey(task), content);
} else {
content = jedis.lpop(RedisKeys.getQueueNoPriorityKey(task));
if (StringUtils.isBlank(content)) {
contents = jedis.zrevrange(RedisKeys.getZsetMinusPriorityKey(task), 0, 0);
if (contents != null && !contents.isEmpty()) {
content = contents.toArray(new String[0])[0];
jedis.zrem(RedisKeys.getZsetPlusPriorityKey(task), content);
}
}
}
return StringUtils.isNotBlank(content) ? serializer.deserialize(content) : null;
} finally {
jedis.close();
}
}
示例2: lpop
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public String lpop(String key) {
Jedis jedis = null;
boolean success = true;
String ret = null;
try {
jedis = jedisPool.getResource();
if (jedis == null) {
success = false;
return ret;
}
ret = jedis.lpop(key);
} catch (Exception e) {
success = false;
returnBrokenResource(jedis, "lpop key:" + key, e);
} finally {
releaseReidsSource(success, jedis);
}
return ret;
}
示例3: poll
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public synchronized Request poll(String spiderName) {
Jedis jedis = pool.getResource();
try {
String url = jedis.lpop(getQueueKey(spiderName));
if (url == null) {
return null;
}
String key = ITEM_PREFIX + url;
String field = DigestUtils.shaHex(url);
byte[] bytes = jedis.hget(key.getBytes(), field.getBytes());
if (bytes != null) {
Request o = JSON.parseObject(new String(bytes), Request.class);
return o;
}
Request request = new Request(url);
return request;
} finally {
pool.returnResource(jedis);
}
}
示例4: jedistest
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@GET
@Path("jedistest")
@Produces(MediaType.TEXT_HTML + ";charset=utf-8")
public String jedistest() {
System.out.println("TEST Jedis ======================================================");
Jedis jedis = new Jedis("localhost", 6379);
jedis.set("foo", "bar");
jedis.get("foo");
jedis.lpush("lll", "a");
jedis.lpush("lll", "b");
jedis.lpush("lll", "c");
jedis.lpop("lll");
jedis.lpop("lll");
jedis.lpop("lll");
jedis.hset("mmm", "abc", "123");
jedis.hset("mmm", "def", "456");
jedis.hgetAll("mmm");
jedis.close();
return "jedistest";
}
示例5: foo
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
private static void foo() {
System.out.println("TEST Jedis ======================================================");
Jedis jedis = new Jedis(ip, port);
jedis.set("foo", "bar");
jedis.get("foo");
jedis.lpush("lll", "a");
jedis.lpush("lll", "b");
jedis.lpush("lll", "c");
jedis.lpop("lll");
jedis.lpop("lll");
jedis.lpop("lll");
jedis.hset("mmm", "abc", "123");
jedis.hset("mmm", "def", "456");
jedis.hgetAll("mmm");
jedis.close();
}
示例6: poll
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public ResourceItem poll(String queueID) {
if (!lockQueue(queueID)) {
return null;
}
Jedis jedis = jedisPool.getResource();
try {
String firstResourceKey = jedis.lpop(makePoolQueueKey(queueID));
if (isNil(firstResourceKey)) {
return null;
}
String dataJson = jedis.hget(makeDataKey(queueID), firstResourceKey);
if (isNil(dataJson)) {
throw new IllegalStateException("this is no meta data for key queue :" + queueID + " ,for resourceKey :" + firstResourceKey);
}
jedis.hdel(makeDataKey(queueID), firstResourceKey);
return JSONObject.toJavaObject(JSON.parseObject(dataJson), ResourceItem.class);
} finally {
IOUtils.closeQuietly(jedis);
unLockQueue(queueID);
}
}
示例7: addFirst
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public boolean addFirst(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.lpop(makeSliceQueueKey(queueID));
if (isNil(sliceID)) {
sliceID = "1";
}
jedis.lpush(makeSliceQueueKey(queueID), sliceID);
jedis.lpush(makePoolQueueKey(queueID, sliceID), e.getKey());
} finally {
unLockQueue(queueID);
}
return true;
}
示例8: poll
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public synchronized Request poll(ISpider spider) {
Jedis jedis = pool.getResource();
try {
String url = jedis.lpop(getQueueKey(spider));
if (url == null) {
return null;
}
String key = ITEM_PREFIX + spider.getName();
String field = DigestUtils.md5Hex(url);
byte[] bytes = jedis.hget(key.getBytes(), field.getBytes());
Request request=SerializationUtils.deserialize(bytes);
return request;
} finally {
jedis.close();
}
}
示例9: jedispolltest
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@GET
@Path("jedispooltest")
@Produces(MediaType.TEXT_HTML + ";charset=utf-8")
public String jedispolltest() {
System.out.println("TEST JedisPool ======================================================");
JedisPoolConfig cfg = new JedisPoolConfig();
cfg.setMaxTotal(5);
cfg.setMaxIdle(1);
cfg.setMaxWaitMillis(10000L);
JedisPool jp = new JedisPool(cfg, "localhost", 6379);
Jedis jedis = jp.getResource();
jedis.set("foo", "bar");
// jedis.close();
jedis = jp.getResource();
jedis.get("foo");
// jedis.close();
jedis = jp.getResource();
jedis.lpush("lll", "a");
jedis.lpush("lll", "b");
jedis.lpush("lll", "c");
jedis.lpop("lll");
jedis.lpop("lll");
jedis.lpop("lll");
// jedis.close();
jedis = jp.getResource();
jedis.hset("mmm", "abc", "123");
jedis.hset("mmm", "def", "456");
jedis.hgetAll("mmm");
jp.close();
return "jedispooltest";
}
示例10: poll
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
* poll種子
*
* @return UrlSeed
*/
@Override
public UrlSeed poll() {
Gson gson = new Gson();
Jedis jedis = null;
String urlSeedJson = null;
try {
jedis = jedisPool.getResource();
//依次取三個隊列,優先級高的被先取!
urlSeedJson = jedis.lpop(Prefix_Queue_high);
if (urlSeedJson != null) {
return gson.fromJson(urlSeedJson, UrlSeed.class);
}
urlSeedJson = jedis.lpop(Prefix_Queue_default);
if (urlSeedJson != null) {
return gson.fromJson(urlSeedJson, UrlSeed.class);
}
urlSeedJson = jedis.lpop(Prefix_Queue_low);
if (urlSeedJson != null) {
return gson.fromJson(urlSeedJson, UrlSeed.class);
}
} catch (Exception e) {
logger.warn("連接獲取失敗!", e);
} finally {
if (null != jedis) {
jedis.close();
}
}
return null;
}
示例11: lpop
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
synchronized public String lpop(String key) {
Jedis jedis = null;
String res = null;
try {
jedis = pool.getResource();
res = jedis.lpop(key);
} catch (Exception e) {
LOGGER.error(e.getMessage());
} finally {
returnResource(pool, jedis);
}
return res;
}
示例12: foo2
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
private static void foo2() {
System.out.println("TEST JedisPool ======================================================");
JedisPoolConfig cfg = new JedisPoolConfig();
cfg.setMaxTotal(5);
cfg.setMaxIdle(1);
cfg.setMaxWaitMillis(10000L);
JedisPool jp = new JedisPool(cfg, ip, port);
Jedis jedis = jp.getResource();
jedis.set("foo", "bar");
// jedis.close();
jedis = jp.getResource();
jedis.get("foo");
// jedis.close();
jedis = jp.getResource();
jedis.lpush("lll", "a");
jedis.lpush("lll", "b");
jedis.lpush("lll", "c");
jedis.lpop("lll");
jedis.lpop("lll");
jedis.lpop("lll");
// jedis.close();
jedis = jp.getResource();
jedis.hset("mmm", "abc", "123");
jedis.hset("mmm", "def", "456");
jedis.hgetAll("mmm");
jp.close();
}
示例13: testJedis
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@POST
@Path("testJedis")
public void testJedis(String jsonString) {
@SuppressWarnings("resource")
Jedis jedis = new Jedis("localhost", 6379);
jedis.set("foo", "bar");
jedis.get("foo");
jedis.lpush("lll", "a");
jedis.lpush("lll", "b");
jedis.lpush("lll", "c");
jedis.lpop("lll");
jedis.lpop("lll");
jedis.lpop("lll");
jedis.hset("mmm", "abc", "123");
jedis.hset("mmm", "def", "456");
jedis.hgetAll("mmm");
jedis.close();
JedisPoolConfig cfg = new JedisPoolConfig();
cfg.setMaxTotal(5);
cfg.setMaxIdle(1);
cfg.setMaxWaitMillis(10000L);
JedisPool jp = new JedisPool(cfg, "localhost", 6379);
jedis = jp.getResource();
jedis.set("foo", "bar");
// jedis.close();
jedis = jp.getResource();
jedis.get("foo");
// jedis.close();
jedis = jp.getResource();
jedis.lpush("lll", "a");
jedis.lpush("lll", "b");
jedis.lpush("lll", "c");
jedis.lpop("lll");
jedis.lpop("lll");
jedis.lpop("lll");
// jedis.close();
jedis = jp.getResource();
jedis.hset("mmm", "abc", "123");
jedis.hset("mmm", "def", "456");
jedis.hgetAll("mmm");
jp.close();
}
示例14: poll
import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public ResourceItem poll(String queueID) {
if (!lockQueue(queueID)) {
return null;
}
@Cleanup Jedis jedis = jedisPool.getResource();
try {
String sliceQueueKey = makeSliceQueueKey(queueID);
String firstResourceKey;
String firstSliceID = null;
while (true) {
String sliceID = jedis.lpop(sliceQueueKey);
if (isNil(sliceID)) {
// empty queue
return null;
}
if (firstSliceID == null) {
firstSliceID = sliceID;
} else if (firstSliceID.equals(sliceID)) {
// 這個條件下,數據紊亂了?
jedis.lpush(sliceQueueKey, firstSliceID);
return null;
}
firstResourceKey = jedis.lpop(makePoolQueueKey(queueID, sliceID));
if (!isNil(firstResourceKey)) {
jedis.lpush(sliceQueueKey, sliceID);
break;
}
jedis.rpush(sliceQueueKey, sliceID);
}
String dataJson = jedis.hget(makeDataKey(queueID), firstResourceKey);
if (isNil(dataJson)) {
throw new IllegalStateException(
"this is no meta data for key queue :" + queueID + " ,for resourceKey :" + firstResourceKey);
}
jedis.hdel(makeDataKey(queueID), firstResourceKey);
return JSONObject.toJavaObject(JSON.parseObject(dataJson), ResourceItem.class);
} finally {
unLockQueue(queueID);
}
}