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

The following examples show how to use redis.clients.jedis.Jedis#rpush() . 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: JedisUtil.java    From scaffold-cloud with MIT License 7 votes vote down vote up
/**
 * 设置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);
        }
        for (String v : value) {
            result += jedis.rpush(key, v);
        }
        if (cacheSeconds != 0) {
            jedis.expire(key, cacheSeconds);
        }
    } catch (Exception e) {
        logger.warn("setList {} = {}", key, value, e);
    } finally {
        close(jedis);
    }
    return result;
}
 
Example 2
Source File: RedisAppender.java    From jframework with Apache License 2.0 6 votes vote down vote up
@Override
protected void append(ILoggingEvent event) {
    Jedis client = pool.getResource();
    try {

        String json = layout == null ? jsonlayout.doLayout(event) : layout.doLayout(event);
        client.rpush(key, json);
    } catch (Exception e) {
        log.error("e message: {}", e.getMessage());
        pool.returnBrokenResource(client);
        client = null;
    } finally {
        if (client != null) {
            pool.returnResource(client);
        }
    }
}
 
Example 3
Source File: RedisContainer.java    From bahir-flink with Apache License 2.0 6 votes vote down vote up
@Override
public void rpush(final String listName, final String value) {
    Jedis jedis = null;
    try {
        jedis = getInstance();
        jedis.rpush(listName, value);
    } catch (Exception e) {
        if (LOG.isErrorEnabled()) {
            LOG.error("Cannot send Redis message with command RPUSH to list {} error message {}",
                listName, e.getMessage());
        }
        throw e;
    } finally {
        releaseInstance(jedis);
    }
}
 
Example 4
Source File: JedisUtils.java    From Shop-for-JavaWeb with MIT License 6 votes vote down vote up
/**
 * 向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;
}
 
Example 5
Source File: JedisUtils.java    From easyweb with Apache License 2.0 6 votes vote down vote up
/**
 * 向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;
}
 
Example 6
Source File: JedisUtils.java    From Shop-for-JavaWeb with MIT License 6 votes vote down vote up
/**
 * 设置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;
}
 
Example 7
Source File: RedisDataSet.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
private void addDataToConnection(Jedis conn, String key, String data) {
    try {
        if (redisDataType == RedisDataType.REDIS_DATA_TYPE_LIST) {
            log.debug("Executing rpush against redis list");
            // Add data string to list's tail
            conn.rpush(redisKey, data);
        } else if (redisDataType == RedisDataType.REDIS_DATA_TYPE_SET) {
            log.debug("Executing sadd against redis set");
            conn.sadd(key, data);
        } else {
            log.warn("Unexpected redis datatype: {0}".format(key));
        }
    } catch (JedisDataException jde) {
        log.error("Exception when adding data to Redis: " + jde);
    }
}
 
Example 8
Source File: JedisScoredQueueStore.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;
    }
    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;
}
 
Example 9
Source File: JedisUtil.java    From scaffold-cloud with MIT License 6 votes vote down vote up
/**
 * 向List缓存中添加值
 *
 * @param key   键
 * @param value 值
 * @return
 */
public static long listObjectAdd(String key, Object... value) {
    long result = 0;
    Jedis jedis = null;
    try {
        jedis = getResource();
        for (Object o : value) {
            result += jedis.rpush(getBytesKey(key), toBytes(o));
        }
    } catch (Exception e) {
        logger.warn("listObjectAdd {} = {}", key, value, e);
    } finally {
        close(jedis);
    }
    return result;
}
 
Example 10
Source File: OutputMatcher.java    From AIDR with GNU Affero General Public License v3.0 5 votes vote down vote up
private void pushToTaskWriteQueue(Document doc) {
      Jedis jedis = DataStore.getJedisConnection();
try {
	jedis.rpush(
			TaggerConfigurator
					.getInstance()
					.getProperty(
							TaggerConfigurationProperty.REDIS_LABEL_TASK_WRITE_QUEUE)
					.getBytes(), Serializer.serialize(doc));
} catch (IOException e) {
	logger.warn("Exception while serializing DocumentSet.");
}
DataStore.close(jedis);
  }
 
Example 11
Source File: AidrFetcherJsonInputProcessor.java    From AIDR with GNU Affero General Public License v3.0 5 votes vote down vote up
private void enqueue(Document doc) {
	Jedis jedis = DataStore.getJedisConnection();

	try {
		jedis.rpush(outputQueueName, Serializer.serialize(doc));
	} catch (IOException e) {
		logger.error("Error when serializing input document.", e);
	} finally {
		DataStore.close(jedis);
	}
}
 
Example 12
Source File: RedisServiceImpl.java    From blog_demos with Apache License 2.0 5 votes vote down vote up
@Override
public void listAppend(String key, String value) {
    Jedis jedis = borrowJedis();

    if(null!=jedis){
        jedis.rpush(key, value);
        returnJedis(jedis);
    }
}
 
Example 13
Source File: JedisUtils.java    From Shop-for-JavaWeb with MIT License 5 votes vote down vote up
/**
 * 向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;
}
 
Example 14
Source File: JedisUtil.java    From scaffold-cloud with MIT License 5 votes vote down vote up
/**
 * 向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);
    } catch (Exception e) {
        logger.warn("listAdd {} = {}", key, value, e);
    } finally {
        close(jedis);
    }
    return result;
}
 
Example 15
Source File: TestRedisSource.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private void initTestData() {
  TEST_VALUE.add("testValue1");
  TEST_VALUE.add("testValue2");
  TEST_VALUE.add("testValue3");
  TEST_VALUE.add("testValue4");
  TEST_VALUE.add("testValue5");

  Jedis redisClient = new Jedis(URI.create(String.format(REDIS_URI_TEMPLATE, redisPort)));

  redisClient.del(TEST_KEY);
  redisClient.rpush(TEST_KEY, TEST_VALUE.toArray(new String[TEST_VALUE.size()]));

  redisClient.close();
}
 
Example 16
Source File: JedisSegmentScoredQueueStore.java    From vscrawler with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 17
Source File: DefaultRedis.java    From craft-atom with MIT License 4 votes vote down vote up
private Long rpush0(Jedis j, String key, String... values) {
	return j.rpush(key, values);
}
 
Example 18
Source File: JedisUtil.java    From Project with Apache License 2.0 3 votes vote down vote up
/**
 * 向List头部追加记录
 * 
 * @param  key
 * @param  value
 * @return 记录总数
 */
public long rpush(byte[] key, byte[] value) {
	Jedis jedis = getJedis();
	long count = jedis.rpush(key, value);
	jedis.close();
	return count;
}
 
Example 19
Source File: JedisUtil.java    From Project with Apache License 2.0 3 votes vote down vote up
/**
 * 向List头部追加记录
 * 
 * @param  key
 * @param  value
 * @return 记录总数
 */
public long rpush(String key, String value) {
	Jedis jedis = getJedis();
	long count = jedis.rpush(key, value);
	jedis.close();
	return count;
}
 
Example 20
Source File: JedisUtil.java    From BigData with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 向List头部追加记录
 * 
 * @param String
 *            key
 * @param String
 *            value
 * @return 记录总数
 * */
public long rpush(String key, String value) {
	Jedis jedis = getJedis();
	long count = jedis.rpush(key, value);
	returnJedis(jedis);
	return count;
}