package com.common.redis;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import com.web.task.TaskTest;
import redis.clients.jedis.BinaryClient.LIST_POSITION;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisShardInfo;
import redis.clients.jedis.ShardedJedis;
import redis.clients.jedis.ShardedJedisPipeline;
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.Tuple;
@Repository("redisClientTemplate")
public class RedisClientTemplate {
private static Logger log = Logger.getLogger(RedisClientTemplate.class);
@Autowired
private RedisDataSource redisDataSource;
public void disconnect() {
ShardedJedis shardedJedis = redisDataSource.getRedisClient();
shardedJedis.disconnect();
}
/**
* 设置单个值
*
* @param key
* @param value
* @return
*/
public String set(String key, String value) {
String result = null;
ShardedJedis shardedJedis = redisDataSource.getRedisClient();
if (shardedJedis == null) {
return result;
}
boolean broken = false;
try {
result = shardedJedis.set(key, value);
} catch (Exception e) {
log.error(e.getMessage(), e);
broken = true;
} finally {
redisDataSource.returnResource(shardedJedis, broken);
}
return result;
}
/**
* 获取单个值
*
* @param key
* @return
*/
public String get(String key) {
String result = null;
ShardedJedis shardedJedis = redisDataSource.getRedisClient();
if (shardedJedis == null) {
return result;
}
boolean broken = false;
try {
result = shardedJedis.get(key);
} catch (Exception e) {
log.error(e.getMessage(), e);
broken = true;
} finally {
redisDataSource.returnResource(shardedJedis, broken);
}
return result;
}
public Boolean exists(String key) {
Boolean result = false;
ShardedJedis shardedJedis = redisDataSource.getRedisClient();
if (shardedJedis == null) {
return result;
}
boolean broken = false;
try {
result = shardedJedis.exists(key);
} catch (Exception e) {
log.error(e.getMessage(), e);
broken = true;
} finally {
redisDataSource.returnResource(shardedJedis, broken);
}
return result;
}
public String type(String key) {
String result = null;
ShardedJedis shardedJedis = redisDataSource.getRedisClient();
if (shardedJedis == null) {
return result;
}
boolean broken = false;
try {
result = shardedJedis.type(key);
} catch (Exception e) {
log.error(e.getMessage(), e);
broken = true;
} finally {
redisDataSource.returnResource(shardedJedis, broken);
}
return result;
}
/**
* 在某段时间后实现
*
* @param key
* @param unixTime
* @return
*/
public Long expire(String key, int seconds) {
Long result = null;
ShardedJedis shardedJedis = redisDataSource.getRedisClient();
if (shardedJedis == null) {
return result;
}
boolean broken = false;
try {
result = shardedJedis.expire(key, seconds);
} catch (Exception e) {
log.error(e.getMessage(), e);
broken = true;
} finally {
redisDataSource.returnResource(shardedJedis, broken);
}
return result;
}
/**
* 在某个时间点失效
*
* @param key
* @param unixTime
* @return
*/
public Long expireAt(String key, long unixTime) {
Long result = null;
ShardedJedis shardedJedis = redisDataSource.getRedisClient();
if (shardedJedis == null) {
return result;
}
boolean broken = false;
try {
result = shardedJedis.expireAt(key, unixTime);
} catch (Exception e) {
log.error(e.getMessage(), e);
broken = true;
} finally {
redisDataSource.returnResource(shardedJedis, broken);
}
return result;
}
public Long ttl(String key) {
Long result = null;
ShardedJedis shardedJedis = redisDataSource.getRedisClient();
if (shardedJedis == null) {
return result;
}
boolean broken = false;
try {
result = shardedJedis.ttl(key);
} catch (Exception e) {
log.error(e.getMessage(), e);
broken = true;
} finally {
redisDataSource.returnResource(shardedJedis, broken);
}
return result;
}
public boolean setbit(String key, long offset, boolean value) {
ShardedJedis shardedJedis = redisDataSource.getRedisClient();
boolean result = false;
if (shardedJedis == null) {
return result;
}
boolean broken = false;
try {
result = shardedJedis.setbit(key, offset, value);
} catch (Exception e) {
log.error(e.getMessage(), e);
broken = true;
} finally {
redisDataSource.returnResource(shardedJedis, broken);
}
return result;
}
public boolean getbit(String key, long offset) {
ShardedJedis shardedJedis = redisDataSource.getRedisClient();
boolean result = false;
if (shardedJedis == null) {
return result;
}
boolean broken = false;
try {
result = shardedJedis.getbit(key, offset);
} catch (Exception e) {
log.error(e.getMessage(), e);
broken = true;
} finally {
redisDataSource.returnResource(shardedJedis, broken);
}
return result;
}
public long setrange(String key, long offset, String value) {
ShardedJedis shardedJedis = redisDataSource.getRedisClient();
long result = 0;
if (shardedJedis == null) {
return result;
}
boolean broken = false;
try {
result = shardedJedis.setrange(key, offset, value);
} catch (Exception e) {
log.error(e.getMessage(), e);
broken = true;
} finally {
redisDataSource.returnResource(shardedJedis, broken);
}
return result;
}
public String getrange(String key, long startOffset, long endOffset) {
ShardedJedis shardedJedis = redisDataSource.getRedisClient();
String result = null;
if (shardedJedis == null) {
return result;
}
boolean broken = false;
try {
result = shardedJedis.getrange(key, startOffset, endOffset);
} catch (Exception e) {
log.error(e.getMessage(), e);
broken = true;
} finally {
redisDataSource.returnResource(shardedJedis, broken);
}
return result;
}
public String getSet(String key, String value) {
String result = null;
ShardedJedis shardedJedis = redisDataSource.getRedisClient();
if (shardedJedis == null) {
return result;
}
boolean broken
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Spring mvc整合redis实例(测试通过) (139个子文件)
RedisClientTemplate.class 62KB
SysUserController.class 3KB
SysUser.class 2KB
RedisDataSourceImpl.class 2KB
SysUserDaoImpl.class 1KB
SysUserServiceImpl.class 1KB
SpringConfigLoader.class 1KB
RedisTest.class 1KB
TestUser.class 1KB
TestDao.class 1008B
TaskTest.class 745B
TaskTestTwo.class 571B
TestService.class 402B
SysUserService.class 321B
RedisDataSource.class 306B
SysUserDao.class 293B
.classpath 841B
org.eclipse.wst.common.component 482B
org.eclipse.wst.jsdt.ui.superType.container 49B
layer.css 14KB
loading-0.gif 6KB
loading-2.gif 2KB
loading-1.gif 701B
hibernate-core-4.3.9.Final.jar 5.03MB
druid-1.0.14.jar 1.84MB
freemarker.jar 1.24MB
jackson-all-1.9.11.jar 1.07MB
spring-context-4.1.6.RELEASE.jar 1002KB
spring-core-4.1.6.RELEASE.jar 984KB
jackson-databind-2.3.2.jar 894KB
mysql-connector-java-5.1.18-bin.jar 771KB
spring-webmvc-4.1.6.RELEASE.jar 762KB
spring-web-4.1.6.RELEASE.jar 702KB
javassist-3.18.1-GA.jar 697KB
spring-beans-4.1.6.RELEASE.jar 692KB
spring-data-redis-1.5.0.RELEASE.jar 661KB
mchange-commons-java-0.2.3.4.jar 568KB
commons-collections-3.2.1.jar 562KB
spring-test-4.1.6.RELEASE.jar 491KB
log4j-1.2.16.jar 470KB
antlr-2.7.7.jar 435KB
spring-jdbc-4.1.6.RELEASE.jar 417KB
c3p0-0.9.2.1.jar 414KB
fastjson-1.2.6.jar 411KB
jstl-1.2.jar 405KB
spring-websocket-4.1.6.RELEASE.jar 379KB
spring-orm-4.1.6.RELEASE.jar 367KB
spring-aop-4.1.6.RELEASE.jar 351KB
jedis-2.7.2.jar 315KB
dom4j-1.6.1.jar 307KB
spring-messaging-4.1.6.RELEASE.jar 279KB
commons-lang-2.6.jar 278KB
commons-net-3.3.jar 274KB
spring-jms-4.1.6.RELEASE.jar 263KB
spring-expression-4.1.6.RELEASE.jar 253KB
junit-4.10.jar 247KB
spring-tx-4.1.6.RELEASE.jar 247KB
commons-beanutils-1.8.3.jar 227KB
jackson-core-2.3.2.jar 195KB
commons-io-2.4.jar 181KB
spring-context-support-4.1.6.RELEASE.jar 174KB
spring-webmvc-portlet-4.1.6.RELEASE.jar 173KB
hibernate-jpa-2.1-api-1.0.0.Final.jar 111KB
commons-pool-1.6.jar 109KB
commons-pool2-2.0.jar 105KB
spring-oxm-4.1.6.RELEASE.jar 80KB
jandex-1.1.0.Final.jar 75KB
hibernate-commons-annotations-4.0.5.Final.jar 74KB
commons-logging-1.1.1.jar 59KB
commons-fileupload-1.2.2.jar 58KB
jboss-logging-3.1.3.GA.jar 56KB
spring-aspects-4.1.6.RELEASE.jar 55KB
hibernate-c3p0-4.3.9.Final.jar 39KB
jackson-annotations-2.3.0.jar 34KB
jboss-transaction-api_1.2_spec-1.0.0.Final.jar 27KB
slf4j-api-1.6.2.jar 25KB
rdjt-framework1.0.jar 23KB
jboss-logging-annotations-1.2.0.Beta1.jar 11KB
spring-instrument-tomcat-4.1.6.RELEASE.jar 10KB
slf4j-log4j12-1.6.2.jar 10KB
slf4j-jdk14-1.6.2.jar 9KB
spring-instrument-4.1.6.RELEASE.jar 7KB
aopalliance-1.0.jar 4KB
RedisClientTemplate.java 89KB
SysUserController.java 2KB
SysUser.java 2KB
RedisDataSourceImpl.java 1KB
SpringConfigLoader.java 939B
SysUserServiceImpl.java 920B
SysUserDaoImpl.java 894B
TaskTest.java 692B
TestUser.java 619B
RedisTest.java 601B
TestDao.java 519B
SysUserService.java 439B
RedisDataSource.java 422B
SysUserDao.java 411B
TaskTestTwo.java 308B
TestService.java 138B
jquery-1.10.2.js 267KB
共 139 条
- 1
- 2
资源评论
- 我爱荤菜2018-08-23不错,这个很好,值得下载
- dx9192018-08-22反正是用来参考 不用太全 嘿嘿
- 前尘忆梦2018-04-10很不错的资源
- 都市妖__影魅2016-09-23数据库文件没有给哦bianlingda2016-09-26有的,在src下的 sys_user.sql
- ZeusLuna2016-09-18可用,编译能过,但是核心的东西都打成了jar包,需要反编译来看bianlingda2016-09-22主要是演示redis和SpringMVC的整合, 打成jar包的那些是web开发用的
bianlingda
- 粉丝: 5
- 资源: 31
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 一个基于JAVA的类魔塔小游戏 a Java based MagicTowerlike game.zip网络安全
- 基于 SpringBoot 开发的员工的季度绩效考核系统.zip
- 微信自动抢红包动态库.zip程序资源学习资料参考
- 新年快乐的烟花代码.zip
- kotlin 实践微信插件助手, 目前支持抢红包(支持微信最新版本 7.0.0及7.0.3).zip
- 多模态大模型在视觉领域的全面调查
- iOS微信自动抢红包和防撤回插件.zip小程序
- 富士打印机(DocuCentre S2110)打印、扫描驱动下载
- 升腾威讯C73N笔记本无线网卡Win10驱动(稳定支持WiFi6)
- Java Web实验报告三:基于Jquery的表单验证插件
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功