zoukankan      html  css  js  c++  java
  • redis入门案例

    1.引入jar包

    <!-- jedis -->
            <dependency>
                <groupId>redis.clients</groupId>
                <artifactId>jedis</artifactId>
                <version>${jedis.version}</version>
            </dependency>
    
            <!--添加spring-datajar包  -->
            <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-redis</artifactId>
                <version>1.4.1.RELEASE</version>
            </dependency>

    2.String类型测试

    //测试字符串 IP:6379
        @Test
        public void testString(){
            Jedis jedis = new Jedis("192.168.126.166",6379);
            jedis.set("aa","1807班");
            System.out.println(jedis.get("aa"));
        }

    3.hash类型数据测试

    //测试hash数据存储
        @Test
        public void testHash(){
            Jedis jedis = new Jedis("192.168.126.166",6379);
            jedis.hset("dog", "id", "100");
            jedis.hset("dog", "name", "中华田园犬");
            jedis.hset("dog", "age", "88");
            System.out.println(jedis.hget("dog", "name"));
            System.out.println(jedis.hgetAll("dog"));
            
        }

    4.List类型测试

    //测试List集合
        @Test
        public void testList(){
            Jedis jedis = new Jedis("192.168.126.166",6379);
            jedis.lpush("idList", "1","2","3");
            System.out.println(jedis.lpop("idList"));
        }

    5.事务控制

    //redis中事务控制
        @Test
        public void testTx(){
            Jedis jedis = new Jedis("192.168.126.166",6379);
            Transaction transaction = jedis.multi();    //开启事务.
            transaction.set("aa", "aaa");
            transaction.set("bb", "bbb");
            transaction.exec();    //事务提交
            System.out.println("执行成功!!!");
            //transaction.discard();    //事务回滚
        }
  • 相关阅读:
    ZOJ3329(数学推导+期望递推)
    洛谷5020(完全背包)
    洛谷1537(bitset+01背包)
    洛谷1052(路径压缩后简单dp)
    使用通配符配置action
    使用通配符配置action
    struts2.Action中的method属性配置
    struts2.Action中的method属性配置
    开启struts2自带的开发模式常量
    开启struts2自带的开发模式常量
  • 原文地址:https://www.cnblogs.com/gxlaqj/p/11588201.html
Copyright © 2011-2022 走看看