本文整理汇总了Java中redis.clients.jedis.Jedis.rpush方法的典型用法代码示例。如果您正苦于以下问题:Java Jedis.rpush方法的具体用法?Java Jedis.rpush怎么用?Java Jedis.rpush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redis.clients.jedis.Jedis
的用法示例。
在下文中一共展示了Jedis.rpush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例2: setList
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 设置List缓存
*
* @param key 键
* @param value 值
* @param cacheSeconds 超时时间,0为不超时
* @return
*/
public static long setList(String key, List<String> value, int cacheSeconds) {
long result = 0;
Jedis jedis = null;
try {
jedis = getResource();
if (jedis.exists(key)) {
jedis.del(key);
}
result = jedis.rpush(key, (String[]) value.toArray());
if (cacheSeconds != 0) {
jedis.expire(key, cacheSeconds);
}
logger.debug("setList {} = {}", key, value);
} catch (Exception e) {
logger.warn("setList {} = {}", key, value, e);
} finally {
returnResource(jedis);
}
return result;
}
示例3: setObjectList
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 设置List缓存
*
* @param key 键
* @param value 值
* @param cacheSeconds 超时时间,0为不超时
* @return
*/
public static long setObjectList(String key, List<Object> value, int cacheSeconds) {
long result = 0;
Jedis jedis = null;
try {
jedis = getResource();
if (jedis.exists(getBytesKey(key))) {
jedis.del(key);
}
List<byte[]> list = Lists.newArrayList();
for (Object o : value) {
list.add(toBytes(o));
}
result = jedis.rpush(getBytesKey(key), (byte[][]) list.toArray());
if (cacheSeconds != 0) {
jedis.expire(key, cacheSeconds);
}
logger.debug("setObjectList {} = {}", key, value);
} catch (Exception e) {
logger.warn("setObjectList {} = {}", key, value, e);
} finally {
returnResource(jedis);
}
return result;
}
示例4: listObjectAdd
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 向List缓存中添加值
*
* @param key 键
* @param value 值
* @return
*/
public static long listObjectAdd(String key, Object... value) {
long result = 0;
Jedis jedis = null;
try {
jedis = getResource();
List<byte[]> list = Lists.newArrayList();
for (Object o : value) {
list.add(toBytes(o));
}
result = jedis.rpush(getBytesKey(key), (byte[][]) list.toArray());
logger.debug("listObjectAdd {} = {}", key, value);
} catch (Exception e) {
logger.warn("listObjectAdd {} = {}", key, value, e);
} finally {
returnResource(jedis);
}
return result;
}
示例5: rPushString
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/** 返回的是列表的剩余个数 */
public long rPushString(String key, String value) {
Jedis jedis = null;
boolean success = true;
long ret = 0;
try {
jedis = jedisPool.getResource();
if (jedis == null) {
success = false;
return ret;
}
ret = jedis.rpush(key, value);
} catch (Exception e) {
success = false;
returnBrokenResource(jedis, "rpushString" + key, e);
} finally {
releaseReidsSource(success, jedis);
}
return ret;
}
示例6: rpush
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public long rpush(String key, String value) {
Jedis jedis = null;
boolean success = true;
long ret = -1;
try {
jedis = jedisPool.getResource();
if (jedis == null) {
success = false;
return ret;
}
ret = jedis.rpush(key, value);
} catch (Exception e) {
success = false;
returnBrokenResource(jedis, "rpush key:" + key + "value:" + value, e);
} finally {
releaseReidsSource(success, jedis);
}
return ret;
}
示例7: setVByList
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 往redis里存List
* @param listKey
* @param value
*/
public void setVByList(String listKey,Object value) throws Exception {
Jedis jds = null;
try {
jds = getJedis();
jds.select(0);
byte[] svalue = SerializeUtil.serialize(value);
jds.rpush(listKey.getBytes(), svalue);
} catch (Exception e) {
throw e;
} finally {
if(jds != null)
{
jds.close();
}
}
}
示例8: setList
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 设置List缓存
* @param key 键
* @param value 值
* @param cacheSeconds 超时时间,0为不超时
* @return
*/
public static long setList(String key, List<String> value, int cacheSeconds) {
long result = 0;
Jedis jedis = null;
try {
jedis = getResource();
if (jedis.exists(key)) {
jedis.del(key);
}
result = jedis.rpush(key, (String[])value.toArray());
if (cacheSeconds != 0) {
jedis.expire(key, cacheSeconds);
}
logger.debug("setList {} = {}", key, value);
} catch (Exception e) {
logger.warn("setList {} = {}", key, value, e);
} finally {
returnResource(jedis);
}
return result;
}
示例9: main
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
Bench<JedisPool> bench = new JedisBench() {
@Override
public void executeOperation(String data, JedisPool benchInstance, int threadNumber, int iteration,
MetricRegistry metrics) {
Jedis jedis = benchInstance.getResource();
Timer.Context time = metrics.timer("list").time();
String key = "list_" + threadNumber;
jedis.rpush(key, data);
time.stop();
jedis.close();
}
};
Benchmark benchmark = new Benchmark(bench);
benchmark.run(args);
}
示例10: push
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Override
public void push(Request request, ISpider spider) {
Jedis jedis = pool.getResource();
if (Const.HttpMethod.POST == request.getMethod()
|| !isDuplicate(request, spider)) {
log.debug("push to queue {}", request.getUrl());
try {
jedis.rpush(getQueueKey(spider), request.getUrl());
String field = DigestUtils.md5Hex(request.getUrl());
byte[] data=SerializationUtils.serialize(request);
jedis.hset((ITEM_PREFIX + spider.getName()).getBytes(), field.getBytes(), data);
} finally {
jedis.close();
}
}
}
示例11: addLast
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Override
public boolean addLast(String queueID, ResourceItem e) {
if (!lockQueue(queueID)) {
return false;
}
remove(queueID, e.getKey());
Jedis jedis = jedisPool.getResource();
try {
jedis.rpush(makePoolQueueKey(queueID), e.getKey());
jedis.hset(makeDataKey(queueID), e.getKey(), JSONObject.toJSONString(e));
} finally {
IOUtils.closeQuietly(jedis);
unLockQueue(queueID);
}
return true;
}
示例12: setSetObjectAdd
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 向Set缓存中添加值
* @param key 键
* @param value 值
* @return
*/
public static long setSetObjectAdd(String key, Object... value) {
long result = 0;
Jedis jedis = null;
try {
jedis = getResource();
Set<byte[]> set = Sets.newHashSet();
for (Object o : value){
set.add(toBytes(o));
}
result = jedis.rpush(getBytesKey(key), (byte[][])set.toArray());
logger.debug("setSetObjectAdd {} = {}", key, value);
} catch (Exception e) {
logger.warn("setSetObjectAdd {} = {}", key, value, e);
} finally {
returnResource(jedis);
}
return result;
}
示例13: 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);
}
}
示例14: listAdd
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 向List缓存中添加值
*
* @param key 键
* @param value 值
* @return
*/
public static long listAdd(String key, String... value) {
long result = 0;
Jedis jedis = null;
try {
jedis = getResource();
result = jedis.rpush(key, value);
logger.debug("listAdd {} = {}", key, value);
} catch (Exception e) {
logger.warn("listAdd {} = {}", key, value, e);
} finally {
returnResource(jedis);
}
return result;
}
示例15: pushWhenNoDuplicate
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Override
protected void pushWhenNoDuplicate(Request request) {
Jedis jedis = pool.getResource();
try {
jedis.rpush(getQueueKey(request.getSpiderName()), request.getUrl());
String field = DigestUtils.shaHex(request.getUrl());
String value = JSON.toJSONString(request);
jedis.hset((ITEM_PREFIX + request.getUrl()), field, value);
} finally {
jedis.close();
}
}