1,利用spring-data-redis整合
项目使用的pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.x.redis</groupId> <artifactId>Spring_redis</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>Spring_redis</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-redis</artifactId> <version>1.0.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>3.1.2.RELEASE</version> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.1.0</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.2</version> <scope>test</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.6.1</version> </dependency> <!-- 将现有的jakarta commons logging的调用转换成lsf4j的调用。 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>jcl-over-slf4j</artifactId> <version>1.6.1</version> </dependency> <!-- Hack:确保commons-logging的jar包不被引入,否则将和jcl-over-slf4j冲突 --> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1.1</version> <scope>provided</scope> </dependency> <!-- slf4j的实现:logback,用来取代log4j。更快、更强! --> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>0.9.24</version> <scope>runtime</scope> </dependency> </dependencies> </project>
除了log部分,只有一个spring core 和 spring-data-redis了
项目文件目录结构:
applicationContext.xml:
1,context:property-placeholder 标签用来导入properties文件。从而替换${redis.maxIdle}这样的变量。
2,context:component-scan 是为了在com.x.redis.dao报下的类能够实用spring的注解注入的方式。
3,事实上我们只需要把JedisPoolConfig配数来就好了,接下来就是spring的封装了。所以直接看UserDAOImpl的实现就明白了。
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:property-placeholder location="classpath:redis.properties" /> <context:component-scan base-package="com.x.redis.dao"> </context:component-scan> <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig"> <property name="maxIdle" value="${redis.maxIdle}" /> <property name="maxActive" value="${redis.maxActive}" /> <property name="maxWait" value="${redis.maxWait}" /> <property name="testOnBorrow" value="${redis.testOnBorrow}" /> </bean> <bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:host-name="${redis.host}" p:port="${redis.port}" p:password="${redis.pass}" p:pool-config-ref="poolConfig"/> <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate"> <property name="connectionFactory" ref="connectionFactory" /> </bean> <bean id="userDAO" class="com.x.redis.dao.impl.UserDAOImpl" /> </beans>
redis.properties:
# Redis settings #redis.host=192.168.20.101 #redis.port=6380 #redis.pass=foobared redis.host=127.0.0.1 redis.port=6379 redis.pass= redis.maxIdle=300 redis.maxActive=600 redis.maxWait=1000 redis.testOnBorrow=true
UserDAOImpl:
1,spring对dao层的封装很多用了类似于下面代码的模板方式。
2,RedisTemplate就是spring对redis的一个封装而已。
1 public class UserDAOImpl implements UserDAO { 2 3 @Autowired 4 protected RedisTemplate<Serializable, Serializable> redisTemplate; 5 6 public void saveUser(final User user) { 7 redisTemplate.execute(new RedisCallback<Object>() { 8 9 @Override 10 public Object doInRedis(RedisConnection connection) throws DataAccessException { 11 connection.set(redisTemplate.getStringSerializer().serialize("user.uid." + user.getId()), 12 redisTemplate.getStringSerializer().serialize(user.getName())); 13 return null; 14 } 15 }); 16 } 17 18 @Override 19 public User getUser(final long id) { 20 return redisTemplate.execute(new RedisCallback<User>() { 21 @Override 22 public User doInRedis(RedisConnection connection) throws DataAccessException { 23 byte[] key = redisTemplate.getStringSerializer().serialize("user.uid." + id); 24 if (connection.exists(key)) { 25 byte[] value = connection.get(key); 26 String name = redisTemplate.getStringSerializer().deserialize(value); 27 User user = new User(); 28 user.setName(name); 29 user.setId(id); 30 return user; 31 } 32 return null; 33 } 34 }); 35 } 36 37 }
其他:
User:
1 public class User { 2 3 private long id; 4 private String name; 5 6 public long getId() { 7 return id; 8 } 9 10 public void setId(long id) { 11 this.id = id; 12 } 13 14 public String getName() { 15 return name; 16 } 17 18 public void setName(String name) { 19 this.name = name; 20 } 21 }
测试代码:
1 public static void main(String[] args) { 2 ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:/applicationContext.xml"); 3 UserDAO userDAO = (UserDAO)ac.getBean("userDAO"); 4 User user1 = new User(); 5 user1.setId(1); 6 user1.setName("obama"); 7 userDAO.saveUser(user1); 8 User user2 = userDAO.getUser(1); 9 System.out.println(user2.getName()); 10 }
2,不利用spring-data-redis整合
个人觉得这样整合灵活度更大,能够更加明了的完成任务。
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.d.work</groupId> <artifactId>Redis_Templete</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>Redis_Templete</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.1.0</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>3.1.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>3.1.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>3.1.2.RELEASE</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.6.1</version> </dependency> <!-- 将现有的jakarta commons logging的调用转换成lsf4j的调用。 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>jcl-over-slf4j</artifactId> <version>1.6.1</version> </dependency> <!-- Hack:确保commons-logging的jar包不被引入,否则将和jcl-over-slf4j冲突 --> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1.1</version> <scope>provided</scope> </dependency> <!-- slf4j的实现:logback,用来取代log4j。更快、更强! --> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>0.9.24</version> <scope>runtime</scope> </dependency> </dependencies> </project>
目录结构:
data-source.xml
1,context:property-placeholder 和 context:component-scan 前面解释过啦。
2,配置了一个ShardedJedisPool,在jdeis里 还有个JedisPool。这两个的区别:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:property-placeholder location="classpath:redis.properties" /> <context:component-scan base-package="com.d.work.main"> </context:component-scan> <context:component-scan base-package="com.d.work.redis"> </context:component-scan> <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"> <property name="maxActive" value="50" /> <property name="maxIdle" value="8" /> <property name="maxWait" value="1000" /> <property name="testOnBorrow" value="true"/> <property name="testOnReturn" value="true"/> <!-- <property name="testWhileIdle" value="true"/> --> </bean> <bean id="shardedJedisPool" class="redis.clients.jedis.ShardedJedisPool" scope="singleton"> <constructor-arg index="0" ref="jedisPoolConfig" /> <constructor-arg index="1"> <list> <bean class="redis.clients.jedis.JedisShardInfo"> <constructor-arg name="host" value="${redis.host}" /> <constructor-arg name="port" value="${redis.port}" /> <constructor-arg name="timeout" value="${redis.timeout}" /> <constructor-arg name="weight" value="1" /> </bean> </list> </constructor-arg> </bean> </beans>
RedisDataSource:定义三个方法
1 public interface RedisDataSource { 2 public abstract ShardedJedis getRedisClient(); 3 public void returnResource(ShardedJedis shardedJedis); 4 public void returnResource(ShardedJedis shardedJedis,boolean broken); 5 }
实现redisDataSource:
1, 注入配置好的ShardedJedisPool,这三个方法的作用:
getRedisClient() : 取得redis的客户端,可以执行命令了。
returnResource(ShardedJedis shardedJedis) : 将资源返还给pool
returnResource(ShardedJedis shardedJedis, boolean broken) : 出现异常后,将资源返还给pool (其实不需要第二个方法)
1 @Repository("redisDataSource") 2 public class RedisDataSourceImpl implements RedisDataSource { 3 4 private static final Logger log = LoggerFactory.getLogger(RedisDataSourceImpl.class); 5 6 @Autowired 7 private ShardedJedisPool shardedJedisPool; 8 9 public ShardedJedis getRedisClient() { 10 try { 11 ShardedJedis shardJedis = shardedJedisPool.getResource(); 12 return shardJedis; 13 } catch (Exception e) { 14 log.error("getRedisClent error", e); 15 } 16 return null; 17 } 18 19 public void returnResource(ShardedJedis shardedJedis) { 20 shardedJedisPool.returnResource(shardedJedis); 21 } 22 23 public void returnResource(ShardedJedis shardedJedis, boolean broken) { 24 if (broken) { 25 shardedJedisPool.returnBrokenResource(shardedJedis); 26 } else { 27 shardedJedisPool.returnResource(shardedJedis); 28 } 29 } 30 }
第二层的封装:RedisClientTemplate,例子实现了放值和取值。最后代码提供了全部命令的实现。
代码就是映射性质的又一次调用jedis的方法而已,用了个broken来做标示符,决定返还资源的方式。
这一层的目的主要也是让再上层的调用不需要关心pool中链接的取得和返还问题了。
1 @Repository("redisClientTemplate") 2 public class RedisClientTemplate { 3 4 private static final Logger log = LoggerFactory.getLogger(RedisClientTemplate.class); 5 6 @Autowired 7 private RedisDataSource redisDataSource; 8 9 public void disconnect() { 10 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 11 shardedJedis.disconnect(); 12 } 13 14 /** 15 * 设置单个值 16 * 17 * @param key 18 * @param value 19 * @return 20 */ 21 public String set(String key, String value) { 22 String result = null; 23 24 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 25 if (shardedJedis == null) { 26 return result; 27 } 28 boolean broken = false; 29 try { 30 result = shardedJedis.set(key, value); 31 } catch (Exception e) { 32 log.error(e.getMessage(), e); 33 broken = true; 34 } finally { 35 redisDataSource.returnResource(shardedJedis, broken); 36 } 37 return result; 38 } 39 40 /** 41 * 获取单个值 42 * 43 * @param key 44 * @return 45 */ 46 public String get(String key) { 47 String result = null; 48 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 49 if (shardedJedis == null) { 50 return result; 51 } 52 53 boolean broken = false; 54 try { 55 result = shardedJedis.get(key); 56 57 } catch (Exception e) { 58 log.error(e.getMessage(), e); 59 broken = true; 60 } finally { 61 redisDataSource.returnResource(shardedJedis, broken); 62 } 63 return result; 64 } 65 }
测试代码:
1 public static void main(String[] args) { 2 ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:/data-source.xml"); 3 RedisClientTemplate redisClient = (RedisClientTemplate)ac.getBean("redisClientTemplate"); 4 redisClient.set("a", "abc"); 5 System.out.println(redisClient.get("a")); 6 }
附上RedisClientTemplate全部实现:
1 @Repository("redisClientTemplate") 2 public class RedisClientTemplate { 3 4 private static final Logger log = LoggerFactory.getLogger(RedisClientTemplate.class); 5 6 @Autowired 7 private RedisDataSource redisDataSource; 8 9 public void disconnect() { 10 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 11 shardedJedis.disconnect(); 12 } 13 14 /** 15 * 设置单个值 16 * 17 * @param key 18 * @param value 19 * @return 20 */ 21 public String set(String key, String value) { 22 String result = null; 23 24 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 25 if (shardedJedis == null) { 26 return result; 27 } 28 boolean broken = false; 29 try { 30 result = shardedJedis.set(key, value); 31 } catch (Exception e) { 32 log.error(e.getMessage(), e); 33 broken = true; 34 } finally { 35 redisDataSource.returnResource(shardedJedis, broken); 36 } 37 return result; 38 } 39 40 /** 41 * 获取单个值 42 * 43 * @param key 44 * @return 45 */ 46 public String get(String key) { 47 String result = null; 48 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 49 if (shardedJedis == null) { 50 return result; 51 } 52 53 boolean broken = false; 54 try { 55 result = shardedJedis.get(key); 56 57 } catch (Exception e) { 58 log.error(e.getMessage(), e); 59 broken = true; 60 } finally { 61 redisDataSource.returnResource(shardedJedis, broken); 62 } 63 return result; 64 } 65 66 public Boolean exists(String key) { 67 Boolean result = false; 68 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 69 if (shardedJedis == null) { 70 return result; 71 } 72 boolean broken = false; 73 try { 74 result = shardedJedis.exists(key); 75 } catch (Exception e) { 76 log.error(e.getMessage(), e); 77 broken = true; 78 } finally { 79 redisDataSource.returnResource(shardedJedis, broken); 80 } 81 return result; 82 } 83 84 public String type(String key) { 85 String result = null; 86 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 87 if (shardedJedis == null) { 88 return result; 89 } 90 boolean broken = false; 91 try { 92 result = shardedJedis.type(key); 93 94 } catch (Exception e) { 95 log.error(e.getMessage(), e); 96 broken = true; 97 } finally { 98 redisDataSource.returnResource(shardedJedis, broken); 99 } 100 return result; 101 } 102 103 /** 104 * 在某段时间后实现 105 * 106 * @param key 107 * @param unixTime 108 * @return 109 */ 110 public Long expire(String key, int seconds) { 111 Long result = null; 112 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 113 if (shardedJedis == null) { 114 return result; 115 } 116 boolean broken = false; 117 try { 118 result = shardedJedis.expire(key, seconds); 119 120 } catch (Exception e) { 121 log.error(e.getMessage(), e); 122 broken = true; 123 } finally { 124 redisDataSource.returnResource(shardedJedis, broken); 125 } 126 return result; 127 } 128 129 /** 130 * 在某个时间点失效 131 * 132 * @param key 133 * @param unixTime 134 * @return 135 */ 136 public Long expireAt(String key, long unixTime) { 137 Long result = null; 138 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 139 if (shardedJedis == null) { 140 return result; 141 } 142 boolean broken = false; 143 try { 144 result = shardedJedis.expireAt(key, unixTime); 145 146 } catch (Exception e) { 147 log.error(e.getMessage(), e); 148 broken = true; 149 } finally { 150 redisDataSource.returnResource(shardedJedis, broken); 151 } 152 return result; 153 } 154 155 public Long ttl(String key) { 156 Long result = null; 157 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 158 if (shardedJedis == null) { 159 return result; 160 } 161 boolean broken = false; 162 try { 163 result = shardedJedis.ttl(key); 164 165 } catch (Exception e) { 166 log.error(e.getMessage(), e); 167 broken = true; 168 } finally { 169 redisDataSource.returnResource(shardedJedis, broken); 170 } 171 return result; 172 } 173 174 public boolean setbit(String key, long offset, boolean value) { 175 176 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 177 boolean result = false; 178 if (shardedJedis == null) { 179 return result; 180 } 181 boolean broken = false; 182 try { 183 result = shardedJedis.setbit(key, offset, value); 184 } catch (Exception e) { 185 log.error(e.getMessage(), e); 186 broken = true; 187 } finally { 188 redisDataSource.returnResource(shardedJedis, broken); 189 } 190 return result; 191 } 192 193 public boolean getbit(String key, long offset) { 194 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 195 boolean result = false; 196 if (shardedJedis == null) { 197 return result; 198 } 199 boolean broken = false; 200 201 try { 202 result = shardedJedis.getbit(key, offset); 203 } catch (Exception e) { 204 log.error(e.getMessage(), e); 205 broken = true; 206 } finally { 207 redisDataSource.returnResource(shardedJedis, broken); 208 } 209 return result; 210 } 211 212 public long setrange(String key, long offset, String value) { 213 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 214 long result = 0; 215 if (shardedJedis == null) { 216 return result; 217 } 218 boolean broken = false; 219 try { 220 result = shardedJedis.setrange(key, offset, value); 221 } catch (Exception e) { 222 log.error(e.getMessage(), e); 223 broken = true; 224 } finally { 225 redisDataSource.returnResource(shardedJedis, broken); 226 } 227 return result; 228 } 229 230 public String getrange(String key, long startOffset, long endOffset) { 231 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 232 String result = null; 233 if (shardedJedis == null) { 234 return result; 235 } 236 boolean broken = false; 237 try { 238 result = shardedJedis.getrange(key, startOffset, endOffset); 239 240 } catch (Exception e) { 241 log.error(e.getMessage(), e); 242 broken = true; 243 } finally { 244 redisDataSource.returnResource(shardedJedis, broken); 245 } 246 return result; 247 } 248 249 public String getSet(String key, String value) { 250 String result = null; 251 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 252 if (shardedJedis == null) { 253 return result; 254 } 255 boolean broken = false; 256 try { 257 result = shardedJedis.getSet(key, value); 258 } catch (Exception e) { 259 log.error(e.getMessage(), e); 260 broken = true; 261 } finally { 262 redisDataSource.returnResource(shardedJedis, broken); 263 } 264 return result; 265 } 266 267 public Long setnx(String key, String value) { 268 Long result = null; 269 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 270 if (shardedJedis == null) { 271 return result; 272 } 273 boolean broken = false; 274 try { 275 result = shardedJedis.setnx(key, value); 276 } catch (Exception e) { 277 log.error(e.getMessage(), e); 278 broken = true; 279 } finally { 280 redisDataSource.returnResource(shardedJedis, broken); 281 } 282 return result; 283 } 284 285 public String setex(String key, int seconds, String value) { 286 String result = null; 287 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 288 if (shardedJedis == null) { 289 return result; 290 } 291 boolean broken = false; 292 try { 293 result = shardedJedis.setex(key, seconds, value); 294 295 } catch (Exception e) { 296 log.error(e.getMessage(), e); 297 broken = true; 298 } finally { 299 redisDataSource.returnResource(shardedJedis, broken); 300 } 301 return result; 302 } 303 304 public Long decrBy(String key, long integer) { 305 Long result = null; 306 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 307 if (shardedJedis == null) { 308 return result; 309 } 310 boolean broken = false; 311 try { 312 result = shardedJedis.decrBy(key, integer); 313 314 } catch (Exception e) { 315 log.error(e.getMessage(), e); 316 broken = true; 317 } finally { 318 redisDataSource.returnResource(shardedJedis, broken); 319 } 320 return result; 321 } 322 323 public Long decr(String key) { 324 Long result = null; 325 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 326 if (shardedJedis == null) { 327 return result; 328 } 329 boolean broken = false; 330 try { 331 result = shardedJedis.decr(key); 332 333 } catch (Exception e) { 334 log.error(e.getMessage(), e); 335 broken = true; 336 } finally { 337 redisDataSource.returnResource(shardedJedis, broken); 338 } 339 return result; 340 } 341 342 public Long incrBy(String key, long integer) { 343 Long result = null; 344 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 345 if (shardedJedis == null) { 346 return result; 347 } 348 boolean broken = false; 349 try { 350 result = shardedJedis.incrBy(key, integer); 351 352 } catch (Exception e) { 353 log.error(e.getMessage(), e); 354 broken = true; 355 } finally { 356 redisDataSource.returnResource(shardedJedis, broken); 357 } 358 return result; 359 } 360 361 public Long incr(String key) { 362 Long result = null; 363 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 364 if (shardedJedis == null) { 365 return result; 366 } 367 boolean broken = false; 368 try { 369 result = shardedJedis.incr(key); 370 371 } catch (Exception e) { 372 log.error(e.getMessage(), e); 373 broken = true; 374 } finally { 375 redisDataSource.returnResource(shardedJedis, broken); 376 } 377 return result; 378 } 379 380 public Long append(String key, String value) { 381 Long result = null; 382 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 383 if (shardedJedis == null) { 384 return result; 385 } 386 boolean broken = false; 387 try { 388 result = shardedJedis.append(key, value); 389 390 } catch (Exception e) { 391 log.error(e.getMessage(), e); 392 broken = true; 393 } finally { 394 redisDataSource.returnResource(shardedJedis, broken); 395 } 396 return result; 397 } 398 399 public String substr(String key, int start, int end) { 400 String result = null; 401 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 402 if (shardedJedis == null) { 403 return result; 404 } 405 boolean broken = false; 406 try { 407 result = shardedJedis.substr(key, start, end); 408 409 } catch (Exception e) { 410 log.error(e.getMessage(), e); 411 broken = true; 412 } finally { 413 redisDataSource.returnResource(shardedJedis, broken); 414 } 415 return result; 416 } 417 418 public Long hset(String key, String field, String value) { 419 Long result = null; 420 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 421 if (shardedJedis == null) { 422 return result; 423 } 424 boolean broken = false; 425 try { 426 result = shardedJedis.hset(key, field, value); 427 428 } catch (Exception e) { 429 log.error(e.getMessage(), e); 430 broken = true; 431 } finally { 432 redisDataSource.returnResource(shardedJedis, broken); 433 } 434 return result; 435 } 436 437 public String hget(String key, String field) { 438 String result = null; 439 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 440 if (shardedJedis == null) { 441 return result; 442 } 443 boolean broken = false; 444 try { 445 result = shardedJedis.hget(key, field); 446 447 } catch (Exception e) { 448 log.error(e.getMessage(), e); 449 broken = true; 450 } finally { 451 redisDataSource.returnResource(shardedJedis, broken); 452 } 453 return result; 454 } 455 456 public Long hsetnx(String key, String field, String value) { 457 Long result = null; 458 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 459 if (shardedJedis == null) { 460 return result; 461 } 462 boolean broken = false; 463 try { 464 result = shardedJedis.hsetnx(key, field, value); 465 466 } catch (Exception e) { 467 log.error(e.getMessage(), e); 468 broken = true; 469 } finally { 470 redisDataSource.returnResource(shardedJedis, broken); 471 } 472 return result; 473 } 474 475 public String hmset(String key, Map<String, String> hash) { 476 String result = null; 477 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 478 if (shardedJedis == null) { 479 return result; 480 } 481 boolean broken = false; 482 try { 483 result = shardedJedis.hmset(key, hash); 484 485 } catch (Exception e) { 486 log.error(e.getMessage(), e); 487 broken = true; 488 } finally { 489 redisDataSource.returnResource(shardedJedis, broken); 490 } 491 return result; 492 } 493 494 public List<String> hmget(String key, String... fields) { 495 List<String> result = null; 496 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 497 if (shardedJedis == null) { 498 return result; 499 } 500 boolean broken = false; 501 try { 502 result = shardedJedis.hmget(key, fields); 503 504 } catch (Exception e) { 505 log.error(e.getMessage(), e); 506 broken = true; 507 } finally { 508 redisDataSource.returnResource(shardedJedis, broken); 509 } 510 return result; 511 } 512 513 public Long hincrBy(String key, String field, long value) { 514 Long result = null; 515 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 516 if (shardedJedis == null) { 517 return result; 518 } 519 boolean broken = false; 520 try { 521 result = shardedJedis.hincrBy(key, field, value); 522 523 } catch (Exception e) { 524 log.error(e.getMessage(), e); 525 broken = true; 526 } finally { 527 redisDataSource.returnResource(shardedJedis, broken); 528 } 529 return result; 530 } 531 532 public Boolean hexists(String key, String field) { 533 Boolean result = false; 534 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 535 if (shardedJedis == null) { 536 return result; 537 } 538 boolean broken = false; 539 try { 540 result = shardedJedis.hexists(key, field); 541 542 } catch (Exception e) { 543 log.error(e.getMessage(), e); 544 broken = true; 545 } finally { 546 redisDataSource.returnResource(shardedJedis, broken); 547 } 548 return result; 549 } 550 551 public Long del(String key) { 552 Long result = null; 553 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 554 if (shardedJedis == null) { 555 return result; 556 } 557 boolean broken = false; 558 try { 559 result = shardedJedis.del(key); 560 561 } catch (Exception e) { 562 log.error(e.getMessage(), e); 563 broken = true; 564 } finally { 565 redisDataSource.returnResource(shardedJedis, broken); 566 } 567 return result; 568 } 569 570 public Long hdel(String key, String field) { 571 Long result = null; 572 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 573 if (shardedJedis == null) { 574 return result; 575 } 576 boolean broken = false; 577 try { 578 result = shardedJedis.hdel(key, field); 579 580 } catch (Exception e) { 581 log.error(e.getMessage(), e); 582 broken = true; 583 } finally { 584 redisDataSource.returnResource(shardedJedis, broken); 585 } 586 return result; 587 } 588 589 public Long hlen(String key) { 590 Long result = null; 591 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 592 if (shardedJedis == null) { 593 return result; 594 } 595 boolean broken = false; 596 try { 597 result = shardedJedis.hlen(key); 598 599 } catch (Exception e) { 600 log.error(e.getMessage(), e); 601 broken = true; 602 } finally { 603 redisDataSource.returnResource(shardedJedis, broken); 604 } 605 return result; 606 } 607 608 public Set<String> hkeys(String key) { 609 Set<String> result = null; 610 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 611 if (shardedJedis == null) { 612 return result; 613 } 614 boolean broken = false; 615 try { 616 result = shardedJedis.hkeys(key); 617 618 } catch (Exception e) { 619 log.error(e.getMessage(), e); 620 broken = true; 621 } finally { 622 redisDataSource.returnResource(shardedJedis, broken); 623 } 624 return result; 625 } 626 627 public List<String> hvals(String key) { 628 List<String> result = null; 629 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 630 if (shardedJedis == null) { 631 return result; 632 } 633 boolean broken = false; 634 try { 635 result = shardedJedis.hvals(key); 636 637 } catch (Exception e) { 638 log.error(e.getMessage(), e); 639 broken = true; 640 } finally { 641 redisDataSource.returnResource(shardedJedis, broken); 642 } 643 return result; 644 } 645 646 public Map<String, String> hgetAll(String key) { 647 Map<String, String> result = null; 648 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 649 if (shardedJedis == null) { 650 return result; 651 } 652 boolean broken = false; 653 try { 654 result = shardedJedis.hgetAll(key); 655 656 } catch (Exception e) { 657 log.error(e.getMessage(), e); 658 broken = true; 659 } finally { 660 redisDataSource.returnResource(shardedJedis, broken); 661 } 662 return result; 663 } 664 665 // ================list ====== l表示 list或 left, r表示right==================== 666 public Long rpush(String key, String string) { 667 Long result = null; 668 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 669 if (shardedJedis == null) { 670 return result; 671 } 672 boolean broken = false; 673 try { 674 result = shardedJedis.rpush(key, string); 675 676 } catch (Exception e) { 677 log.error(e.getMessage(), e); 678 broken = true; 679 } finally { 680 redisDataSource.returnResource(shardedJedis, broken); 681 } 682 return result; 683 } 684 685 public Long lpush(String key, String string) { 686 Long result = null; 687 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 688 if (shardedJedis == null) { 689 return result; 690 } 691 boolean broken = false; 692 try { 693 result = shardedJedis.lpush(key, string); 694 695 } catch (Exception e) { 696 log.error(e.getMessage(), e); 697 broken = true; 698 } finally { 699 redisDataSource.returnResource(shardedJedis, broken); 700 } 701 return result; 702 } 703 704 public Long llen(String key) { 705 Long result = null; 706 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 707 if (shardedJedis == null) { 708 return result; 709 } 710 boolean broken = false; 711 try { 712 result = shardedJedis.llen(key); 713 714 } catch (Exception e) { 715 log.error(e.getMessage(), e); 716 broken = true; 717 } finally { 718 redisDataSource.returnResource(shardedJedis, broken); 719 } 720 return result; 721 } 722 723 public List<String> lrange(String key, long start, long end) { 724 List<String> result = null; 725 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 726 if (shardedJedis == null) { 727 return result; 728 } 729 boolean broken = false; 730 try { 731 result = shardedJedis.lrange(key, start, end); 732 733 } catch (Exception e) { 734 log.error(e.getMessage(), e); 735 broken = true; 736 } finally { 737 redisDataSource.returnResource(shardedJedis, broken); 738 } 739 return result; 740 } 741 742 public String ltrim(String key, long start, long end) { 743 String result = null; 744 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 745 if (shardedJedis == null) { 746 return result; 747 } 748 boolean broken = false; 749 try { 750 result = shardedJedis.ltrim(key, start, end); 751 752 } catch (Exception e) { 753 log.error(e.getMessage(), e); 754 broken = true; 755 } finally { 756 redisDataSource.returnResource(shardedJedis, broken); 757 } 758 return result; 759 } 760 761 public String lindex(String key, long index) { 762 String result = null; 763 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 764 if (shardedJedis == null) { 765 return result; 766 } 767 boolean broken = false; 768 try { 769 result = shardedJedis.lindex(key, index); 770 771 } catch (Exception e) { 772 log.error(e.getMessage(), e); 773 broken = true; 774 } finally { 775 redisDataSource.returnResource(shardedJedis, broken); 776 } 777 return result; 778 } 779 780 public String lset(String key, long index, String value) { 781 String result = null; 782 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 783 if (shardedJedis == null) { 784 return result; 785 } 786 boolean broken = false; 787 try { 788 result = shardedJedis.lset(key, index, value); 789 790 } catch (Exception e) { 791 log.error(e.getMessage(), e); 792 broken = true; 793 } finally { 794 redisDataSource.returnResource(shardedJedis, broken); 795 } 796 return result; 797 } 798 799 public Long lrem(String key, long count, String value) { 800 Long result = null; 801 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 802 if (shardedJedis == null) { 803 return result; 804 } 805 boolean broken = false; 806 try { 807 result = shardedJedis.lrem(key, count, value); 808 809 } catch (Exception e) { 810 log.error(e.getMessage(), e); 811 broken = true; 812 } finally { 813 redisDataSource.returnResource(shardedJedis, broken); 814 } 815 return result; 816 } 817 818 public String lpop(String key) { 819 String result = null; 820 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 821 if (shardedJedis == null) { 822 return result; 823 } 824 boolean broken = false; 825 try { 826 result = shardedJedis.lpop(key); 827 828 } catch (Exception e) { 829 log.error(e.getMessage(), e); 830 broken = true; 831 } finally { 832 redisDataSource.returnResource(shardedJedis, broken); 833 } 834 return result; 835 } 836 837 public String rpop(String key) { 838 String result = null; 839 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 840 if (shardedJedis == null) { 841 return result; 842 } 843 boolean broken = false; 844 try { 845 result = shardedJedis.rpop(key); 846 847 } catch (Exception e) { 848 log.error(e.getMessage(), e); 849 broken = true; 850 } finally { 851 redisDataSource.returnResource(shardedJedis, broken); 852 } 853 return result; 854 } 855 856 //return 1 add a not exist value , 857 //return 0 add a exist value 858 public Long sadd(String key, String member) { 859 Long result = null; 860 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 861 if (shardedJedis == null) { 862 return result; 863 } 864 boolean broken = false; 865 try { 866 result = shardedJedis.sadd(key, member); 867 868 } catch (Exception e) { 869 log.error(e.getMessage(), e); 870 broken = true; 871 } finally { 872 redisDataSource.returnResource(shardedJedis, broken); 873 } 874 return result; 875 } 876 877 public Set<String> smembers(String key) { 878 Set<String> result = null; 879 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 880 if (shardedJedis == null) { 881 return result; 882 } 883 boolean broken = false; 884 try { 885 result = shardedJedis.smembers(key); 886 887 } catch (Exception e) { 888 log.error(e.getMessage(), e); 889 broken = true; 890 } finally { 891 redisDataSource.returnResource(shardedJedis, broken); 892 } 893 return result; 894 } 895 896 public Long srem(String key, String member) { 897 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 898 899 Long result = null; 900 if (shardedJedis == null) { 901 return result; 902 } 903 boolean broken = false; 904 try { 905 result = shardedJedis.srem(key, member); 906 } catch (Exception e) { 907 log.error(e.getMessage(), e); 908 broken = true; 909 } finally { 910 redisDataSource.returnResource(shardedJedis, broken); 911 } 912 return result; 913 } 914 915 public String spop(String key) { 916 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 917 String result = null; 918 if (shardedJedis == null) { 919 return result; 920 } 921 boolean broken = false; 922 try { 923 result = shardedJedis.spop(key); 924 } catch (Exception e) { 925 log.error(e.getMessage(), e); 926 broken = true; 927 } finally { 928 redisDataSource.returnResource(shardedJedis, broken); 929 } 930 return result; 931 } 932 933 public Long scard(String key) { 934 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 935 Long result = null; 936 if (shardedJedis == null) { 937 return result; 938 } 939 boolean broken = false; 940 try { 941 result = shardedJedis.scard(key); 942 943 } catch (Exception e) { 944 log.error(e.getMessage(), e); 945 broken = true; 946 } finally { 947 redisDataSource.returnResource(shardedJedis, broken); 948 } 949 return result; 950 } 951 952 public Boolean sismember(String key, String member) { 953 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 954 Boolean result = null; 955 if (shardedJedis == null) { 956 return result; 957 } 958 boolean broken = false; 959 try { 960 result = shardedJedis.sismember(key, member); 961 } catch (Exception e) { 962 log.error(e.getMessage(), e); 963 broken = true; 964 } finally { 965 redisDataSource.returnResource(shardedJedis, broken); 966 } 967 return result; 968 } 969 970 public String srandmember(String key) { 971 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 972 String result = null; 973 if (shardedJedis == null) { 974 return result; 975 } 976 boolean broken = false; 977 try { 978 result = shardedJedis.srandmember(key); 979 } catch (Exception e) { 980 log.error(e.getMessage(), e); 981 broken = true; 982 } finally { 983 redisDataSource.returnResource(shardedJedis, broken); 984 } 985 return result; 986 } 987 988 public Long zadd(String key, double score, String member) { 989 Long result = null; 990 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 991 if (shardedJedis == null) { 992 return result; 993 } 994 boolean broken = false; 995 try { 996 result = shardedJedis.zadd(key, score, member); 997 } catch (Exception e) { 998 log.error(e.getMessage(), e); 999 broken = true; 1000 } finally { 1001 redisDataSource.returnResource(shardedJedis, broken); 1002 } 1003 return result; 1004 } 1005 1006 public Set<String> zrange(String key, int start, int end) { 1007 Set<String> result = null; 1008 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1009 if (shardedJedis == null) { 1010 return result; 1011 } 1012 boolean broken = false; 1013 try { 1014 result = shardedJedis.zrange(key, start, end); 1015 } catch (Exception e) { 1016 log.error(e.getMessage(), e); 1017 broken = true; 1018 } finally { 1019 redisDataSource.returnResource(shardedJedis, broken); 1020 } 1021 return result; 1022 } 1023 1024 public Long zrem(String key, String member) { 1025 Long result = null; 1026 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1027 if (shardedJedis == null) { 1028 return result; 1029 } 1030 boolean broken = false; 1031 try { 1032 result = shardedJedis.zrem(key, member); 1033 } catch (Exception e) { 1034 log.error(e.getMessage(), e); 1035 broken = true; 1036 } finally { 1037 redisDataSource.returnResource(shardedJedis, broken); 1038 } 1039 return result; 1040 } 1041 1042 public Double zincrby(String key, double score, String member) { 1043 Double result = null; 1044 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1045 if (shardedJedis == null) { 1046 return result; 1047 } 1048 boolean broken = false; 1049 try { 1050 1051 result = shardedJedis.zincrby(key, score, member); 1052 1053 } catch (Exception e) { 1054 log.error(e.getMessage(), e); 1055 broken = true; 1056 } finally { 1057 redisDataSource.returnResource(shardedJedis, broken); 1058 } 1059 return result; 1060 } 1061 1062 public Long zrank(String key, String member) { 1063 Long result = null; 1064 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1065 if (shardedJedis == null) { 1066 return result; 1067 } 1068 boolean broken = false; 1069 try { 1070 1071 result = shardedJedis.zrank(key, member); 1072 1073 } catch (Exception e) { 1074 log.error(e.getMessage(), e); 1075 broken = true; 1076 } finally { 1077 redisDataSource.returnResource(shardedJedis, broken); 1078 } 1079 return result; 1080 } 1081 1082 public Long zrevrank(String key, String member) { 1083 Long result = null; 1084 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1085 if (shardedJedis == null) { 1086 return result; 1087 } 1088 boolean broken = false; 1089 try { 1090 1091 result = shardedJedis.zrevrank(key, member); 1092 1093 } catch (Exception e) { 1094 log.error(e.getMessage(), e); 1095 broken = true; 1096 } finally { 1097 redisDataSource.returnResource(shardedJedis, broken); 1098 } 1099 return result; 1100 } 1101 1102 public Set<String> zrevrange(String key, int start, int end) { 1103 Set<String> result = null; 1104 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1105 if (shardedJedis == null) { 1106 return result; 1107 } 1108 boolean broken = false; 1109 try { 1110 1111 result = shardedJedis.zrevrange(key, start, end); 1112 1113 } catch (Exception e) { 1114 log.error(e.getMessage(), e); 1115 broken = true; 1116 } finally { 1117 redisDataSource.returnResource(shardedJedis, broken); 1118 } 1119 return result; 1120 } 1121 1122 public Set<Tuple> zrangeWithScores(String key, int start, int end) { 1123 Set<Tuple> result = null; 1124 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1125 if (shardedJedis == null) { 1126 return result; 1127 } 1128 boolean broken = false; 1129 try { 1130 1131 result = shardedJedis.zrangeWithScores(key, start, end); 1132 1133 } catch (Exception e) { 1134 log.error(e.getMessage(), e); 1135 broken = true; 1136 } finally { 1137 redisDataSource.returnResource(shardedJedis, broken); 1138 } 1139 return result; 1140 } 1141 1142 public Set<Tuple> zrevrangeWithScores(String key, int start, int end) { 1143 Set<Tuple> result = null; 1144 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1145 if (shardedJedis == null) { 1146 return result; 1147 } 1148 boolean broken = false; 1149 try { 1150 1151 result = shardedJedis.zrevrangeWithScores(key, start, end); 1152 1153 } catch (Exception e) { 1154 log.error(e.getMessage(), e); 1155 broken = true; 1156 } finally { 1157 redisDataSource.returnResource(shardedJedis, broken); 1158 } 1159 return result; 1160 } 1161 1162 public Long zcard(String key) { 1163 Long result = null; 1164 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1165 if (shardedJedis == null) { 1166 return result; 1167 } 1168 boolean broken = false; 1169 try { 1170 1171 result = shardedJedis.zcard(key); 1172 1173 } catch (Exception e) { 1174 log.error(e.getMessage(), e); 1175 broken = true; 1176 } finally { 1177 redisDataSource.returnResource(shardedJedis, broken); 1178 } 1179 return result; 1180 } 1181 1182 public Double zscore(String key, String member) { 1183 Double result = null; 1184 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1185 if (shardedJedis == null) { 1186 return result; 1187 } 1188 boolean broken = false; 1189 try { 1190 1191 result = shardedJedis.zscore(key, member); 1192 1193 } catch (Exception e) { 1194 log.error(e.getMessage(), e); 1195 broken = true; 1196 } finally { 1197 redisDataSource.returnResource(shardedJedis, broken); 1198 } 1199 return result; 1200 } 1201 1202 public List<String> sort(String key) { 1203 List<String> result = null; 1204 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1205 if (shardedJedis == null) { 1206 return result; 1207 } 1208 boolean broken = false; 1209 try { 1210 1211 result = shardedJedis.sort(key); 1212 1213 } catch (Exception e) { 1214 log.error(e.getMessage(), e); 1215 broken = true; 1216 } finally { 1217 redisDataSource.returnResource(shardedJedis, broken); 1218 } 1219 return result; 1220 } 1221 1222 public List<String> sort(String key, SortingParams sortingParameters) { 1223 List<String> result = null; 1224 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1225 if (shardedJedis == null) { 1226 return result; 1227 } 1228 boolean broken = false; 1229 try { 1230 1231 result = shardedJedis.sort(key, sortingParameters); 1232 1233 } catch (Exception e) { 1234 log.error(e.getMessage(), e); 1235 broken = true; 1236 } finally { 1237 redisDataSource.returnResource(shardedJedis, broken); 1238 } 1239 return result; 1240 } 1241 1242 public Long zcount(String key, double min, double max) { 1243 Long result = null; 1244 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1245 if (shardedJedis == null) { 1246 return result; 1247 } 1248 boolean broken = false; 1249 try { 1250 1251 result = shardedJedis.zcount(key, min, max); 1252 1253 } catch (Exception e) { 1254 log.error(e.getMessage(), e); 1255 broken = true; 1256 } finally { 1257 redisDataSource.returnResource(shardedJedis, broken); 1258 } 1259 return result; 1260 } 1261 1262 public Set<String> zrangeByScore(String key, double min, double max) { 1263 Set<String> result = null; 1264 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1265 if (shardedJedis == null) { 1266 return result; 1267 } 1268 boolean broken = false; 1269 try { 1270 1271 result = shardedJedis.zrangeByScore(key, min, max); 1272 1273 } catch (Exception e) { 1274 log.error(e.getMessage(), e); 1275 broken = true; 1276 } finally { 1277 redisDataSource.returnResource(shardedJedis, broken); 1278 } 1279 return result; 1280 } 1281 1282 public Set<String> zrevrangeByScore(String key, double max, double min) { 1283 Set<String> result = null; 1284 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1285 if (shardedJedis == null) { 1286 return result; 1287 } 1288 boolean broken = false; 1289 try { 1290 1291 result = shardedJedis.zrevrangeByScore(key, max, min); 1292 1293 } catch (Exception e) { 1294 log.error(e.getMessage(), e); 1295 broken = true; 1296 } finally { 1297 redisDataSource.returnResource(shardedJedis, broken); 1298 } 1299 return result; 1300 } 1301 1302 public Set<String> zrangeByScore(String key, double min, double max, int offset, int count) { 1303 Set<String> result = null; 1304 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1305 if (shardedJedis == null) { 1306 return result; 1307 } 1308 boolean broken = false; 1309 try { 1310 1311 result = shardedJedis.zrangeByScore(key, min, max, offset, count); 1312 1313 } catch (Exception e) { 1314 log.error(e.getMessage(), e); 1315 broken = true; 1316 } finally { 1317 redisDataSource.returnResource(shardedJedis, broken); 1318 } 1319 return result; 1320 } 1321 1322 public Set<String> zrevrangeByScore(String key, double max, double min, int offset, int count) { 1323 Set<String> result = null; 1324 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1325 if (shardedJedis == null) { 1326 return result; 1327 } 1328 boolean broken = false; 1329 try { 1330 1331 result = shardedJedis.zrevrangeByScore(key, max, min, offset, count); 1332 1333 } catch (Exception e) { 1334 log.error(e.getMessage(), e); 1335 broken = true; 1336 } finally { 1337 redisDataSource.returnResource(shardedJedis, broken); 1338 } 1339 return result; 1340 } 1341 1342 public Set<Tuple> zrangeByScoreWithScores(String key, double min, double max) { 1343 Set<Tuple> result = null; 1344 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1345 if (shardedJedis == null) { 1346 return result; 1347 } 1348 boolean broken = false; 1349 try { 1350 1351 result = shardedJedis.zrangeByScoreWithScores(key, min, max); 1352 1353 } catch (Exception e) { 1354 log.error(e.getMessage(), e); 1355 broken = true; 1356 } finally { 1357 redisDataSource.returnResource(shardedJedis, broken); 1358 } 1359 return result; 1360 } 1361 1362 public Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min) { 1363 Set<Tuple> result = null; 1364 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1365 if (shardedJedis == null) { 1366 return result; 1367 } 1368 boolean broken = false; 1369 try { 1370 1371 result = shardedJedis.zrevrangeByScoreWithScores(key, max, min); 1372 1373 } catch (Exception e) { 1374 log.error(e.getMessage(), e); 1375 broken = true; 1376 } finally { 1377 redisDataSource.returnResource(shardedJedis, broken); 1378 } 1379 return result; 1380 } 1381 1382 public Set<Tuple> zrangeByScoreWithScores(String key, double min, double max, int offset, int count) { 1383 Set<Tuple> result = null; 1384 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1385 if (shardedJedis == null) { 1386 return result; 1387 } 1388 boolean broken = false; 1389 try { 1390 1391 result = shardedJedis.zrangeByScoreWithScores(key, min, max, offset, count); 1392 1393 } catch (Exception e) { 1394 log.error(e.getMessage(), e); 1395 broken = true; 1396 } finally { 1397 redisDataSource.returnResource(shardedJedis, broken); 1398 } 1399 return result; 1400 } 1401 1402 public Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min, int offset, int count) { 1403 Set<Tuple> result = null; 1404 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1405 if (shardedJedis == null) { 1406 return result; 1407 } 1408 boolean broken = false; 1409 try { 1410 1411 result = shardedJedis.zrevrangeByScoreWithScores(key, max, min, offset, count); 1412 1413 } catch (Exception e) { 1414 log.error(e.getMessage(), e); 1415 broken = true; 1416 } finally { 1417 redisDataSource.returnResource(shardedJedis, broken); 1418 } 1419 return result; 1420 } 1421 1422 public Long zremrangeByRank(String key, int start, int end) { 1423 Long result = null; 1424 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1425 if (shardedJedis == null) { 1426 return result; 1427 } 1428 boolean broken = false; 1429 try { 1430 1431 result = shardedJedis.zremrangeByRank(key, start, end); 1432 1433 } catch (Exception e) { 1434 log.error(e.getMessage(), e); 1435 broken = true; 1436 } finally { 1437 redisDataSource.returnResource(shardedJedis, broken); 1438 } 1439 return result; 1440 } 1441 1442 public Long zremrangeByScore(String key, double start, double end) { 1443 Long result = null; 1444 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1445 if (shardedJedis == null) { 1446 return result; 1447 } 1448 boolean broken = false; 1449 try { 1450 1451 result = shardedJedis.zremrangeByScore(key, start, end); 1452 1453 } catch (Exception e) { 1454 log.error(e.getMessage(), e); 1455 broken = true; 1456 } finally { 1457 redisDataSource.returnResource(shardedJedis, broken); 1458 } 1459 return result; 1460 } 1461 1462 public Long linsert(String key, LIST_POSITION where, String pivot, String value) { 1463 Long result = null; 1464 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1465 if (shardedJedis == null) { 1466 return result; 1467 } 1468 boolean broken = false; 1469 try { 1470 1471 result = shardedJedis.linsert(key, where, pivot, value); 1472 1473 } catch (Exception e) { 1474 log.error(e.getMessage(), e); 1475 broken = true; 1476 } finally { 1477 redisDataSource.returnResource(shardedJedis, broken); 1478 } 1479 return result; 1480 } 1481 1482 public String set(byte[] key, byte[] value) { 1483 String result = null; 1484 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1485 if (shardedJedis == null) { 1486 return result; 1487 } 1488 boolean broken = false; 1489 try { 1490 1491 result = shardedJedis.set(key, value); 1492 1493 } catch (Exception e) { 1494 log.error(e.getMessage(), e); 1495 broken = true; 1496 } finally { 1497 redisDataSource.returnResource(shardedJedis, broken); 1498 } 1499 return result; 1500 } 1501 1502 public byte[] get(byte[] key) { 1503 byte[] result = null; 1504 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1505 if (shardedJedis == null) { 1506 return result; 1507 } 1508 boolean broken = false; 1509 try { 1510 1511 result = shardedJedis.get(key); 1512 1513 } catch (Exception e) { 1514 log.error(e.getMessage(), e); 1515 broken = true; 1516 } finally { 1517 redisDataSource.returnResource(shardedJedis, broken); 1518 } 1519 return result; 1520 } 1521 1522 public Boolean exists(byte[] key) { 1523 Boolean result = false; 1524 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1525 if (shardedJedis == null) { 1526 return result; 1527 } 1528 boolean broken = false; 1529 try { 1530 1531 result = shardedJedis.exists(key); 1532 1533 } catch (Exception e) { 1534 log.error(e.getMessage(), e); 1535 broken = true; 1536 } finally { 1537 redisDataSource.returnResource(shardedJedis, broken); 1538 } 1539 return result; 1540 } 1541 1542 public String type(byte[] key) { 1543 String result = null; 1544 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1545 if (shardedJedis == null) { 1546 return result; 1547 } 1548 boolean broken = false; 1549 try { 1550 1551 result = shardedJedis.type(key); 1552 1553 } catch (Exception e) { 1554 log.error(e.getMessage(), e); 1555 broken = true; 1556 } finally { 1557 redisDataSource.returnResource(shardedJedis, broken); 1558 } 1559 return result; 1560 } 1561 1562 public Long expire(byte[] key, int seconds) { 1563 Long result = null; 1564 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1565 if (shardedJedis == null) { 1566 return result; 1567 } 1568 boolean broken = false; 1569 try { 1570 1571 result = shardedJedis.expire(key, seconds); 1572 1573 } catch (Exception e) { 1574 log.error(e.getMessage(), e); 1575 broken = true; 1576 } finally { 1577 redisDataSource.returnResource(shardedJedis, broken); 1578 } 1579 return result; 1580 } 1581 1582 public Long expireAt(byte[] key, long unixTime) { 1583 Long result = null; 1584 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1585 if (shardedJedis == null) { 1586 return result; 1587 } 1588 boolean broken = false; 1589 try { 1590 1591 result = shardedJedis.expireAt(key, unixTime); 1592 1593 } catch (Exception e) { 1594 log.error(e.getMessage(), e); 1595 broken = true; 1596 } finally { 1597 redisDataSource.returnResource(shardedJedis, broken); 1598 } 1599 return result; 1600 } 1601 1602 public Long ttl(byte[] key) { 1603 Long result = null; 1604 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1605 if (shardedJedis == null) { 1606 return result; 1607 } 1608 boolean broken = false; 1609 try { 1610 1611 result = shardedJedis.ttl(key); 1612 1613 } catch (Exception e) { 1614 log.error(e.getMessage(), e); 1615 broken = true; 1616 } finally { 1617 redisDataSource.returnResource(shardedJedis, broken); 1618 } 1619 return result; 1620 } 1621 1622 public byte[] getSet(byte[] key, byte[] value) { 1623 byte[] result = null; 1624 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1625 if (shardedJedis == null) { 1626 return result; 1627 } 1628 boolean broken = false; 1629 try { 1630 1631 result = shardedJedis.getSet(key, value); 1632 1633 } catch (Exception e) { 1634 log.error(e.getMessage(), e); 1635 broken = true; 1636 } finally { 1637 redisDataSource.returnResource(shardedJedis, broken); 1638 } 1639 return result; 1640 } 1641 1642 public Long setnx(byte[] key, byte[] value) { 1643 Long result = null; 1644 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1645 if (shardedJedis == null) { 1646 return result; 1647 } 1648 boolean broken = false; 1649 try { 1650 1651 result = shardedJedis.setnx(key, value); 1652 1653 } catch (Exception e) { 1654 log.error(e.getMessage(), e); 1655 broken = true; 1656 } finally { 1657 redisDataSource.returnResource(shardedJedis, broken); 1658 } 1659 return result; 1660 } 1661 1662 public String setex(byte[] key, int seconds, byte[] value) { 1663 String result = null; 1664 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1665 if (shardedJedis == null) { 1666 return result; 1667 } 1668 boolean broken = false; 1669 try { 1670 1671 result = shardedJedis.setex(key, seconds, value); 1672 1673 } catch (Exception e) { 1674 log.error(e.getMessage(), e); 1675 broken = true; 1676 } finally { 1677 redisDataSource.returnResource(shardedJedis, broken); 1678 } 1679 return result; 1680 } 1681 1682 public Long decrBy(byte[] key, long integer) { 1683 Long result = null; 1684 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1685 if (shardedJedis == null) { 1686 return result; 1687 } 1688 boolean broken = false; 1689 try { 1690 1691 result = shardedJedis.decrBy(key, integer); 1692 1693 } catch (Exception e) { 1694 log.error(e.getMessage(), e); 1695 broken = true; 1696 } finally { 1697 redisDataSource.returnResource(shardedJedis, broken); 1698 } 1699 return result; 1700 } 1701 1702 public Long decr(byte[] key) { 1703 Long result = null; 1704 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1705 if (shardedJedis == null) { 1706 return result; 1707 } 1708 boolean broken = false; 1709 try { 1710 1711 result = shardedJedis.decr(key); 1712 1713 } catch (Exception e) { 1714 log.error(e.getMessage(), e); 1715 broken = true; 1716 } finally { 1717 redisDataSource.returnResource(shardedJedis, broken); 1718 } 1719 return result; 1720 } 1721 1722 public Long incrBy(byte[] key, long integer) { 1723 Long result = null; 1724 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1725 if (shardedJedis == null) { 1726 return result; 1727 } 1728 boolean broken = false; 1729 try { 1730 1731 result = shardedJedis.incrBy(key, integer); 1732 1733 } catch (Exception e) { 1734 log.error(e.getMessage(), e); 1735 broken = true; 1736 } finally { 1737 redisDataSource.returnResource(shardedJedis, broken); 1738 } 1739 return result; 1740 } 1741 1742 public Long incr(byte[] key) { 1743 Long result = null; 1744 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1745 if (shardedJedis == null) { 1746 return result; 1747 } 1748 boolean broken = false; 1749 try { 1750 1751 result = shardedJedis.incr(key); 1752 1753 } catch (Exception e) { 1754 log.error(e.getMessage(), e); 1755 broken = true; 1756 } finally { 1757 redisDataSource.returnResource(shardedJedis, broken); 1758 } 1759 return result; 1760 } 1761 1762 public Long append(byte[] key, byte[] value) { 1763 Long result = null; 1764 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1765 if (shardedJedis == null) { 1766 return result; 1767 } 1768 boolean broken = false; 1769 try { 1770 1771 result = shardedJedis.append(key, value); 1772 1773 } catch (Exception e) { 1774 log.error(e.getMessage(), e); 1775 broken = true; 1776 } finally { 1777 redisDataSource.returnResource(shardedJedis, broken); 1778 } 1779 return result; 1780 } 1781 1782 public byte[] substr(byte[] key, int start, int end) { 1783 byte[] result = null; 1784 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1785 if (shardedJedis == null) { 1786 return result; 1787 } 1788 boolean broken = false; 1789 try { 1790 1791 result = shardedJedis.substr(key, start, end); 1792 1793 } catch (Exception e) { 1794 log.error(e.getMessage(), e); 1795 broken = true; 1796 } finally { 1797 redisDataSource.returnResource(shardedJedis, broken); 1798 } 1799 return result; 1800 } 1801 1802 public Long hset(byte[] key, byte[] field, byte[] value) { 1803 Long result = null; 1804 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1805 if (shardedJedis == null) { 1806 return result; 1807 } 1808 boolean broken = false; 1809 try { 1810 1811 result = shardedJedis.hset(key, field, value); 1812 1813 } catch (Exception e) { 1814 log.error(e.getMessage(), e); 1815 broken = true; 1816 } finally { 1817 redisDataSource.returnResource(shardedJedis, broken); 1818 } 1819 return result; 1820 } 1821 1822 public byte[] hget(byte[] key, byte[] field) { 1823 byte[] result = null; 1824 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1825 if (shardedJedis == null) { 1826 return result; 1827 } 1828 boolean broken = false; 1829 try { 1830 1831 result = shardedJedis.hget(key, field); 1832 1833 } catch (Exception e) { 1834 log.error(e.getMessage(), e); 1835 broken = true; 1836 } finally { 1837 redisDataSource.returnResource(shardedJedis, broken); 1838 } 1839 return result; 1840 } 1841 1842 public Long hsetnx(byte[] key, byte[] field, byte[] value) { 1843 Long result = null; 1844 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1845 if (shardedJedis == null) { 1846 return result; 1847 } 1848 boolean broken = false; 1849 try { 1850 1851 result = shardedJedis.hsetnx(key, field, value); 1852 1853 } catch (Exception e) { 1854 1855 log.error(e.getMessage(), e); 1856 broken = true; 1857 } finally { 1858 redisDataSource.returnResource(shardedJedis, broken); 1859 } 1860 return result; 1861 } 1862 1863 public String hmset(byte[] key, Map<byte[], byte[]> hash) { 1864 String result = null; 1865 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1866 if (shardedJedis == null) { 1867 return result; 1868 } 1869 boolean broken = false; 1870 try { 1871 1872 result = shardedJedis.hmset(key, hash); 1873 1874 } catch (Exception e) { 1875 1876 log.error(e.getMessage(), e); 1877 broken = true; 1878 } finally { 1879 redisDataSource.returnResource(shardedJedis, broken); 1880 } 1881 return result; 1882 } 1883 1884 public List<byte[]> hmget(byte[] key, byte[]... fields) { 1885 List<byte[]> result = null; 1886 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1887 if (shardedJedis == null) { 1888 return result; 1889 } 1890 boolean broken = false; 1891 try { 1892 1893 result = shardedJedis.hmget(key, fields); 1894 1895 } catch (Exception e) { 1896 1897 log.error(e.getMessage(), e); 1898 broken = true; 1899 } finally { 1900 redisDataSource.returnResource(shardedJedis, broken); 1901 } 1902 return result; 1903 } 1904 1905 public Long hincrBy(byte[] key, byte[] field, long value) { 1906 Long result = null; 1907 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1908 if (shardedJedis == null) { 1909 return result; 1910 } 1911 boolean broken = false; 1912 try { 1913 1914 result = shardedJedis.hincrBy(key, field, value); 1915 1916 } catch (Exception e) { 1917 1918 log.error(e.getMessage(), e); 1919 broken = true; 1920 } finally { 1921 redisDataSource.returnResource(shardedJedis, broken); 1922 } 1923 return result; 1924 } 1925 1926 public Boolean hexists(byte[] key, byte[] field) { 1927 Boolean result = false; 1928 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1929 if (shardedJedis == null) { 1930 return result; 1931 } 1932 boolean broken = false; 1933 try { 1934 1935 result = shardedJedis.hexists(key, field); 1936 1937 } catch (Exception e) { 1938 1939 log.error(e.getMessage(), e); 1940 broken = true; 1941 } finally { 1942 redisDataSource.returnResource(shardedJedis, broken); 1943 } 1944 return result; 1945 } 1946 1947 public Long hdel(byte[] key, byte[] field) { 1948 Long result = null; 1949 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1950 if (shardedJedis == null) { 1951 return result; 1952 } 1953 boolean broken = false; 1954 try { 1955 1956 result = shardedJedis.hdel(key, field); 1957 1958 } catch (Exception e) { 1959 1960 log.error(e.getMessage(), e); 1961 broken = true; 1962 } finally { 1963 redisDataSource.returnResource(shardedJedis, broken); 1964 } 1965 return result; 1966 } 1967 1968 public Long hlen(byte[] key) { 1969 Long result = null; 1970 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1971 if (shardedJedis == null) { 1972 return result; 1973 } 1974 boolean broken = false; 1975 try { 1976 1977 result = shardedJedis.hlen(key); 1978 1979 } catch (Exception e) { 1980 1981 log.error(e.getMessage(), e); 1982 broken = true; 1983 } finally { 1984 redisDataSource.returnResource(shardedJedis, broken); 1985 } 1986 return result; 1987 } 1988 1989 public Set<byte[]> hkeys(byte[] key) { 1990 Set<byte[]> result = null; 1991 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 1992 if (shardedJedis == null) { 1993 return result; 1994 } 1995 boolean broken = false; 1996 try { 1997 1998 result = shardedJedis.hkeys(key); 1999 2000 } catch (Exception e) { 2001 2002 log.error(e.getMessage(), e); 2003 broken = true; 2004 } finally { 2005 redisDataSource.returnResource(shardedJedis, broken); 2006 } 2007 return result; 2008 } 2009 2010 public Collection<byte[]> hvals(byte[] key) { 2011 Collection<byte[]> result = null; 2012 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2013 if (shardedJedis == null) { 2014 return result; 2015 } 2016 boolean broken = false; 2017 try { 2018 2019 result = shardedJedis.hvals(key); 2020 2021 } catch (Exception e) { 2022 2023 log.error(e.getMessage(), e); 2024 broken = true; 2025 } finally { 2026 redisDataSource.returnResource(shardedJedis, broken); 2027 } 2028 return result; 2029 } 2030 2031 public Map<byte[], byte[]> hgetAll(byte[] key) { 2032 Map<byte[], byte[]> result = null; 2033 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2034 if (shardedJedis == null) { 2035 return result; 2036 } 2037 boolean broken = false; 2038 try { 2039 2040 result = shardedJedis.hgetAll(key); 2041 2042 } catch (Exception e) { 2043 2044 log.error(e.getMessage(), e); 2045 broken = true; 2046 } finally { 2047 redisDataSource.returnResource(shardedJedis, broken); 2048 } 2049 return result; 2050 } 2051 2052 public Long rpush(byte[] key, byte[] string) { 2053 Long result = null; 2054 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2055 if (shardedJedis == null) { 2056 return result; 2057 } 2058 boolean broken = false; 2059 try { 2060 2061 result = shardedJedis.rpush(key, string); 2062 2063 } catch (Exception e) { 2064 2065 log.error(e.getMessage(), e); 2066 broken = true; 2067 } finally { 2068 redisDataSource.returnResource(shardedJedis, broken); 2069 } 2070 return result; 2071 } 2072 2073 public Long lpush(byte[] key, byte[] string) { 2074 Long result = null; 2075 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2076 if (shardedJedis == null) { 2077 return result; 2078 } 2079 boolean broken = false; 2080 try { 2081 2082 result = shardedJedis.lpush(key, string); 2083 2084 } catch (Exception e) { 2085 2086 log.error(e.getMessage(), e); 2087 broken = true; 2088 } finally { 2089 redisDataSource.returnResource(shardedJedis, broken); 2090 } 2091 return result; 2092 } 2093 2094 public Long llen(byte[] key) { 2095 Long result = null; 2096 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2097 if (shardedJedis == null) { 2098 return result; 2099 } 2100 boolean broken = false; 2101 try { 2102 2103 result = shardedJedis.llen(key); 2104 2105 } catch (Exception e) { 2106 2107 log.error(e.getMessage(), e); 2108 broken = true; 2109 } finally { 2110 redisDataSource.returnResource(shardedJedis, broken); 2111 } 2112 return result; 2113 } 2114 2115 public List<byte[]> lrange(byte[] key, int start, int end) { 2116 List<byte[]> result = null; 2117 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2118 if (shardedJedis == null) { 2119 return result; 2120 } 2121 boolean broken = false; 2122 try { 2123 2124 result = shardedJedis.lrange(key, start, end); 2125 2126 } catch (Exception e) { 2127 2128 log.error(e.getMessage(), e); 2129 broken = true; 2130 } finally { 2131 redisDataSource.returnResource(shardedJedis, broken); 2132 } 2133 return result; 2134 } 2135 2136 public String ltrim(byte[] key, int start, int end) { 2137 String result = null; 2138 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2139 if (shardedJedis == null) { 2140 return result; 2141 } 2142 boolean broken = false; 2143 try { 2144 2145 result = shardedJedis.ltrim(key, start, end); 2146 2147 } catch (Exception e) { 2148 log.error(e.getMessage(), e); 2149 broken = true; 2150 } finally { 2151 redisDataSource.returnResource(shardedJedis, broken); 2152 } 2153 return result; 2154 } 2155 2156 public byte[] lindex(byte[] key, int index) { 2157 byte[] result = null; 2158 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2159 if (shardedJedis == null) { 2160 return result; 2161 } 2162 boolean broken = false; 2163 try { 2164 2165 result = shardedJedis.lindex(key, index); 2166 2167 } catch (Exception e) { 2168 2169 log.error(e.getMessage(), e); 2170 broken = true; 2171 } finally { 2172 redisDataSource.returnResource(shardedJedis, broken); 2173 } 2174 return result; 2175 } 2176 2177 public String lset(byte[] key, int index, byte[] value) { 2178 String result = null; 2179 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2180 if (shardedJedis == null) { 2181 return result; 2182 } 2183 boolean broken = false; 2184 try { 2185 2186 result = shardedJedis.lset(key, index, value); 2187 2188 } catch (Exception e) { 2189 2190 log.error(e.getMessage(), e); 2191 broken = true; 2192 } finally { 2193 redisDataSource.returnResource(shardedJedis, broken); 2194 } 2195 return result; 2196 } 2197 2198 public Long lrem(byte[] key, int count, byte[] value) { 2199 Long result = null; 2200 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2201 if (shardedJedis == null) { 2202 return result; 2203 } 2204 boolean broken = false; 2205 try { 2206 2207 result = shardedJedis.lrem(key, count, value); 2208 2209 } catch (Exception e) { 2210 2211 log.error(e.getMessage(), e); 2212 broken = true; 2213 } finally { 2214 redisDataSource.returnResource(shardedJedis, broken); 2215 } 2216 return result; 2217 } 2218 2219 public byte[] lpop(byte[] key) { 2220 byte[] result = null; 2221 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2222 if (shardedJedis == null) { 2223 return result; 2224 } 2225 boolean broken = false; 2226 try { 2227 2228 result = shardedJedis.lpop(key); 2229 2230 } catch (Exception e) { 2231 2232 log.error(e.getMessage(), e); 2233 broken = true; 2234 } finally { 2235 redisDataSource.returnResource(shardedJedis, broken); 2236 } 2237 return result; 2238 } 2239 2240 public byte[] rpop(byte[] key) { 2241 byte[] result = null; 2242 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2243 if (shardedJedis == null) { 2244 return result; 2245 } 2246 boolean broken = false; 2247 try { 2248 2249 result = shardedJedis.rpop(key); 2250 2251 } catch (Exception e) { 2252 2253 log.error(e.getMessage(), e); 2254 broken = true; 2255 } finally { 2256 redisDataSource.returnResource(shardedJedis, broken); 2257 } 2258 return result; 2259 } 2260 2261 public Long sadd(byte[] key, byte[] member) { 2262 Long result = null; 2263 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2264 if (shardedJedis == null) { 2265 return result; 2266 } 2267 boolean broken = false; 2268 try { 2269 2270 result = shardedJedis.sadd(key, member); 2271 2272 } catch (Exception e) { 2273 2274 log.error(e.getMessage(), e); 2275 broken = true; 2276 } finally { 2277 redisDataSource.returnResource(shardedJedis, broken); 2278 } 2279 return result; 2280 } 2281 2282 public Set<byte[]> smembers(byte[] key) { 2283 Set<byte[]> result = null; 2284 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2285 if (shardedJedis == null) { 2286 return result; 2287 } 2288 boolean broken = false; 2289 try { 2290 2291 result = shardedJedis.smembers(key); 2292 2293 } catch (Exception e) { 2294 2295 log.error(e.getMessage(), e); 2296 broken = true; 2297 } finally { 2298 redisDataSource.returnResource(shardedJedis, broken); 2299 } 2300 return result; 2301 } 2302 2303 public Long srem(byte[] key, byte[] member) { 2304 Long result = null; 2305 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2306 if (shardedJedis == null) { 2307 return result; 2308 } 2309 boolean broken = false; 2310 try { 2311 2312 result = shardedJedis.srem(key, member); 2313 2314 } catch (Exception e) { 2315 2316 log.error(e.getMessage(), e); 2317 broken = true; 2318 } finally { 2319 redisDataSource.returnResource(shardedJedis, broken); 2320 } 2321 return result; 2322 } 2323 2324 public byte[] spop(byte[] key) { 2325 byte[] result = null; 2326 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2327 if (shardedJedis == null) { 2328 return result; 2329 } 2330 boolean broken = false; 2331 try { 2332 2333 result = shardedJedis.spop(key); 2334 2335 } catch (Exception e) { 2336 2337 log.error(e.getMessage(), e); 2338 broken = true; 2339 } finally { 2340 redisDataSource.returnResource(shardedJedis, broken); 2341 } 2342 return result; 2343 } 2344 2345 public Long scard(byte[] key) { 2346 Long result = null; 2347 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2348 if (shardedJedis == null) { 2349 return result; 2350 } 2351 boolean broken = false; 2352 try { 2353 2354 result = shardedJedis.scard(key); 2355 2356 } catch (Exception e) { 2357 2358 log.error(e.getMessage(), e); 2359 broken = true; 2360 } finally { 2361 redisDataSource.returnResource(shardedJedis, broken); 2362 } 2363 return result; 2364 } 2365 2366 public Boolean sismember(byte[] key, byte[] member) { 2367 Boolean result = false; 2368 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2369 if (shardedJedis == null) { 2370 return result; 2371 } 2372 boolean broken = false; 2373 try { 2374 2375 result = shardedJedis.sismember(key, member); 2376 2377 } catch (Exception e) { 2378 2379 log.error(e.getMessage(), e); 2380 broken = true; 2381 } finally { 2382 redisDataSource.returnResource(shardedJedis, broken); 2383 } 2384 return result; 2385 } 2386 2387 public byte[] srandmember(byte[] key) { 2388 byte[] result = null; 2389 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2390 if (shardedJedis == null) { 2391 return result; 2392 } 2393 boolean broken = false; 2394 try { 2395 2396 result = shardedJedis.srandmember(key); 2397 2398 } catch (Exception e) { 2399 2400 log.error(e.getMessage(), e); 2401 broken = true; 2402 } finally { 2403 redisDataSource.returnResource(shardedJedis, broken); 2404 } 2405 return result; 2406 } 2407 2408 public Long zadd(byte[] key, double score, byte[] member) { 2409 Long result = null; 2410 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2411 if (shardedJedis == null) { 2412 return result; 2413 } 2414 boolean broken = false; 2415 try { 2416 2417 result = shardedJedis.zadd(key, score, member); 2418 2419 } catch (Exception e) { 2420 2421 log.error(e.getMessage(), e); 2422 broken = true; 2423 } finally { 2424 redisDataSource.returnResource(shardedJedis, broken); 2425 } 2426 return result; 2427 } 2428 2429 public Set<byte[]> zrange(byte[] key, int start, int end) { 2430 Set<byte[]> result = null; 2431 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2432 if (shardedJedis == null) { 2433 return result; 2434 } 2435 boolean broken = false; 2436 try { 2437 2438 result = shardedJedis.zrange(key, start, end); 2439 2440 } catch (Exception e) { 2441 2442 log.error(e.getMessage(), e); 2443 broken = true; 2444 } finally { 2445 redisDataSource.returnResource(shardedJedis, broken); 2446 } 2447 return result; 2448 } 2449 2450 public Long zrem(byte[] key, byte[] member) { 2451 Long result = null; 2452 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2453 if (shardedJedis == null) { 2454 return result; 2455 } 2456 boolean broken = false; 2457 try { 2458 2459 result = shardedJedis.zrem(key, member); 2460 2461 } catch (Exception e) { 2462 2463 log.error(e.getMessage(), e); 2464 broken = true; 2465 } finally { 2466 redisDataSource.returnResource(shardedJedis, broken); 2467 } 2468 return result; 2469 } 2470 2471 public Double zincrby(byte[] key, double score, byte[] member) { 2472 Double result = null; 2473 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2474 if (shardedJedis == null) { 2475 return result; 2476 } 2477 boolean broken = false; 2478 try { 2479 2480 result = shardedJedis.zincrby(key, score, member); 2481 2482 } catch (Exception e) { 2483 2484 log.error(e.getMessage(), e); 2485 broken = true; 2486 } finally { 2487 redisDataSource.returnResource(shardedJedis, broken); 2488 } 2489 return result; 2490 } 2491 2492 public Long zrank(byte[] key, byte[] member) { 2493 Long result = null; 2494 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2495 if (shardedJedis == null) { 2496 return result; 2497 } 2498 boolean broken = false; 2499 try { 2500 2501 result = shardedJedis.zrank(key, member); 2502 2503 } catch (Exception e) { 2504 2505 log.error(e.getMessage(), e); 2506 broken = true; 2507 } finally { 2508 redisDataSource.returnResource(shardedJedis, broken); 2509 } 2510 return result; 2511 } 2512 2513 public Long zrevrank(byte[] key, byte[] member) { 2514 Long result = null; 2515 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2516 if (shardedJedis == null) { 2517 return result; 2518 } 2519 boolean broken = false; 2520 try { 2521 2522 result = shardedJedis.zrevrank(key, member); 2523 2524 } catch (Exception e) { 2525 2526 log.error(e.getMessage(), e); 2527 broken = true; 2528 } finally { 2529 redisDataSource.returnResource(shardedJedis, broken); 2530 } 2531 return result; 2532 } 2533 2534 public Set<byte[]> zrevrange(byte[] key, int start, int end) { 2535 Set<byte[]> result = null; 2536 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2537 if (shardedJedis == null) { 2538 return result; 2539 } 2540 boolean broken = false; 2541 try { 2542 2543 result = shardedJedis.zrevrange(key, start, end); 2544 2545 } catch (Exception e) { 2546 2547 log.error(e.getMessage(), e); 2548 broken = true; 2549 } finally { 2550 redisDataSource.returnResource(shardedJedis, broken); 2551 } 2552 return result; 2553 } 2554 2555 public Set<Tuple> zrangeWithScores(byte[] key, int start, int end) { 2556 Set<Tuple> result = null; 2557 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2558 if (shardedJedis == null) { 2559 return result; 2560 } 2561 boolean broken = false; 2562 try { 2563 2564 result = shardedJedis.zrangeWithScores(key, start, end); 2565 2566 } catch (Exception e) { 2567 2568 log.error(e.getMessage(), e); 2569 broken = true; 2570 } finally { 2571 redisDataSource.returnResource(shardedJedis, broken); 2572 } 2573 return result; 2574 } 2575 2576 public Set<Tuple> zrevrangeWithScores(byte[] key, int start, int end) { 2577 Set<Tuple> result = null; 2578 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2579 if (shardedJedis == null) { 2580 return result; 2581 } 2582 boolean broken = false; 2583 try { 2584 2585 result = shardedJedis.zrevrangeWithScores(key, start, end); 2586 2587 } catch (Exception e) { 2588 2589 log.error(e.getMessage(), e); 2590 broken = true; 2591 } finally { 2592 redisDataSource.returnResource(shardedJedis, broken); 2593 } 2594 return result; 2595 } 2596 2597 public Long zcard(byte[] key) { 2598 Long result = null; 2599 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2600 if (shardedJedis == null) { 2601 return result; 2602 } 2603 boolean broken = false; 2604 try { 2605 2606 result = shardedJedis.zcard(key); 2607 2608 } catch (Exception e) { 2609 2610 log.error(e.getMessage(), e); 2611 broken = true; 2612 } finally { 2613 redisDataSource.returnResource(shardedJedis, broken); 2614 } 2615 return result; 2616 } 2617 2618 public Double zscore(byte[] key, byte[] member) { 2619 Double result = null; 2620 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2621 if (shardedJedis == null) { 2622 return result; 2623 } 2624 boolean broken = false; 2625 try { 2626 2627 result = shardedJedis.zscore(key, member); 2628 2629 } catch (Exception e) { 2630 2631 log.error(e.getMessage(), e); 2632 broken = true; 2633 } finally { 2634 redisDataSource.returnResource(shardedJedis, broken); 2635 } 2636 return result; 2637 } 2638 2639 public List<byte[]> sort(byte[] key) { 2640 List<byte[]> result = null; 2641 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2642 if (shardedJedis == null) { 2643 return result; 2644 } 2645 boolean broken = false; 2646 try { 2647 2648 result = shardedJedis.sort(key); 2649 2650 } catch (Exception e) { 2651 2652 log.error(e.getMessage(), e); 2653 broken = true; 2654 } finally { 2655 redisDataSource.returnResource(shardedJedis, broken); 2656 } 2657 return result; 2658 } 2659 2660 public List<byte[]> sort(byte[] key, SortingParams sortingParameters) { 2661 List<byte[]> result = null; 2662 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2663 if (shardedJedis == null) { 2664 return result; 2665 } 2666 boolean broken = false; 2667 try { 2668 2669 result = shardedJedis.sort(key, sortingParameters); 2670 2671 } catch (Exception e) { 2672 2673 log.error(e.getMessage(), e); 2674 broken = true; 2675 } finally { 2676 redisDataSource.returnResource(shardedJedis, broken); 2677 } 2678 return result; 2679 } 2680 2681 public Long zcount(byte[] key, double min, double max) { 2682 Long result = null; 2683 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2684 if (shardedJedis == null) { 2685 return result; 2686 } 2687 boolean broken = false; 2688 try { 2689 2690 result = shardedJedis.zcount(key, min, max); 2691 2692 } catch (Exception e) { 2693 2694 log.error(e.getMessage(), e); 2695 broken = true; 2696 } finally { 2697 redisDataSource.returnResource(shardedJedis, broken); 2698 } 2699 return result; 2700 } 2701 2702 public Set<byte[]> zrangeByScore(byte[] key, double min, double max) { 2703 Set<byte[]> result = null; 2704 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2705 if (shardedJedis == null) { 2706 return result; 2707 } 2708 boolean broken = false; 2709 try { 2710 2711 result = shardedJedis.zrangeByScore(key, min, max); 2712 2713 } catch (Exception e) { 2714 2715 log.error(e.getMessage(), e); 2716 broken = true; 2717 } finally { 2718 redisDataSource.returnResource(shardedJedis, broken); 2719 } 2720 return result; 2721 } 2722 2723 public Set<byte[]> zrangeByScore(byte[] key, double min, double max, int offset, int count) { 2724 Set<byte[]> result = null; 2725 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2726 if (shardedJedis == null) { 2727 return result; 2728 } 2729 boolean broken = false; 2730 try { 2731 2732 result = shardedJedis.zrangeByScore(key, min, max, offset, count); 2733 2734 } catch (Exception e) { 2735 2736 log.error(e.getMessage(), e); 2737 broken = true; 2738 } finally { 2739 redisDataSource.returnResource(shardedJedis, broken); 2740 } 2741 return result; 2742 } 2743 2744 public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max) { 2745 Set<Tuple> result = null; 2746 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2747 if (shardedJedis == null) { 2748 return result; 2749 } 2750 boolean broken = false; 2751 try { 2752 2753 result = shardedJedis.zrangeByScoreWithScores(key, min, max); 2754 2755 } catch (Exception e) { 2756 2757 log.error(e.getMessage(), e); 2758 broken = true; 2759 } finally { 2760 redisDataSource.returnResource(shardedJedis, broken); 2761 } 2762 return result; 2763 } 2764 2765 public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max, int offset, int count) { 2766 Set<Tuple> result = null; 2767 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2768 if (shardedJedis == null) { 2769 return result; 2770 } 2771 boolean broken = false; 2772 try { 2773 2774 result = shardedJedis.zrangeByScoreWithScores(key, min, max, offset, count); 2775 2776 } catch (Exception e) { 2777 2778 log.error(e.getMessage(), e); 2779 broken = true; 2780 } finally { 2781 redisDataSource.returnResource(shardedJedis, broken); 2782 } 2783 return result; 2784 } 2785 2786 public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min) { 2787 Set<byte[]> result = null; 2788 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2789 if (shardedJedis == null) { 2790 return result; 2791 } 2792 boolean broken = false; 2793 try { 2794 2795 result = shardedJedis.zrevrangeByScore(key, max, min); 2796 2797 } catch (Exception e) { 2798 2799 log.error(e.getMessage(), e); 2800 broken = true; 2801 } finally { 2802 redisDataSource.returnResource(shardedJedis, broken); 2803 } 2804 return result; 2805 } 2806 2807 public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min, int offset, int count) { 2808 Set<byte[]> result = null; 2809 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2810 if (shardedJedis == null) { 2811 return result; 2812 } 2813 boolean broken = false; 2814 try { 2815 2816 result = shardedJedis.zrevrangeByScore(key, max, min, offset, count); 2817 2818 } catch (Exception e) { 2819 2820 log.error(e.getMessage(), e); 2821 broken = true; 2822 } finally { 2823 redisDataSource.returnResource(shardedJedis, broken); 2824 } 2825 return result; 2826 } 2827 2828 public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min) { 2829 Set<Tuple> result = null; 2830 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2831 if (shardedJedis == null) { 2832 return result; 2833 } 2834 boolean broken = false; 2835 try { 2836 2837 result = shardedJedis.zrevrangeByScoreWithScores(key, max, min); 2838 2839 } catch (Exception e) { 2840 2841 log.error(e.getMessage(), e); 2842 broken = true; 2843 } finally { 2844 redisDataSource.returnResource(shardedJedis, broken); 2845 } 2846 return result; 2847 } 2848 2849 public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min, int offset, int count) { 2850 Set<Tuple> result = null; 2851 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2852 if (shardedJedis == null) { 2853 return result; 2854 } 2855 boolean broken = false; 2856 try { 2857 2858 result = shardedJedis.zrevrangeByScoreWithScores(key, max, min, offset, count); 2859 2860 } catch (Exception e) { 2861 2862 log.error(e.getMessage(), e); 2863 broken = true; 2864 } finally { 2865 redisDataSource.returnResource(shardedJedis, broken); 2866 } 2867 return result; 2868 } 2869 2870 public Long zremrangeByRank(byte[] key, int start, int end) { 2871 Long result = null; 2872 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2873 if (shardedJedis == null) { 2874 return result; 2875 } 2876 boolean broken = false; 2877 try { 2878 2879 result = shardedJedis.zremrangeByRank(key, start, end); 2880 2881 } catch (Exception e) { 2882 2883 log.error(e.getMessage(), e); 2884 broken = true; 2885 } finally { 2886 redisDataSource.returnResource(shardedJedis, broken); 2887 } 2888 return result; 2889 } 2890 2891 public Long zremrangeByScore(byte[] key, double start, double end) { 2892 Long result = null; 2893 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2894 if (shardedJedis == null) { 2895 return result; 2896 } 2897 boolean broken = false; 2898 try { 2899 2900 result = shardedJedis.zremrangeByScore(key, start, end); 2901 2902 } catch (Exception e) { 2903 log.error(e.getMessage(), e); 2904 broken = true; 2905 } finally { 2906 redisDataSource.returnResource(shardedJedis, broken); 2907 } 2908 return result; 2909 } 2910 2911 public Long linsert(byte[] key, LIST_POSITION where, byte[] pivot, byte[] value) { 2912 Long result = null; 2913 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2914 if (shardedJedis == null) { 2915 return result; 2916 } 2917 boolean broken = false; 2918 try { 2919 2920 result = shardedJedis.linsert(key, where, pivot, value); 2921 2922 } catch (Exception e) { 2923 log.error(e.getMessage(), e); 2924 broken = true; 2925 } finally { 2926 redisDataSource.returnResource(shardedJedis, broken); 2927 } 2928 return result; 2929 } 2930 2931 public List<Object> pipelined(ShardedJedisPipeline shardedJedisPipeline) { 2932 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2933 List<Object> result = null; 2934 if (shardedJedis == null) { 2935 return result; 2936 } 2937 boolean broken = false; 2938 try { 2939 result = shardedJedis.pipelined(shardedJedisPipeline); 2940 } catch (Exception e) { 2941 log.error(e.getMessage(), e); 2942 broken = true; 2943 } finally { 2944 redisDataSource.returnResource(shardedJedis, broken); 2945 } 2946 return result; 2947 } 2948 2949 public Jedis getShard(byte[] key) { 2950 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2951 Jedis result = null; 2952 if (shardedJedis == null) { 2953 return result; 2954 } 2955 boolean broken = false; 2956 try { 2957 result = shardedJedis.getShard(key); 2958 } catch (Exception e) { 2959 log.error(e.getMessage(), e); 2960 broken = true; 2961 } finally { 2962 redisDataSource.returnResource(shardedJedis, broken); 2963 } 2964 return result; 2965 } 2966 2967 public Jedis getShard(String key) { 2968 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2969 Jedis result = null; 2970 if (shardedJedis == null) { 2971 return result; 2972 } 2973 boolean broken = false; 2974 try { 2975 result = shardedJedis.getShard(key); 2976 } catch (Exception e) { 2977 log.error(e.getMessage(), e); 2978 broken = true; 2979 } finally { 2980 redisDataSource.returnResource(shardedJedis, broken); 2981 } 2982 return result; 2983 } 2984 2985 public JedisShardInfo getShardInfo(byte[] key) { 2986 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 2987 JedisShardInfo result = null; 2988 if (shardedJedis == null) { 2989 return result; 2990 } 2991 boolean broken = false; 2992 try { 2993 result = shardedJedis.getShardInfo(key); 2994 } catch (Exception e) { 2995 log.error(e.getMessage(), e); 2996 broken = true; 2997 } finally { 2998 redisDataSource.returnResource(shardedJedis, broken); 2999 } 3000 return result; 3001 } 3002 3003 public JedisShardInfo getShardInfo(String key) { 3004 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 3005 JedisShardInfo result = null; 3006 if (shardedJedis == null) { 3007 return result; 3008 } 3009 boolean broken = false; 3010 try { 3011 result = shardedJedis.getShardInfo(key); 3012 } catch (Exception e) { 3013 log.error(e.getMessage(), e); 3014 broken = true; 3015 } finally { 3016 redisDataSource.returnResource(shardedJedis, broken); 3017 } 3018 return result; 3019 } 3020 3021 public String getKeyTag(String key) { 3022 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 3023 String result = null; 3024 if (shardedJedis == null) { 3025 return result; 3026 } 3027 boolean broken = false; 3028 try { 3029 result = shardedJedis.getKeyTag(key); 3030 } catch (Exception e) { 3031 log.error(e.getMessage(), e); 3032 broken = true; 3033 } finally { 3034 redisDataSource.returnResource(shardedJedis, broken); 3035 } 3036 return result; 3037 } 3038 3039 public Collection<JedisShardInfo> getAllShardInfo() { 3040 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 3041 Collection<JedisShardInfo> result = null; 3042 if (shardedJedis == null) { 3043 return result; 3044 } 3045 boolean broken = false; 3046 try { 3047 result = shardedJedis.getAllShardInfo(); 3048 3049 } catch (Exception e) { 3050 log.error(e.getMessage(), e); 3051 broken = true; 3052 } finally { 3053 redisDataSource.returnResource(shardedJedis, broken); 3054 } 3055 return result; 3056 } 3057 3058 public Collection<Jedis> getAllShards() { 3059 ShardedJedis shardedJedis = redisDataSource.getRedisClient(); 3060 Collection<Jedis> result = null; 3061 if (shardedJedis == null) { 3062 return result; 3063 } 3064 boolean broken = false; 3065 try { 3066 result = shardedJedis.getAllShards(); 3067 3068 } catch (Exception e) { 3069 log.error(e.getMessage(), e); 3070 broken = true; 3071 } finally { 3072 redisDataSource.returnResource(shardedJedis, broken); 3073 } 3074 return result; 3075 } 3076 3077 }