package com.ace.cache.service.impl;
import com.ace.cache.service.IRedisService;
import lombok.extern.slf4j.Slf4j;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.BinaryClient.LIST_POSITION;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import java.util.*;
@Slf4j
public class RedisServiceImpl implements IRedisService {
@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) {
log.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) {
log.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) {
log.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) {
log.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 Long.valueOf(result);
} catch (Exception e) {
log.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) {
log.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) {
log.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) {
log.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) {
log.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) {
log.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) {
log.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) {
log.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) {
log.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) {
log.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) {
log.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) {
log.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) {
log.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) {
log.error(e.getMessage());
} finally {
returnResource(pool, jedis);
}
return res;
}
@Override
public Long decr(String key) {
Jedis jedis = null;
Long res = null;
try {
jedis = pool.getResource();
res = jedis.decr(key);
} catch (Exception e) {
log.error(e.getMessage());
} finally {
returnResource(pool, jedis
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
ace-cache-master.zip (60个子文件)
ace-cache-master
pom.xml 6KB
Jenkinsfile 379B
LICENSE 11KB
src
test
resources
application.yml 537B
java
com
ace
cache
test
cache
MyKeyGenerator.java 583B
unit
UserServiceTest.java 2KB
service
UserService.java 487B
impl
UserServiceImpl.java 4KB
entity
User.java 1KB
CacheTest.java 440B
main
resources
META-INF
static
css
bootstrap-3.1.0.css 126KB
jquery.jsonview.min.css 1KB
bootstrap-treeview.min.css 260B
index.html 4KB
js
bootstrap-treeview.min.js 21KB
jquery.jsonview.min.js 6KB
bootstrap-3.1.0.js 60KB
cache.js 4KB
jquery-2.1.1.min.js 82KB
java
com
ace
cache
config
CacheWebConfig.java 561B
RedisPoolConfig.java 658B
WebConfig.java 600B
RedisConfig.java 3KB
aspect
CacheAspect.java 2KB
ResultParseService.java 2KB
CacheClearAspect.java 5KB
CacheGlobalLockAspect.java 2KB
KeyGenerateService.java 3KB
constants
CacheConstants.java 174B
CacheScope.java 83B
AutoConfiguration.java 6KB
rest
CacheRest.java 2KB
EnableAceCache.java 312B
annotation
CacheClear.java 1KB
Cache.java 2KB
CacheGlobalLock.java 1KB
api
CacheAPI.java 2KB
impl
CacheRedis.java 6KB
controller
CacheController.java 597B
service
IRedisService.java 19KB
ICacheManager.java 665B
impl
BootRedisServiceImpl.java 8KB
RedisLock.java 2KB
RedisServiceImpl.java 30KB
CacheManagerImpl.java 4KB
entity
CacheBean.java 1KB
utils
PropertiesLoaderUtils.java 4KB
CacheUtil.java 3KB
ReflectionUtils.java 13KB
WebUtil.java 844B
TreeUtils.java 907B
vo
CacheTree.java 2KB
parser
IKeyGenerator.java 1KB
IUserKeyGenerator.java 235B
ICacheResultParser.java 434B
impl
DefaultResultParser.java 1KB
DefaultKeyGenerator.java 3KB
.classpath 1KB
.gitignore 28B
.gitattributes 87B
共 60 条
- 1
资源评论
m0_72731342
- 粉丝: 2
- 资源: 1832
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功