redis.clients.jedis.BinaryClient Java Examples

The following examples show how to use redis.clients.jedis.BinaryClient. 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: JedisUtils.java    From fw-spring-cloud with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * 通过key在list指定的位置之前或者之后 添加字符串元素
 * </p>
 *
 * @param key
 * @param where
 *            LIST_POSITION枚举类型
 * @param pivot
 *            list里面的value
 * @param value
 *            添加的value
 * @return
 */
public Long linsert(String key, BinaryClient.LIST_POSITION where, String pivot,
                    String value) {
    Jedis jedis = null;
    Long res = null;
    try {
        jedis = jedisPool.getResource();
        res = jedis.linsert(key, where, pivot, value);
    } catch (Exception e) {

        log.error(e.getMessage());
    } finally {
        returnResource(jedisPool, jedis);
    }
    return res;
}
 
Example #2
Source File: JedisScoredQueueStore.java    From vscrawler with Apache License 2.0 6 votes vote down vote up
@Override
public boolean addIndex(String queueID, long index, ResourceItem e) {
    if (!lockQueue(queueID)) {
        return false;
    }
    remove(queueID, e.getKey());
    Jedis jedis = jedisPool.getResource();
    try {
        String poolQueueKey = makePoolQueueKey(queueID);
        Long length = jedis.llen(poolQueueKey);
        if (index <= length) {
            index = length - 1;
        }
        String position = jedis.lindex(makePoolQueueKey(queueID), index);
        if (isNil(position)) {
            jedis.rpush(poolQueueKey, e.getKey());
        } else {
            jedis.linsert(poolQueueKey, BinaryClient.LIST_POSITION.AFTER, position, e.getKey());
        }
        jedis.hset(makeDataKey(queueID), e.getKey(), JSONObject.toJSONString(e));
    } finally {
        IOUtils.closeQuietly(jedis);
        unLockQueue(queueID);
    }
    return true;
}
 
Example #3
Source File: ClusterClient.java    From JRediSearch with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public List<Object> broadcast(String... args) {
    try (Jedis conn = _conn()) {
        BinaryClient client = conn.getClient();
        client.sendCommand(Commands.ClusterCommand.BROADCAST, args);
        return client.getObjectMultiBulkReply();
    }
}
 
Example #4
Source File: RedisList.java    From Voovan with Apache License 2.0 5 votes vote down vote up
@Override
public boolean addAll(int index, Collection<? extends V> c) {
    try (Jedis jedis = getJedis()) {
        byte[] pivot = jedis.lindex(name.getBytes(), index);
        for(V item : c){
            jedis.linsert(name.getBytes(), BinaryClient.LIST_POSITION.AFTER, pivot, TSerialize.serialize(item));
        }
    }

    return true;
}
 
Example #5
Source File: RedisList.java    From Voovan with Apache License 2.0 5 votes vote down vote up
@Override
public void add(int index, V element) {
    try (Jedis jedis = getJedis()) {
        byte[] pivot = jedis.lindex(name.getBytes(), index);
        jedis.linsert(name.getBytes(), BinaryClient.LIST_POSITION.AFTER, pivot, TSerialize.serialize(element));
    }
}
 
Example #6
Source File: JedisSegmentScoredQueueStore.java    From vscrawler with Apache License 2.0 4 votes vote down vote up
@Override
public boolean addIndex(String queueID, long index, ResourceItem e) {
    if (!lockQueue(queueID)) {
        return false;
    }
    @Cleanup Jedis jedis = jedisPool.getResource();
    try {
        remove(queueID, e.getKey());
        // block 从1开始计数
        int block = blockID(index + 1);
        List<String> sliceQueue = sliceQueue(queueID);
        String sliceID;
        if (block - 1 < sliceQueue.size()) {
            sliceID = sliceQueue.get(block - 1);
        } else {
            // create a new slice
            sliceID = String.valueOf(block);
            if (!sliceQueue.contains(sliceID)) {
                Preconditions.checkArgument(index <= size(queueID));
                jedis.rpush(makeSliceQueueKey(queueID), sliceID);
            } else {
                sliceID = sliceQueue.get(sliceQueue.size() - 1);
            }
        }
        String poolQueueKey = makePoolQueueKey(queueID, sliceID);
        Long length = jedis.llen(poolQueueKey);
        long offset = blockOffset(index);
        if (offset <= length) {
            offset = length - 1;
        }
        String position = jedis.lindex(makePoolQueueKey(queueID, sliceID), offset);
        if (isNil(position)) {
            jedis.rpush(poolQueueKey, e.getKey());
        } else {
            jedis.linsert(poolQueueKey, BinaryClient.LIST_POSITION.AFTER, position, e.getKey());
        }
        jedis.hset(makeDataKey(queueID), e.getKey(), JSONObject.toJSONString(e));
    } finally {
        unLockQueue(queueID);
    }
    return true;
}
 
Example #7
Source File: JedisUtil.java    From Project with Apache License 2.0 3 votes vote down vote up
/**
 * 在指定位置插入记录
 * 
 * @param    key
 * @param where 前面插入或后面插入
 * @param    pivot 相对位置的内容
 * @param     value 插入的内容
 * @return 记录总数
 */
public long linsert(byte[] key, BinaryClient.LIST_POSITION where, byte[] pivot, byte[] value) {
	Jedis jedis = getJedis();
	long count = jedis.linsert(key, where, pivot, value);
	jedis.close();
	return count;
}
 
Example #8
Source File: JedisUtil.java    From Project with Apache License 2.0 2 votes vote down vote up
/**
 * 在value的相对位置插入记录
 * 
 * @param key
 * @param where 前面插入或后面插入
 * @param      pivot 相对位置的内容
 * @param   value 插入的内容
 * @return 记录总数
 */
public long linsert(String key, BinaryClient.LIST_POSITION where, String pivot, String value) {
	return linsert(SafeEncoder.encode(key), where, SafeEncoder.encode(pivot), SafeEncoder.encode(value));
}
 
Example #9
Source File: RedisList.java    From MythRedisClient with Apache License 2.0 2 votes vote down vote up
/**
 * @param key list键
 * @param pivot 关键的元素,有重复就只看第一个
 * @param value 在关键元素之后插入
 * @return list长度
 */
public long insertAfter(String key, String pivot, String value) {
  return getJedis().linsert(key, BinaryClient.LIST_POSITION.AFTER, pivot, value);
}
 
Example #10
Source File: RedisList.java    From MythRedisClient with Apache License 2.0 2 votes vote down vote up
/**
 * @param key list键
 * @param pivot 关键的元素,只匹配到第一个
 * @param value 之前插入
 * @return list 长度
 */
public long insertBefore(String key, String pivot, String value) {
  return getJedis().linsert(key, BinaryClient.LIST_POSITION.BEFORE, pivot, value);
}