SpringMVC 连接Redis数据库

来源:互联网 发布:万花尺软件 编辑:程序博客网 时间:2024/06/05 09:30

1、pom.xml

<!-- redis --><dependency>        <groupId>redis.clients</groupId>        <artifactId>jedis</artifactId>      <scope>compile</scope>      </dependency>

2、测试类

/** *  */package cn.bizbook.resource.manage.dao.impl;import static org.junit.Assert.*;import org.junit.Test;import redis.clients.jedis.Jedis;/** * @author jiangxingqi * */public class RedisTest {@Testpublic void test() {String key = "rs_test";Jedis jedis = null;try {jedis = new Jedis("host", 6379);System.out.println(jedis.get(key));System.out.println(jedis.type(key));System.out.println("key:" + key + ", tyep:" + jedis.type(key) + "; value:" + jedis.get(key));jedis.del(key); //del} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {if (jedis != null) {jedis.close();}}}}


0 0