美文网首页
RedisTemplate入门程序

RedisTemplate入门程序

作者: 大雨滂沱在关外 | 来源:发表于2020-01-09 15:30 被阅读0次

RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();

        redisStandaloneConfiguration.setHostName("localhost");

        redisStandaloneConfiguration.setPort(6379);

        JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(redisStandaloneConfiguration);

        RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();

        redisTemplate.setConnectionFactory(jedisConnectionFactory);

        // 这行代码有点意思啊。

        redisTemplate.afterPropertiesSet();

        System.out.println(redisTemplate.keys("key1"));

        System.out.println(redisTemplate.hasKey("key"));

        System.out.println(redisTemplate.opsForValue().get("key"));

        redisTemplate.opsForValue().set("key","hahah");

        redisTemplate.delete("key");

        ArrayList<Object> objects = new ArrayList<>();

        objects.add("hhello owrld");

        redisTemplate.opsForList().leftPushAll("key",objects);

        redisTemplate.opsForList().leftPop("key",1000L, TimeUnit.NANOSECONDS );

        System.out.println(redisTemplate.opsForValue().get("key"));

        StringRedisTemplate stringRedisTemplate = new StringRedisTemplate();

        stringRedisTemplate.setConnectionFactory(jedisConnectionFactory);

        stringRedisTemplate.afterPropertiesSet();

        System.out.println(stringRedisTemplate.hasKey("key"));

相关文章

网友评论

      本文标题:RedisTemplate入门程序

      本文链接:https://www.haomeiwen.com/subject/hxyugctx.html