初识Jedis

  1. 创建maven项目

  2. 导入依赖

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    <dependencies>
    <!--jedis-->
    <dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
    <version>4.1.1</version>
    </dependency>
    <!--单元测试-->
    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>5.7</version>
    <scope>test</scope>
    </dependency>
    <dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter</artifactId>
    <version>RELEASE</version>
    <scope>test</scope>
    </dependency>
    </dependencies>
  3. 测试

    使用测试单元测试

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    public class JedisTest {
    private Jedis jedis;

    @BeforeEach
    void setUp(){
    jedis = JedisPoolTest.getJedis();
    jedis.auth("000415");
    jedis.select(0);
    }

    @Test
    void testString(){
    HashMap<String,String> map = new HashMap<>();
    map.put("name","lihua");
    map.put("age","13");
    jedis.hmset("doc:1",map);
    System.out.println(jedis.hgetAll("doc:1"));
    }

    @AfterEach
    void tearDown(){
    if(jedis != null){
    jedis.close();
    }
    }


    }