时间:2021-07-01 10:21:17 帮助过:19人阅读
测试类:
package com.haonan.jedis; import org.junit.Test; import redis.clients.jedis.Jedis; /** * @author haonan * @version 1.0 * @date 2020/4/6 16:23 */ public class JedisTest { @Test public void testjedis() { //1.连接redis Jedis jedis = new Jedis("localhost", 6379); //2.操作redis jedis.set("kagome", "inuyasha"); String kagome = jedis.get("kagome"); System.out.println(kagome); //3.关闭连接 jedis.close(); } }
小工具类:
配置文件jedis.properties
#fileName jedis.properties jedis.host=127.0.0.1 jedis.port=6379 jedis.maxTotal=30 jedis.maxIdle=10
工具类:
import java.util.ResourceBundle; /** * @author haonan * @version 1.0 * @date 2020/4/6 16:29 */ public class JedisUtils { private static JedisPool jp = null; static { //getBundle传入配置文件的名称,不用写后缀名称 ResourceBundle rb = ResourceBundle.getBundle("jedis"); JedisPoolConfig jpc = new JedisPoolConfig(); jpc.setMaxTotal(Integer.parseInt(rb.getString("jedis.maxTotal"))); jpc.setMaxIdle(Integer.parseInt(rb.getString("jedis.maxIdle"))); jp = new JedisPool(jpc, rb.getString("jedis.host"), Integer.parseInt(rb.getString("jedis.port"))); } public static Jedis getJedis() { return jp.getResource(); } }
db#redis#jedis
标签:配置文件 import str package 关闭 stat depend resource ack