java通过jedis连接
转自:http://blog.csdn.net/sjtu_chenchen/article/details/51308137
Redis客户端
Redis-cli最常用,而java程序代码可以通过jedis连接
Jedis客户端
maven中pom文件增加依赖
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
java测试代码如下:
public class JedisTest {
@Test
public void testJedisSingle() {
Jedis jedis = new Jedis("192.168.25.153", 6379);
jedis.set("key1", "jedis test");
String string = jedis.get("key1");
System.out.println(string);
jedis.close();
}
/**
* 使用连接池
*/
@Test
public void testJedisPool() {
JedisPool pool = new JedisPool("192.168.25.153", 6379);
Jedis jedis = pool.getResource();
String string = jedis.get("key1");
System.out.println(string);
jedis.close();
pool.close();
}
}