Spring RedisTemplate操作-通道操作(10)

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

    @Autowired
    @Resource(name = "redisTemplate")
    private RedisTemplate rt;

    public void flushdb() {
        rt.execute(new RedisCallback() {
            public String doInRedis(RedisConnection connection) throws DataAccessException {
                connection.flushDb();
                return "ok";
            }
        });
    }

    public void set() {
        flushdb();
        rt.opsForValue().set("a", "1");
        List results = rt.executePipelined(new RedisCallback() {
            public Object doInRedis(RedisConnection connection) throws DataAccessException {
                for (int i = 0; i < 10; i++) {
                    connection.incr("a".getBytes());
                }
                return null;
            }
        });
        System.out.println(rt.opsForValue().get("a"));
    }
 
   

转载于:https://my.oschina.net/haokevin/blog/1826429

你可能感兴趣的:(Spring RedisTemplate操作-通道操作(10))