Redis中插入队列

从右侧插入队列(插入string)

    public int lSet(String key, String value) {
        try {
            redisTemplate.opsForList().rightPush(key, value);
            return 1;
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

从右侧插入队列(插入list)

public int llSetAll(String key, List<V> values) {
        try {
            if(CollectionUtils.isEmpty(values)){
                return 0;
            }
                redisTemplate.opsForList().rightPushAll(key,values );
            }
            return values.size();
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

从左侧获取队列

public Object leftPop(String key) {
        try {
            return redisTemplate.opsForList().leftPop(key);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
发布了103 篇原创文章 · 获赞 40 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/chenguanghan123/article/details/100064890