首页>代码>基于mysql binlog的redis/elasticsearch数据同步中间件>/com/rumtel/dss/system/cache/RedisUtils.java
package com.rumtel.dss.system.cache;

import java.util.List;

import com.rumtel.dss.system.util.ConstantUtil;

import redis.clients.jedis.Jedis;

/**
 * 
 * Java Redis读写分离操作工具
 *
 * @author yangtao
 * @since 2017年1月23日 下午1:14:45
 *
 */
public class RedisUtils {

	private Jedis getClient() {
		Jedis jedis = new Jedis(ConstantUtil.REDISHOST, ConstantUtil.REDISPORT);
		jedis.auth(ConstantUtil.REDISPASSWORD);
		return jedis;
	}
	
	/**
	 * hash删除对应field
	 */
	public boolean hdel(String key, String field) {
		Jedis jedis = getClient();
		long effects = 0;
		effects = jedis.hdel(key, field);
		jedis.close();
		return effects > 0;
	}

	/**
	 * hash删除对应fields
	 */
	public boolean hdel(String key, List<String> fields) {
		Jedis jedis = getClient();
		long effects = 0;
		for (String field : fields) {
			effects += jedis.hdel(key, field);
		}
		jedis.close();
		return effects > 0;
	}

	/**
	 * 删除key
	 */
	public boolean del(String key) {
		Jedis jedis = getClient();
		long effects = jedis.del(key);
		jedis.close();
		return effects > 0;
	}
}
最近下载更多
zjlvhk  LV4 2023年10月31日
安安an  LV17 2020年4月7日
说的s51221额  LV3 2019年10月22日
xiaoxiao303  LV8 2019年3月4日
xuhao432  LV8 2019年1月24日
小时代222  LV1 2018年5月11日
AbrahamLeeJay  LV1 2018年5月8日
最代码官方  LV167 2018年3月25日
最近浏览更多
zhujunnan  LV12 3月21日
简约时尚  LV13 2月6日
sunlzh888888  LV28 1月22日
zjlvhk  LV4 2023年10月31日
qwertyuiopzxc  LV1 2022年10月14日
Hachi6  LV13 2022年6月15日
youwuzuichen  LV10 2022年5月11日
人工智能4708  LV11 2022年1月13日
zz56zz  LV1 2021年12月19日
笛卡尔积  LV6 2021年12月6日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友