zoukankan      html  css  js  c++  java
  • spring redis

    @Test
        public void testSpringRedis() {
            ConfigurableApplicationContext ctx = null;
            try {
                ctx = new ClassPathXmlApplicationContext("spring.xml");
    
                StringRedisTemplate stringRedisTemplate = ctx.getBean("stringRedisTemplate", StringRedisTemplate.class);
    
                // String读写
                stringRedisTemplate.delete("myStr");
                stringRedisTemplate.opsForValue().set("myStr", "http://yjmyzz.cnblogs.com/");
                System.out.println(stringRedisTemplate.opsForValue().get("myStr"));
                System.out.println("---------------");
    
                // List读写
                stringRedisTemplate.delete("myList");
                stringRedisTemplate.opsForList().rightPush("myList", "A");
                stringRedisTemplate.opsForList().rightPush("myList", "B");
                stringRedisTemplate.opsForList().leftPush("myList", "0");
                List<String> listCache = stringRedisTemplate.opsForList().range(
                        "myList", 0, -1);
                for (String s : listCache) {
                    System.out.println(s);
                }
                System.out.println("---------------");
    
                // Set读写
                stringRedisTemplate.delete("mySet");
                stringRedisTemplate.opsForSet().add("mySet", "A");
                stringRedisTemplate.opsForSet().add("mySet", "B");
                stringRedisTemplate.opsForSet().add("mySet", "C");
                Set<String> setCache = stringRedisTemplate.opsForSet().members(
                        "mySet");
                for (String s : setCache) {
                    System.out.println(s);
                }
                System.out.println("---------------");
    
                // Hash读写
                stringRedisTemplate.delete("myHash");
                stringRedisTemplate.opsForHash().put("myHash", "PEK", "北京");
                stringRedisTemplate.opsForHash().put("myHash", "SHA", "上海虹桥");
                stringRedisTemplate.opsForHash().put("myHash", "PVG", "浦东");
                Map<Object, Object> hashCache = stringRedisTemplate.opsForHash()
                        .entries("myHash");
                for (Map.Entry<Object, Object> entry : hashCache.entrySet()) {
                    System.out.println(entry.getKey() + " - " + entry.getValue());
                }
    
                System.out.println("---------------");
    
            } finally {
                if (ctx != null && ctx.isActive()) {
                    ctx.close();
                }
            }
    
        }

     http://www.cnblogs.com/yjmyzz/p/4113019.html

  • 相关阅读:
    飞跃平野(sdut1124)
    背包
    sdut2193救基友记3(三维)
    hdu1542 Atlantis(矩阵面积的并)
    hdu1505City Game(扫描线)
    poj3468A Simple Problem with Integers(线段树的区域更新)
    hdu1166敌兵布阵&&hdu1754I Hate It(线段树入门)
    Biorhythms(中国剩余定理)
    Sequence(priority_queue)
    Message Flood(map)
  • 原文地址:https://www.cnblogs.com/jifeng/p/4678938.html
Copyright © 2011-2022 走看看