Redis实现Restful的访问权限控制(二)
2017-03-31 11:36
351 查看
redis数据源接入
redis缓存
用户登录标识缓存
访问接口权限拦截
package zdh.territory.redis.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import redis.clients.jedis.*;
import arthur.test.redis.RedisClient;
import arthur.test.redis.RedisDataSource;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @Author:Arthur Han
* @Description:
* @CreateDate:2017/3/317:54
* @Modified By:
*/
@Repository(“redisClient”)
public class RedisClientImpl implements RedisClient {
@Autowired
private RedisDataSource redisDataSource;
}
“`
至此Redis已经和Spring整合,下一步就是实现用户登录标识Token的Redis操作。
redis缓存
用户登录标识缓存
访问接口权限拦截
redis缓存
RedisClientimport redis.clients.jedis.*; import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; /** * @Author:Arthur Han * @Description: * @CreateDate:2017/3/1410:33 * @Modified By: */ public interface RedisClient { void disconnect(); String set(String key, String value); String get(String key); Boolean exists(String key); String type(String key); Long expire(String key, int seconds); Long expireAt(String key, long unixTime); Long ttl(String key); boolean setbit(String key, long offset, boolean value); boolean getbit(String key, long offset); long setrange(String key, long offset, String value); String getrange(String key, long startOffset, long endOffset); String getSet(String key, String value); Long setnx(String key, String value); String setex(String key, int seconds, String value); Long decrBy(String key, long integer); Long decr(String key); Long incrBy(String key, long integer); Long incr(String key); Long append(String key, String value); String substr(String key, int start, int end); Long hset(String key, String field, String value); String hget(String key, String field); Long hsetnx(String key, String field, String value); String hmset(String key, Map<String, String> hash); List<String> hmget(String key, String... fields); Long hincrBy(String key, String field, long value); Boolean hexists(String key, String field); Long del(String key); Long hdel(String key, String field); Long hlen(String key); Set<String> hkeys(String key); List<String> hvals(String key); Map<String, String> hgetAll(String key); Long rpush(String key, String string); Long lpush(String key, String string); Long llen(String key); List<String> lrange(String key, long start, long end); String ltrim(String key, long start, long end); String lindex(String key, long index); String lset(String key, long index, String value); Long lrem(String key, long count, String value); String lpop(String key); String rpop(String key); Long sadd(String key, String member); Set<String> smembers(String key); Long srem(String key, String member); String spop(String key); Long scard(String key); Boolean sismember(String key, String member); String srandmember(String key); Long zadd(String key, double score, String member); Set<String> zrange(String key, int start, int end); Long zrem(String key, String member); Double zincrby(String key, double score, String member); Long zrank(String key, String member); Long zrevrank(String key, String member); Set<String> zrevrange(String key, int start, int end); Set<Tuple> zrangeWithScores(String key, int start, int end); Set<Tuple> zrevrangeWithScores(String key, int start, int end); Long zcard(String key); Double zscore(String key, String member); List<String> sort(String key); List<String> sort(String key, SortingParams sortingParameters); Long zcount(String key, double min, double max); Set<String> zrangeByScore(String key, double min, double max); Set<String> zrevrangeByScore(String key, double max, double min); Set<String> zrangeByScore(String key, double min, double max, int offset, int count); Set<String> zrevrangeByScore(String key, double max, double min, int offset, int count); Set<Tuple> zrangeByScoreWithScores(String key, double min, double max); Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min); Set<Tuple> zrangeByScoreWithScores(String key, double min, double max, int offset, int count); Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min, int offset, int count); Long zremrangeByRank(String key, int start, int end); Long zremrangeByScore(String key, double start, double end); Long linsert(String key, BinaryClient.LIST_POSITION where, String pivot, String value); String set(byte[] key, byte[] value); byte[] get(byte[] key); Boolean exists(byte[] key); String type(byte[] key); Long expire(byte[] key, int seconds); Long expireAt(byte[] key, long unixTime); Long ttl(byte[] key); byte[] getSet(byte[] key, byte[] value); Long setnx(byte[] key, byte[] value); String setex(byte[] key, int seconds, byte[] value); Long decrBy(byte[] key, long integer); Long decr(byte[] key); 4000 Long incrBy(byte[] key, long integer); Long incr(byte[] key); Long append(byte[] key, byte[] value); byte[] substr(byte[] key, int start, int end); Long hset(byte[] key, byte[] field, byte[] value); byte[] hget(byte[] key, byte[] field); Long hsetnx(byte[] key, byte[] field, byte[] value); String hmset(byte[] key, Map<byte[], byte[]> hash); List<byte[]> hmget(byte[] key, byte[]... fields); Long hincrBy(byte[] key, byte[] field, long value); Boolean hexists(byte[] key, byte[] field); Long hdel(byte[] key, byte[] field); Long hlen(byte[] key); Set<byte[]> hkeys(byte[] key); Collection<byte[]> hvals(byte[] key); Map<byte[], byte[]> hgetAll(byte[] key); Long rpush(byte[] key, byte[] string); Long lpush(byte[] key, byte[] string); Long llen(byte[] key); List<byte[]> lrange(byte[] key, int start, int end); String ltrim(byte[] key, int start, int end); byte[] lindex(byte[] key, int index); String lset(byte[] key, int index, byte[] value); Long lrem(byte[] key, int count, byte[] value); byte[] lpop(byte[] key); byte[] rpop(byte[] key); Long sadd(byte[] key, byte[] member); Set<byte[]> smembers(byte[] key); Long srem(byte[] key, byte[] member); byte[] spop(byte[] key); Long scard(byte[] key); Boolean sismember(byte[] key, byte[] member); byte[] srandmember(byte[] key); Long zadd(byte[] key, double score, byte[] member); Set<byte[]> zrange(byte[] key, int start, int end); Long zrem(byte[] key, byte[] member); Double zincrby(byte[] key, double score, byte[] member); Long zrank(byte[] key, byte[] member); Long zrevrank(byte[] key, byte[] member); Set<byte[]> zrevrange(byte[] key, int start, int end); Set<Tuple> zrangeWithScores(byte[] key, int start, int end); Set<Tuple> zrevrangeWithScores(byte[] key, int start, int end); Long zcard(byte[] key); Double zscore(byte[] key, byte[] member); List<byte[]> sort(byte[] key); List<byte[]> sort(byte[] key, SortingParams sortingParameters); Long zcount(byte[] key, double min, double max); Set<byte[]> zrangeByScore(byte[] key, double min, double max); Set<byte[]> zrangeByScore(byte[] key, double min, double max, int offset, int count); Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max); Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max, int offset, int count); Set<byte[]> zrevrangeByScore(byte[] key, double max, double min); Set<byte[]> zrevrangeByScore(byte[] key, double max, double min, int offset, int count); Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min); Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min, int offset, int count); Long zremrangeByRank(byte[] key, int start, int end); Long zremrangeByScore(byte[] key, double start, double end); Long linsert(byte[] key, BinaryClient.LIST_POSITION where, byte[] pivot, byte[] value); List<Object> pipelined(ShardedJedisPipeline shardedJedisPipeline); Jedis getShard(byte[] key); Jedis getShard(String key); JedisShardInfo getShardInfo(byte[] key); JedisShardInfo getShardInfo(String key); String getKeyTag(String key); Collection<JedisShardInfo> getAllShardInfo(); Collection<Jedis> getAllShards(); } *RedisClientImpl*
package zdh.territory.redis.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import redis.clients.jedis.*;
import arthur.test.redis.RedisClient;
import arthur.test.redis.RedisDataSource;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @Author:Arthur Han
* @Description:
* @CreateDate:2017/3/317:54
* @Modified By:
*/
@Repository(“redisClient”)
public class RedisClientImpl implements RedisClient {
@Autowired
private RedisDataSource redisDataSource;
@Override public void disconnect() { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); shardedJedis.disconnect(); } /** * 设置单个值 * * @param key * @param value * @return */ @Override 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) { e.printStackTrace(); broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } /** * 获取单个值 * * @param key * @return */ @Override 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) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override 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) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override 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) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } /** * 在某段时间后实现 * * @param key * @param seconds * @return */ @Override 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) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } /** * 在某个时间点失效 * * @param key * @param unixTime * @return */ @Override 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) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override 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) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override 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) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override 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) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override 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) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override 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) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public String getSet(String key, String value) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.getSet(key, value); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long setnx(String key, String value) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.setnx(key, value); } catch (Exception e) { 193a0 broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public String setex(String key, int seconds, String value) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.setex(key, seconds, value); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long decrBy(String key, long integer) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.decrBy(key, integer); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long decr(String key) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.decr(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long incrBy(String key, long integer) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.incrBy(key, integer); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long incr(String key) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.incr(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long append(String key, String value) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.append(key, value); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public String substr(String key, int start, int end) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.substr(key, start, end); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long hset(String key, String field, String value) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hset(key, field, value); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public String hget(String key, String field) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hget(key, field); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long hsetnx(String key, String field, String value) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hsetnx(key, field, value); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public String hmset(String key, Map<String, String> hash) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hmset(key, hash); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public List<String> hmget(String key, String... fields) { List<String> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hmget(key, fields); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long hincrBy(String key, String field, long value) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hincrBy(key, field, value); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Boolean hexists(String key, String field) { Boolean result = false; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hexists(key, field); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long del(String key) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.del(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long hdel(String key, String field) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hdel(key, field); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long hlen(String key) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hlen(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<String> hkeys(String key) { Set<String> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hkeys(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public List<String> hvals(String key) { List<String> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hvals(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Map<String, String> hgetAll(String key) { Map<String, String> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hgetAll(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } // ================list ====== l表示 list或 left, r表示right==================== @Override public Long rpush(String key, String string) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.rpush(key, string); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long lpush(String key, String string) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.lpush(key, string); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long llen(String key) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.llen(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public List<String> lrange(String key, long start, long end) { List<String> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.lrange(key, start, end); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public String ltrim(String key, long start, long end) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.ltrim(key, start, end); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public String lindex(String key, long index) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.lindex(key, index); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public String lset(String key, long index, String value) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.lset(key, index, value); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long lrem(String key, long count, String value) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.lrem(key, count, value); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public String lpop(String key) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.lpop(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public String rpop(String key) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.rpop(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } //return 1 add a not exist value , //return 0 add a exist value @Override public Long sadd(String key, String member) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.sadd(key, member); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<String> smembers(String key) { Set<String> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.smembers(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long srem(String key, String member) { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); Long result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.srem(key, member); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public String spop(String key) { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); String result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.spop(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long scard(String key) { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); Long result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.scard(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Boolean sismember(String key, String member) { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); Boolean result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.sismember(key, member); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public String srandmember(String key) { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); String result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.srandmember(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long zadd(String key, double score, String member) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zadd(key, score, member); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<String> zrange(String key, int start, int end) { Set<String> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrange(key, start, end); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long zrem(String key, String member) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrem(key, member); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Double zincrby(String key, double score, String member) { Double result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zincrby(key, score, member); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long zrank(String key, String member) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrank(key, member); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long zrevrank(String key, String member) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrank(key, member); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<String> zrevrange(String key, int start, int end) { Set<String> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrange(key, start, end); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<Tuple> zrangeWithScores(String key, int start, int end) { Set<Tuple> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrangeWithScores(key, start, end); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<Tuple> zrevrangeWithScores(String key, int start, int end) { Set<Tuple> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrangeWithScores(key, start, end); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long zcard(String key) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zcard(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Double zscore(String key, String member) { Double result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zscore(key, member); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public List<String> sort(String key) { List<String> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.sort(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public List<String> sort(String key, SortingParams sortingParameters) { List<String> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.sort(key, sortingParameters); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long zcount(String key, double min, double max) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zcount(key, min, max); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<String> zrangeByScore(String key, double min, double max) { Set<String> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrangeByScore(key, min, max); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<String> zrevrangeByScore(String key, double max, double min) { Set<String> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrangeByScore(key, max, min); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<String> zrangeByScore(String key, double min, double max, int offset, int count) { Set<String> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrangeByScore(key, min, max, offset, count); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<String> zrevrangeByScore(String key, double max, double min, int offset, int count) { Set<String> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrangeByScore(key, max, min, offset, count); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<Tuple> zrangeByScoreWithScores(String key, double min, double max) { Set<Tuple> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrangeByScoreWithScores(key, min, max); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min) { Set<Tuple> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrangeByScoreWithScores(key, max, min); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<Tuple> zrangeByScoreWithScores(String key, double min, double max, int offset, int count) { Set<Tuple> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrangeByScoreWithScores(key, min, max, offset, count); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min, int offset, int count) { Set<Tuple> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrangeByScoreWithScores(key, max, min, offset, count); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long zremrangeByRank(String key, int start, int end) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zremrangeByRank(key, start, end); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long zremrangeByScore(String key, double start, double end) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zremrangeByScore(key, start, end); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long linsert(String key, BinaryClient.LIST_POSITION where, String pivot, String value) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.linsert(key, where, pivot, value); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public String set(byte[] key, byte[] 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) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public byte[] get(byte[] key) { byte[] result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.get(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Boolean exists(byte[] key) { Boolean result = false; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.exists(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public String type(byte[] key) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.type(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long expire(byte[] 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) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long expireAt(byte[] 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) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long ttl(byte[] key) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.ttl(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public byte[] getSet(byte[] key, byte[] value) { byte[] result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.getSet(key, value); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long setnx(byte[] key, byte[] value) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.setnx(key, value); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public String setex(byte[] key, int seconds, byte[] value) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.setex(key, seconds, value); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long decrBy(byte[] key, long integer) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.decrBy(key, integer); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long decr(byte[] key) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.decr(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long incrBy(byte[] key, long integer) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.incrBy(key, integer); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long incr(byte[] key) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.incr(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long append(byte[] key, byte[] value) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.append(key, value); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public byte[] substr(byte[] key, int start, int end) { byte[] result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.substr(key, start, end); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long hset(byte[] key, byte[] field, byte[] value) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hset(key, field, value); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public byte[] hget(byte[] key, byte[] field) { byte[] result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hget(key, field); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long hsetnx(byte[] key, byte[] field, byte[] value) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hsetnx(key, field, value); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public String hmset(byte[] key, Map<byte[], byte[]> hash) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hmset(key, hash); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public List<byte[]> hmget(byte[] key, byte[]... fields) { List<byte[]> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hmget(key, fields); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long hincrBy(byte[] key, byte[] field, long value) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hincrBy(key, field, value); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Boolean hexists(byte[] key, byte[] field) { Boolean result = false; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hexists(key, field); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long hdel(byte[] key, byte[] field) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hdel(key, field); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long hlen(byte[] key) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hlen(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<byte[]> hkeys(byte[] key) { Set<byte[]> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hkeys(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Collection<byte[]> hvals(byte[] key) { Collection<byte[]> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hvals(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Map<byte[], byte[]> hgetAll(byte[] key) { Map<byte[], byte[]> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.hgetAll(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long rpush(byte[] key, byte[] string) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.rpush(key, string); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long lpush(byte[] key, byte[] string) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.lpush(key, string); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long llen(byte[] key) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.llen(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public List<byte[]> lrange(byte[] key, int start, int end) { List<byte[]> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.lrange(key, start, end); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public String ltrim(byte[] key, int start, int end) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.ltrim(key, start, end); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public byte[] lindex(byte[] key, int index) { byte[] result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.lindex(key, index); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public String lset(byte[] key, int index, byte[] value) { String result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.lset(key, index, value); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long lrem(byte[] key, int count, byte[] value) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.lrem(key, count, value); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public byte[] lpop(byte[] key) { byte[] result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.lpop(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public byte[] rpop(byte[] key) { byte[] result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.rpop(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long sadd(byte[] key, byte[] member) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.sadd(key, member); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<byte[]> smembers(byte[] key) { Set<byte[]> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.smembers(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long srem(byte[] key, byte[] member) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.srem(key, member); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public byte[] spop(byte[] key) { byte[] result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.spop(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long scard(byte[] key) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.scard(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Boolean sismember(byte[] key, byte[] member) { Boolean result = false; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.sismember(key, member); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public byte[] srandmember(byte[] key) { byte[] result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.srandmember(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long zadd(byte[] key, double score, byte[] member) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zadd(key, score, member); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<byte[]> zrange(byte[] key, int start, int end) { Set<byte[]> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrange(key, start, end); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long zrem(byte[] key, byte[] member) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrem(key, member); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Double zincrby(byte[] key, double score, byte[] member) { Double result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zincrby(key, score, member); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long zrank(byte[] key, byte[] member) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrank(key, member); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long zrevrank(byte[] key, byte[] member) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrank(key, member); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<byte[]> zrevrange(byte[] key, int start, int end) { Set<byte[]> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrange(key, start, end); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<Tuple> zrangeWithScores(byte[] key, int start, int end) { Set<Tuple> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrangeWithScores(key, start, end); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<Tuple> zrevrangeWithScores(byte[] key, int start, int end) { Set<Tuple> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrangeWithScores(key, start, end); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long zcard(byte[] key) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zcard(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Double zscore(byte[] key, byte[] member) { Double result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zscore(key, member); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public List<byte[]> sort(byte[] key) { List<byte[]> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.sort(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public List<byte[]> sort(byte[] key, SortingParams sortingParameters) { List<byte[]> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.sort(key, sortingParameters); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long zcount(byte[] key, double min, double max) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zcount(key, min, max); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<byte[]> zrangeByScore(byte[] key, double min, double max) { Set<byte[]> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrangeByScore(key, min, max); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<byte[]> zrangeByScore(byte[] key, double min, double max, int offset, int count) { Set<byte[]> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrangeByScore(key, min, max, offset, count); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max) { Set<Tuple> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrangeByScoreWithScores(key, min, max); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max, int offset, int count) { Set<Tuple> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrangeByScoreWithScores(key, min, max, offset, count); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min) { Set<byte[]> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrangeByScore(key, max, min); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min, int offset, int count) { Set<byte[]> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrangeByScore(key, max, min, offset, count); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min) { Set<Tuple> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrangeByScoreWithScores(key, max, min); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min, int offset, int count) { Set<Tuple> result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zrevrangeByScoreWithScores(key, max, min, offset, count); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long zremrangeByRank(byte[] key, int start, int end) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zremrangeByRank(key, start, end); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long zremrangeByScore(byte[] key, double start, double end) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.zremrangeByScore(key, start, end); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Long linsert(byte[] key, BinaryClient.LIST_POSITION where, byte[] pivot, byte[] value) { Long result = null; ShardedJedis shardedJedis = redisDataSource.getRedisClient(); if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.linsert(key, where, pivot, value); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public List<Object> pipelined(ShardedJedisPipeline shardedJedisPipeline) { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); List<Object> result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.pipelined(shardedJedisPipeline); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Jedis getShard(byte[] key) { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); Jedis result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.getShard(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Jedis getShard(String key) { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); Jedis result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.getShard(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public JedisShardInfo getShardInfo(byte[] key) { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); JedisShardInfo result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.getShardInfo(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public JedisShardInfo getShardInfo(String key) { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); JedisShardInfo result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.getShardInfo(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public String getKeyTag(String key) { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); String result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.getKeyTag(key); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Collection<JedisShardInfo> getAllShardInfo() { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); Collection<JedisShardInfo> result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.getAllShardInfo(); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; } @Override public Collection<Jedis> getAllShards() { ShardedJedis shardedJedis = redisDataSource.getRedisClient(); Collection<Jedis> result = null; if (shardedJedis == null) { return result; } boolean broken = false; try { result = shardedJedis.getAllShards(); } catch (Exception e) { broken = true; } finally { redisDataSource.returnResource(shardedJedis, broken); } return result; }
}
“`
至此Redis已经和Spring整合,下一步就是实现用户登录标识Token的Redis操作。
相关文章推荐
- Redis实现Restful的访问权限控制(四)
- Redis实现Restful的访问权限控制(一)
- Redis实现Restful的访问权限控制(三)
- Subversion之路---实现精细的目录访问权限控制
- Subversion之路--实现精细的目录访问权限控制
- 基于角色的访问控制'的权限管理的数据库的设计实现
- Subversion之路实现精细的目录访问权限控制
- Subversion之路--实现精细的目录访问权限控制
- Subversion之路-实现精细的目录访问权限控制
- Subversion之路--实现精细的目录访问权限控制 (转)
- Subversion之路--实现精细的目录访问权限控制
- 用Cacls修改文件访问控制权限 VB实现
- 用session实现頁麵访问权限控制
- 基于角色的访问控制'的权限管理的数据库的设计实现
- svn 实现精细的目录访问权限控制
- Subversion实现精细的目录访问权限控制
- svn 实现精细的目录访问权限控制
- Subversion之路--实现精细的目录访问权限控制(v1.0 更新于2006.12.05) (二)
- Subversion之路--实现精细的目录访问权限控制(v1.0 更新于2006.12.05)(二)
- Subversion之路--实现精细的目录访问权限控制(v1.0 更新于2006.12.05)