Spring RedisTemplate操作-List配置

Posted aoeiuv

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring RedisTemplate操作-List配置相关的知识,希望对你有一定的参考价值。

@Autowired
    @Resource(name="redisTemplate")
    private RedisTemplate<String, String> rt;
    
    public void flushdb(){
        rt.execute(new RedisCallback<Object>() {
            public String doInRedis(RedisConnection connection) throws DataAccessException {
                connection.flushDb();
                return "ok";
            }
        });
    }
    
    public void set(){
        flushdb();
        ListOperations<String, String> vo = rt.opsForList();
        vo.leftPush("book", "wzg");
        vo.leftPushAll("book", "cff","cl","mc");
        vo.leftPush("book", "cl", "||");
        vo.rightPush("book", "yw");
        vo.rightPushAll("book", "sj","jy");
        vo.rightPush( "book", "sj", "||");
        vo.leftPop("book");
        vo.rightPop("book");
        vo.rightPopAndLeftPush("book", "bag");
        vo.set("book", 0, "gzf");
        vo.leftPush("bag", "||");
        vo.remove("bag", 3, "||");
    }
    
    public void get(){
        ListOperations<String, String> vo = rt.opsForList();
        out(vo.range("book", 0, -1));
        vo.trim("book", 2, 3);
        out(vo.range("book", 0, -1));
        out(vo.size("book"));
        out(vo.range("bag", 0, -1));
        out(vo.index("book", 1));
        
    }
    
    public void out(String str){
        System.out.println(str);
    }
    public void out(Collection list){
        System.out.println(list);
    }
    public void out(long num){
        System.out.println(num);
    }
    public void out(boolean num){
        System.out.println(num);
    }
    public void out(DataType num){
        System.out.println(num);
    }

 

以上是关于Spring RedisTemplate操作-List配置的主要内容,如果未能解决你的问题,请参考以下文章

Spring RedisTemplate操作-String操作

Spring RedisTemplate操作-ZSet操作

Spring RedisTemplate操作-HyperLogLog操作

Spring RedisTemplate操作-Set操作

spring 的redis操作类RedisTemplate

Spring RedisTemplate操作-发布订阅操作