码迷,mamicode.com
首页 > 其他好文 > 详细

Redis入门

时间:2017-10-24 22:36:38      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:main   测试   org   exception   trace   name   final   test   连接   

package com.nanrenld.jedis;

import org.junit.Test;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
* Jedis测试
* @author Administrator
*
*/
public class JedisDemo1 {

public static void main(String[] args) throws Exception{
//1.设置IP地址和端口
Jedis jedis = new Jedis("192.168.4.7",6379);
jedis.set("name", "nanrenld");
String value = jedis.get("name");
System.out.println(value);
jedis.close();
JedisDemo1 demo = new JedisDemo1();
demo.demo2();
}
public void demo2(){
//获取链接池的配置对象
JedisPoolConfig config = new JedisPoolConfig();

//获得最大连接数
config.setMaxTotal(30); 

//获取最大空闲连接数
config.setMaxIdle(10);
//获取链接池
JedisPool jedisPool = new JedisPool(config,"192.168.4.7",6379);
//获取核心对象
Jedis jedis = null;
try{
jedis = jedisPool.getResource();
jedis.set("name","张珊");
String value = jedis.get("name");
System.out.println(value);
}catch(Exception e){
e.printStackTrace();
}finally{
if(jedis != null){
jedis.close();
}
if(jedisPool != null){
jedisPool.close();
}
}

}
}

Redis入门

标签:main   测试   org   exception   trace   name   final   test   连接   

原文地址:http://www.cnblogs.com/gylhaut/p/7725781.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!