博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
redis简单的操作
阅读量:7218 次
发布时间:2019-06-29

本文共 1660 字,大约阅读时间需要 5 分钟。

常用数据结构 redis简单操作

public class Test1 {	@Test	public void test() {		Jedis jedis = new Jedis("192.168.1.96");		String zml = jedis.get("zml");		System.out.println(zml);		if(zml==null){			jedis.set("zml", "zhumeilu");		}		System.out.println(jedis.get("zml"));	}}复制代码

redis池化

配置文件 #最大分配的对象数

redis.pool.maxActive=1024 #最大能够保持idel状态的对象数
redis.pool.maxIdle=200 #当池内没有返回对象时,最大等待时间
redis.pool.maxWait=1000 #当调用borrow Object方法时,是否进行有效性检查
redis.pool.testOnBorrow=true #当调用return Object方法时,是否进行有效性检查
redis.pool.testOnReturn=true #IP
redis.ip=192.168.1.96 #Port
redis.port=6379 创建一个redis池工具类

public class RedisClient {		private static JedisPool pool;		static{		ResourceBundle bundle = ResourceBundle.getBundle("redis");		if(bundle==null){			throw new RuntimeException("reids.propertis为空");		}		System.out.println(bundle);		JedisPoolConfig config = new JedisPoolConfig();		config.setMaxActive(Integer.valueOf(bundle.getString("redis.pool.maxActive")));		config.setMaxIdle(Integer.valueOf(bundle.getString("redis.pool.maxIdle")));		config.setMaxWait(Integer.valueOf(bundle.getString("redis.pool.maxWait")));		config.setTestOnBorrow(Boolean.valueOf(bundle.getString("redis.pool.testOnBorrow")));		config.setTestOnBorrow(Boolean.valueOf(bundle.getString("redis.pool.testOnReturn")));		pool = new JedisPool(config, bundle.getString("redis.ip"));			}		public static JedisPool getPool() {		return pool;	}	}复制代码

通过JedisPool获取jedis实例

public class TestPool {	@Test	public void test() {		JedisPool pool = RedisClient.getPool();		Jedis jedis = pool.getResource();		System.out.println(jedis);		String zml = jedis.get("zml");				System.out.println(zml);		pool.returnResource(jedis);	}}复制代码

转载地址:http://spxym.baihongyu.com/

你可能感兴趣的文章
MySQL 用户连接与用户线程
查看>>
RabbitMq、ActiveMq、Kafka和Redis做Mq对比
查看>>
C# 图片处理(压缩、剪裁,转换,优化)
查看>>
Linux bridge-utils tunctl 使用
查看>>
Leetcode Pascal's Triangle II
查看>>
运行shell脚本报错 '\357\273\277': command not found 解决的方法
查看>>
android studio 0.8.1使用和遇到问题解决
查看>>
云服务器ECS选购集锦之六区域选择帮助
查看>>
云虚机选购指南之二云虚拟主机试用帮助文档
查看>>
女友眼中的IT男
查看>>
Excel连接
查看>>
java基础-多线程学习
查看>>
WPF打印原理,自定义打印
查看>>
HTML5 5
查看>>
箭头css
查看>>
Python入门,以及简单爬取网页文本内容
查看>>
顺丰科技笔试回忆
查看>>
excel技巧
查看>>
通用防SQL注入漏洞程序(Global.asax方式)
查看>>
服务器进程为何通常fork()两次
查看>>