package com.icloud.cache.service.impl;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.icloud.cache.service.IRedisService;
import org.apache.log4j.Logger;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.BinaryClient.LIST_POSITION;
@Service
public class RedisServiceImpl implements IRedisService {
private static final Logger LOGGER = Logger.getLogger(RedisServiceImpl.class);
@Autowired
private JedisPool pool;
@Override
public String get(String key) {
Jedis jedis = null;
String value = null;
try {
jedis = pool.getResource();
value = jedis.get(key);
} catch (Exception e) {
LOGGER.error(e.getMessage());
} finally {
returnResource(pool, jedis);
}
return value;
}
@Override
public Set<String> getByPre(String pre) {
Jedis jedis = null;
Set<String> value = null;
try {
jedis = pool.getResource();
value = jedis.keys(pre + "*");
} catch (Exception e) {
LOGGER.error(e.getMessage());
} finally {
returnResource(pool, jedis);
}
return value;
}
@Override
public String set(String key, String value) {
Jedis jedis = null;
try {
jedis = pool.getResource();
return jedis.set(key, value);
} catch (Exception e) {
LOGGER.error(e.getMessage());
return "0";
} finally {
returnResource(pool, jedis);
}
}
@Override
public String set(String key, String value, int expire) {
Jedis jedis = null;
try {
jedis = pool.getResource();
int time = jedis.ttl(key).intValue() + expire;
String result = jedis.set(key, value);
jedis.expire(key, time);
return result;
} catch (Exception e) {
LOGGER.error(e.getMessage());
return "0";
} finally {
returnResource(pool, jedis);
}
}
@Override
public Long delPre(String key) {
Jedis jedis = null;
try {
jedis = pool.getResource();
Set<String> set = jedis.keys(key + "*");
int result = set.size();
Iterator<String> it = set.iterator();
while (it.hasNext()) {
String keyStr = it.next();
jedis.del(keyStr);
}
return new Long(result);
} catch (Exception e) {
LOGGER.error(e.getMessage());
return 0L;
} finally {
returnResource(pool, jedis);
}
}
@Override
public Long del(String... keys) {
Jedis jedis = null;
try {
jedis = pool.getResource();
return jedis.del(keys);
} catch (Exception e) {
LOGGER.error(e.getMessage());
return 0L;
} finally {
returnResource(pool, jedis);
}
}
@Override
public Long append(String key, String str) {
Jedis jedis = null;
Long res = null;
try {
jedis = pool.getResource();
res = jedis.append(key, str);
} catch (Exception e) {
LOGGER.error(e.getMessage());
return 0L;
} finally {
returnResource(pool, jedis);
}
return res;
}
@Override
public Boolean exists(String key) {
Jedis jedis = null;
try {
jedis = pool.getResource();
return jedis.exists(key);
} catch (Exception e) {
LOGGER.error(e.getMessage());
return false;
} finally {
returnResource(pool, jedis);
}
}
@Override
public Long setnx(String key, String value) {
Jedis jedis = null;
try {
jedis = pool.getResource();
return jedis.setnx(key, value);
} catch (Exception e) {
LOGGER.error(e.getMessage());
return 0L;
} finally {
returnResource(pool, jedis);
}
}
@Override
public String setex(String key, String value, int seconds) {
Jedis jedis = null;
String res = null;
try {
jedis = pool.getResource();
res = jedis.setex(key, seconds, value);
} catch (Exception e) {
LOGGER.error(e.getMessage());
} finally {
returnResource(pool, jedis);
}
return res;
}
@Override
public Long setrange(String key, String str, int offset) {
Jedis jedis = null;
try {
jedis = pool.getResource();
return jedis.setrange(key, offset, str);
} catch (Exception e) {
LOGGER.error(e.getMessage());
return 0L;
} finally {
returnResource(pool, jedis);
}
}
@Override
public List<String> mget(String... keys) {
Jedis jedis = null;
List<String> values = null;
try {
jedis = pool.getResource();
values = jedis.mget(keys);
} catch (Exception e) {
LOGGER.error(e.getMessage());
} finally {
returnResource(pool, jedis);
}
return values;
}
@Override
public String mset(String... keysvalues) {
Jedis jedis = null;
String res = null;
try {
jedis = pool.getResource();
res = jedis.mset(keysvalues);
} catch (Exception e) {
LOGGER.error(e.getMessage());
} finally {
returnResource(pool, jedis);
}
return res;
}
@Override
public Long msetnx(String... keysvalues) {
Jedis jedis = null;
Long res = 0L;
try {
jedis = pool.getResource();
res = jedis.msetnx(keysvalues);
} catch (Exception e) {
LOGGER.error(e.getMessage());
} finally {
returnResource(pool, jedis);
}
return res;
}
@Override
public String getset(String key, String value) {
Jedis jedis = null;
String res = null;
try {
jedis = pool.getResource();
res = jedis.getSet(key, value);
} catch (Exception e) {
LOGGER.error(e.getMessage());
} finally {
returnResource(pool, jedis);
}
return res;
}
@Override
public String getrange(String key, int startOffset, int endOffset) {
Jedis jedis = null;
String res = null;
try {
jedis = pool.getResource();
res = jedis.getrange(key, startOffset, endOffset);
} catch (Exception e) {
LOGGER.error(e.getMessage());
} finally {
returnResource(pool, jedis);
}
return res;
}
@Override
public Long incr(String key) {
Jedis jedis = null;
Long res = null;
try {
jedis = pool.getResource();
res = jedis.incr(key);
} catch (Exception e) {
LOGGER.error(e.getMessage());
} finally {
returnResource(pool, jedis);
}
return res;
}
@Override
public Long incrBy(String key, Long integer) {
Jedis jedis = null;
Long res = null;
try {
jedis = pool.getResource();
res = jedis.incrBy(key, integer);
} catch (Exception e) {
LOGGER.error(e.getMessage());
} finally {
returnResource(pool, jedis);
}
return res;
}
@Override
public Long decr(
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
m0_72731342
- 粉丝: 4
- 资源: 1829
最新资源
- Linux环境中Redis的安装、配置与系统集成方法解析
- Linux环境下Git工具的安装与配置流程指引
- Linux环境下Node.js的安装与简易Web服务部署教程
- 卡尔曼信号滤波与滑动平均及高斯滤波算法的MATLAB仿真演示及详细注释文档,卡尔曼信号滤波MATLAB仿真演示与滑动平均、高斯滤波算法对比手册,卡尔曼信号滤波demo,MATLAB仿真,对比算法还有滑
- PHP最新匿名在线聊天系统源码
- 上位机与FPGA间的数据交互:通过PCIe传输与光纤通信实现DDR3数据存储与取回,PCle与FPGA通信:数据收发、DDR3存储与光纤传输一体化处理,上位机通过PCle把数据发送给FPGA,FPGA
- Linux环境中Nginx服务器的部署与配置教程
- COMSOL相场法模拟毛细管渗吸过程:油水两相流相界面移动的基准验证与准确描述,COMSOL相场法模拟毛细管渗吸过程:油水两相流相界面移动的验证与比较,COMSOL相场法模拟毛细管渗吸过程! 经典毛
- 一个用 c 语言编写的文件加密与解密源码
- 基于用户协同过滤与爬虫技术的Python景区智能推荐系统:通过评分与余弦相似度算法,精准预测用户喜好并推荐景点,基于用户协同过滤的Python景点推荐系统:利用爬虫技术实现个性化评分预测与推荐,基于用
- 2025清华:DeepSeek+DeepResearch应用报告.pdf
- 高效永磁同步电机无位置传感器控制:基于龙伯格观测器的离散化仿真与STM32代码生成解决方案,高效永磁同步电机无位置传感器控制:基于龙伯格观测器的离散化仿真与STM32代码生成解决方案,IF开环切龙伯格
- PHP盲盒商城系统源码 晒图+免签+短信验证+在线回收 ThinkPHP框架
- Simulink卡尔曼滤波算法Demo:高效处理输入信号数据,与高斯滤波及滑动平均滤波算法的对比分析,轻松修改以适应不同应用场景,Simulink卡尔曼滤波算法DEMO:输入信号数据处理及与高斯滤波和
- 一个用 c 语言编写的简单的计算器(支持表达式求值)源码
- IPTV电视直播源管理系统源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)