Get Set value from Redis using RedisTemplate

前端 未结 2 475
执笔经年
执笔经年 2021-01-31 20:42

I am able to retrieve values from Redis using Jedis:

public static void main(String[] args) {
        Jedis jedis = new Jedis(HOST, POR         


        
2条回答
  •  灰色年华
    2021-01-31 21:17

    You could do it much easier with Redisson:

    public static void main(String[] args) {
        Config conf = new Config();
        conf.useSingleServer().setAddress(host + ":" + port);
    
        RedissonClient redisson = Redisson.create(conf);
        RSet set = redisson.getSet(KEY)
        for (String s : set.readAllValues()) {
            System.out.println(s);
        }
        redisson.shutdown();
    }
    

    This framewrok handles serialization and work with connection so you don't need to deal with it each time. Work with Redis as you used to work with Java objects (Set, Map, List ...). It supports many popular codecs too.

提交回复
热议问题