session 共享方案
- memcached-session-manager
- 客户端Cookie保存
- 服务器间Session同步
- 把Session持久化到数据库
- 不使用session….
导入包
redis.properties
redis.hostName=127.0.0.1
redis.port=6379
redis.password=1234567890
redis.timeout=3000
配置redis-session.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
<!--redis 连接池工具类-->
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"/>
<!--redis util 工具连接池配置-->
<bean id="jedisShardInfo" class="redis.clients.jedis.JedisShardInfo">
<constructor-arg index="0" value="${redis.hostname}" />
<constructor-arg index="1" value="${redis.port}" type="int" />
<property name="password" value="${redis.password}"/>
</bean>
<!--redis util 工具连接池配置-->
<bean id="shardedJedisPool" class="redis.clients.jedis.ShardedJedisPool">
<constructor-arg index="0" ref="jedisPoolConfig" />
<constructor-arg index="1">
<list>
<!--有多个redis 集群配置多个ref-->
<ref bean="jedisShardInfo" />
</list>
</constructor-arg>
</bean>
<!--以下是spring session相关配置-->
<!--spring redis 配置-->
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="${redis.hostname}"/>
<property name="port" value="${redis.port}"/>
<property name="password" value="${redis.password}"/>
<property name="timeout" value="${redis.timeout}"/>
<property name="poolConfig" ref="jedisPoolConfig"/>
<property name="usePool" value="true"/>
</bean>
<!--spring session redis 配置-->
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory"/>
</bean>
<!--spring session 配置 -->
<bean id="redisHttpSessionConfiguration" class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
<property name="maxInactiveIntervalInSeconds" value="1800"/>
<property name="redisNamespace" value="ianbase" />
</bean>
<!--spring session 监听器-->
<bean class="org.springframework.session.config.annotation.web.http.SpringHttpSessionConfiguration">
<property name="httpSessionListeners">
<list>
<bean class="cn.anniweiya.session.SessionListener" />
</list>
</property>
</bean>
</beans>
配置web.xml
(注意这个filter一定要放到其他filter的前面)
<filter>
<filter-name>springSessionRepositoryFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSessionRepositoryFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
响应session创建与销毁
package cn.anniweiya.session;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import cn.anniweiya.common.util.RedisUtil;
public class SessionListener implements HttpSessionListener {
private Logger logger = LogManager.getLogger(SessionListener.class);
/** 客户端主题 */
public static final String WEBTHEME = "webTheme";
/** 当前用户 */
public static final String CURRENT_USER = "CURRENT_USER";
/** 在线用户数量 */
public static final String ALLUSER_NUMBER = "ALLUSER_NUMBER";
/**
* session创建
* @param event
*/
public void sessionCreated(HttpSessionEvent event) {
HttpSession session = event.getSession();
session.setAttribute(WEBTHEME, "default");
logger.info("创建了一个Session连接:[" + session.getId() + "]");
setAllUserNumber(1);
}
/**
* session销毁
* @param event
*/
public void sessionDestroyed(HttpSessionEvent event) {
HttpSession session = event.getSession();
if (getAllUserNumber() > 0) {
logger.info("销毁了一个Session连接:[" + session.getId() + "]");
}
session.removeAttribute(CURRENT_USER);
setAllUserNumber(-1);
}
/**
* 保存用户数
* @param n
*/
private void setAllUserNumber(int n) {
Long number = getAllUserNumber() + n;
if (number >= 0) {
logger.info("用户数:" + number);
RedisUtil.set(ALLUSER_NUMBER, 60 * 60 * 24, number);
}
}
/**
* 获取登录用户数目
* @return
*/
public static Long getAllUserNumber() {
String v = RedisUtil.get(ALLUSER_NUMBER);
if (v != null) {
return Long.valueOf(v);
}
return 0L;
}
}
Executor
package cn.anniweiya.common.util.jedis;
import redis.clients.jedis.ShardedJedis;
/**
* @author ShenHuaJie
* @version 2016年5月20日 下午3:19:19
*/
public interface Executor<K> {
public K execute(ShardedJedis jedis);
}
JedisTemplate
package com.ian.common.util.jedis;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;
import redis.clients.jedis.ShardedJedis;
import redis.clients.jedis.ShardedJedisPool;
/**
* @author ShenHuaJie
* @version 2016年5月20日 下午3:19:19
*/
public class JedisTemplate {
private static final Logger logger = LogManager.getLogger();
private static ShardedJedisPool shardedJedisPool = null;
private static Integer EXPIRE = 60 * 60; // 1小时
// 获取线程
private static ShardedJedis getJedis() {
if (shardedJedisPool == null) {
synchronized (EXPIRE) {
if (shardedJedisPool == null) {
WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
shardedJedisPool = wac.getBean(ShardedJedisPool.class);
}
}
}
return shardedJedisPool.getResource();
}
public static <K> K run(String key, Executor<K> executor, boolean... expired) {
ShardedJedis jedis = getJedis();
if (jedis == null) {
return null;
}
try {
K result = executor.execute(jedis);
if (jedis.exists(key) && expired == null) {
jedis.expire(key, EXPIRE);
}
return result;
} catch (Exception e) {
logger.error(e.getMessage(), e);
} finally {
if (jedis != null) {
jedis.close();
}
}
return null;
}
public static <K> K run(byte[] key, Executor<K> executor, boolean... expired) {
ShardedJedis jedis = getJedis();
if (jedis == null) {
return null;
}
try {
K result = executor.execute(jedis);
if (jedis.exists(key) && expired == null) {
jedis.expire(key, EXPIRE);
}
return result;
} catch (Exception e) {
logger.error(e.getMessage(), e);
} finally {
if (jedis != null) {
jedis.close();
}
}
return null;
}
}
RedisUtil
package cn.anniweiya.common.util;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.alibaba.fastjson.JSON;
import com.ian.common.util.jedis.Executor;
import com.ian.common.util.jedis.JedisTemplate;
import redis.clients.jedis.BinaryClient.LIST_POSITION;
import redis.clients.jedis.ShardedJedis;
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.Tuple;
/**
* Redis缓存辅助类
*
* @author ShenHuaJie
* @version 2016年4月2日 下午4:17:22
*/
public final class RedisUtil {
private RedisUtil() {
}
public static final String get(final String key) {
return JedisTemplate.run(key, new Executor<String>() {
public String execute(ShardedJedis jedis) {
return jedis.get(key);
}
});
}
public static final String set(final String key, final Integer seconds, final Object value) {
return JedisTemplate.run(key, new Executor<String>() {
public String execute(ShardedJedis jedis) {
return jedis.setex(key, seconds, JSON.toJSONString(value));
}
}, true);
}
public static final Boolean exists(final String key) {
return JedisTemplate.run(key, new Executor<Boolean>() {
public Boolean execute(ShardedJedis jedis) {
return jedis.exists(key);
}
});
}
public static final Long del(final String key) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.del(key);
}
});
}
public static final String type(final String key) {
return JedisTemplate.run(key, new Executor<String>() {
public String execute(ShardedJedis jedis) {
return jedis.type(key);
}
});
}
/**
* 在某段时间后失效
*
* @return
*/
public static final Long expire(final String key, final int seconds) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.expire(key, seconds);
}
}, true);
}
/**
* 在某个时间点失效
*
* @param key
* @param unixTime
* @return
*/
public static final Long expireAt(final String key, final long unixTime) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.expireAt(key, unixTime);
}
});
}
public static final Long ttl(final String key) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.ttl(key);
}
});
}
public static final Boolean setbit(final String key, final long offset, final boolean value) {
return JedisTemplate.run(key, new Executor<Boolean>() {
public Boolean execute(ShardedJedis jedis) {
return jedis.setbit(key, offset, value);
}
});
}
public static final Boolean getbit(final String key, final long offset) {
return JedisTemplate.run(key, new Executor<Boolean>() {
public Boolean execute(ShardedJedis jedis) {
return jedis.getbit(key, offset);
}
});
}
public static final Long setrange(final String key, final long offset, final String value) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.setrange(key, offset, value);
}
});
}
public static final String getrange(final String key, final long startOffset, final long endOffset) {
return JedisTemplate.run(key, new Executor<String>() {
public String execute(ShardedJedis jedis) {
return jedis.getrange(key, startOffset, endOffset);
}
});
}
public static final String getSet(final String key, final String value) {
return JedisTemplate.run(key, new Executor<String>() {
public String execute(ShardedJedis jedis) {
return jedis.getSet(key, value);
}
});
}
public static final Long setnx(final String key, final String value) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.setnx(key, value);
}
});
}
public static final String setex(final String key, final int seconds, final String value) {
return JedisTemplate.run(key, new Executor<String>() {
public String execute(ShardedJedis jedis) {
return jedis.setex(key, seconds, value);
}
}, true);
}
public static final Long decrBy(final String key, final long integer) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.decrBy(key, integer);
}
});
}
public static final Long decr(final String key) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.decr(key);
}
});
}
public static final Long incrBy(final String key, final long integer) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.incrBy(key, integer);
}
});
}
public static final Long incr(final String key) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.incr(key);
}
});
}
public static final Long append(final String key, final String value) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.append(key, value);
}
});
}
public static final String substr(final String key, final int start, final int end) {
return JedisTemplate.run(key, new Executor<String>() {
public String execute(ShardedJedis jedis) {
return jedis.substr(key, start, end);
}
});
}
public static final Long hset(final String key, final String field, final String value) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.hset(key, field, value);
}
});
}
public static final String hget(final String key, final String field) {
return JedisTemplate.run(key, new Executor<String>() {
public String execute(ShardedJedis jedis) {
return jedis.hget(key, field);
}
});
}
public static final Long hsetnx(final String key, final String field, final String value) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.hsetnx(key, field, value);
}
});
}
public static final String hmset(final String key, final Map<String, String> hash) {
return JedisTemplate.run(key, new Executor<String>() {
public String execute(ShardedJedis jedis) {
return jedis.hmset(key, hash);
}
});
}
public static final List<String> hmget(final String key, final String... fields) {
return JedisTemplate.run(key, new Executor<List<String>>() {
public List<String> execute(ShardedJedis jedis) {
return jedis.hmget(key, fields);
}
});
}
public static final Long hincrBy(final String key, final String field, final long value) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.hincrBy(key, field, value);
}
});
}
public static final Boolean hexists(final String key, final String field) {
return JedisTemplate.run(key, new Executor<Boolean>() {
public Boolean execute(ShardedJedis jedis) {
return jedis.hexists(key, field);
}
});
}
public static final Long hdel(final String key, final String field) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.hdel(key, field);
}
});
}
public static final Long hlen(final String key) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.hlen(key);
}
});
}
public static final Set<String> hkeys(final String key) {
return JedisTemplate.run(key, new Executor<Set<String>>() {
public Set<String> execute(ShardedJedis jedis) {
return jedis.hkeys(key);
}
});
}
public static final List<String> hvals(final String key) {
return JedisTemplate.run(key, new Executor<List<String>>() {
public List<String> execute(ShardedJedis jedis) {
return jedis.hvals(key);
}
});
}
public static final Map<String, String> hgetAll(final String key) {
return JedisTemplate.run(key, new Executor<Map<String, String>>() {
public Map<String, String> execute(ShardedJedis jedis) {
return jedis.hgetAll(key);
}
});
}
public static final Long rpush(final String key, final String string) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.rpush(key, string);
}
});
}
public static final Long lpush(final String key, final String string) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.lpush(key, string);
}
});
}
public static final Long llen(final String key) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.llen(key);
}
});
}
public static final List<String> lrange(final String key, final long start, final long end) {
return JedisTemplate.run(key, new Executor<List<String>>() {
public List<String> execute(ShardedJedis jedis) {
return jedis.lrange(key, start, end);
}
});
}
public static final String ltrim(final String key, final long start, final long end) {
return JedisTemplate.run(key, new Executor<String>() {
public String execute(ShardedJedis jedis) {
return jedis.ltrim(key, start, end);
}
});
}
public static final String lindex(final String key, final long index) {
return JedisTemplate.run(key, new Executor<String>() {
public String execute(ShardedJedis jedis) {
return jedis.lindex(key, index);
}
});
}
public static final String lset(final String key, final long index, final String value) {
return JedisTemplate.run(key, new Executor<String>() {
public String execute(ShardedJedis jedis) {
return jedis.lset(key, index, value);
}
});
}
public static final Long lrem(final String key, final long count, final String value) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.lrem(key, count, value);
}
});
}
public static final String lpop(final String key) {
return JedisTemplate.run(key, new Executor<String>() {
public String execute(ShardedJedis jedis) {
return jedis.lpop(key);
}
});
}
public static final String rpop(final String key) {
return JedisTemplate.run(key, new Executor<String>() {
public String execute(ShardedJedis jedis) {
return jedis.rpop(key);
}
});
}
// return 1 add a not exist value ,
// return 0 add a exist value
public static final Long sadd(final String key, final String member) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.sadd(key, member);
}
});
}
public static final Set<String> smembers(final String key) {
return JedisTemplate.run(key, new Executor<Set<String>>() {
public Set<String> execute(ShardedJedis jedis) {
return jedis.smembers(key);
}
});
}
public static final Long srem(final String key, final String member) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.srem(key, member);
}
});
}
public static final String spop(final String key) {
return JedisTemplate.run(key, new Executor<String>() {
public String execute(ShardedJedis jedis) {
return jedis.spop(key);
}
});
}
public static final Long scard(final String key) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.scard(key);
}
});
}
public static final Boolean sismember(final String key, final String member) {
return JedisTemplate.run(key, new Executor<Boolean>() {
public Boolean execute(ShardedJedis jedis) {
return jedis.sismember(key, member);
}
});
}
public static final String srandmember(final String key) {
return JedisTemplate.run(key, new Executor<String>() {
public String execute(ShardedJedis jedis) {
return jedis.srandmember(key);
}
});
}
public static final Long zadd(final String key, final double score, final String member) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.zadd(key, score, member);
}
});
}
public static final Set<String> zrange(final String key, final int start, final int end) {
return JedisTemplate.run(key, new Executor<Set<String>>() {
public Set<String> execute(ShardedJedis jedis) {
return jedis.zrange(key, start, end);
}
});
}
public static final Long zrem(final String key, final String member) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.zrem(key, member);
}
});
}
public static final Double zincrby(final String key, final double score, final String member) {
return JedisTemplate.run(key, new Executor<Double>() {
public Double execute(ShardedJedis jedis) {
return jedis.zincrby(key, score, member);
}
});
}
public static final Long zrank(final String key, final String member) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.zrank(key, member);
}
});
}
public static final Long zrevrank(final String key, final String member) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.zrevrank(key, member);
}
});
}
public static final Set<String> zrevrange(final String key, final int start, final int end) {
return JedisTemplate.run(key, new Executor<Set<String>>() {
public Set<String> execute(ShardedJedis jedis) {
return jedis.zrevrange(key, start, end);
}
});
}
public static final Set<Tuple> zrangeWithScores(final String key, final int start, final int end) {
return JedisTemplate.run(key, new Executor<Set<Tuple>>() {
public Set<Tuple> execute(ShardedJedis jedis) {
return jedis.zrangeWithScores(key, start, end);
}
});
}
public static final Set<Tuple> zrevrangeWithScores(final String key, final int start, final int end) {
return JedisTemplate.run(key, new Executor<Set<Tuple>>() {
public Set<Tuple> execute(ShardedJedis jedis) {
return jedis.zrevrangeWithScores(key, start, end);
}
});
}
public static final Long zcard(final String key) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.zcard(key);
}
});
}
public static final Double zscore(final String key, final String member) {
return JedisTemplate.run(key, new Executor<Double>() {
public Double execute(ShardedJedis jedis) {
return jedis.zscore(key, member);
}
});
}
public static final List<String> sort(final String key) {
return JedisTemplate.run(key, new Executor<List<String>>() {
public List<String> execute(ShardedJedis jedis) {
return jedis.sort(key);
}
});
}
public static final List<String> sort(final String key, final SortingParams sortingParameters) {
return JedisTemplate.run(key, new Executor<List<String>>() {
public List<String> execute(ShardedJedis jedis) {
return jedis.sort(key, sortingParameters);
}
});
}
public static final Long zcount(final String key, final double min, final double max) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.zcount(key, min, max);
}
});
}
public static final Set<String> zrangeByScore(final String key, final double min, final double max) {
return JedisTemplate.run(key, new Executor<Set<String>>() {
public Set<String> execute(ShardedJedis jedis) {
return jedis.zrangeByScore(key, min, max);
}
});
}
public static final Set<String> zrevrangeByScore(final String key, final double max, final double min) {
return JedisTemplate.run(key, new Executor<Set<String>>() {
public Set<String> execute(ShardedJedis jedis) {
return jedis.zrevrangeByScore(key, max, min);
}
});
}
public static final Set<String> zrangeByScore(final String key, final double min, final double max,
final int offset, final int count) {
return JedisTemplate.run(key, new Executor<Set<String>>() {
public Set<String> execute(ShardedJedis jedis) {
return jedis.zrangeByScore(key, min, max, offset, count);
}
});
}
public static final Set<String> zrevrangeByScore(final String key, final double max, final double min,
final int offset, final int count) {
return JedisTemplate.run(key, new Executor<Set<String>>() {
public Set<String> execute(ShardedJedis jedis) {
return jedis.zrevrangeByScore(key, max, min, offset, count);
}
});
}
public static final Set<Tuple> zrangeByScoreWithScores(final String key, final double min, final double max) {
return JedisTemplate.run(key, new Executor<Set<Tuple>>() {
public Set<Tuple> execute(ShardedJedis jedis) {
return jedis.zrangeByScoreWithScores(key, min, max);
}
});
}
public static final Set<Tuple> zrevrangeByScoreWithScores(final String key, final double max, final double min) {
return JedisTemplate.run(key, new Executor<Set<Tuple>>() {
public Set<Tuple> execute(ShardedJedis jedis) {
return jedis.zrevrangeByScoreWithScores(key, max, min);
}
});
}
public static final Set<Tuple> zrangeByScoreWithScores(final String key, final double min, final double max,
final int offset, final int count) {
return JedisTemplate.run(key, new Executor<Set<Tuple>>() {
public Set<Tuple> execute(ShardedJedis jedis) {
return jedis.zrangeByScoreWithScores(key, min, max, offset, count);
}
});
}
public static final Set<Tuple> zrevrangeByScoreWithScores(final String key, final double max, final double min,
final int offset, final int count) {
return JedisTemplate.run(key, new Executor<Set<Tuple>>() {
public Set<Tuple> execute(ShardedJedis jedis) {
return jedis.zrevrangeByScoreWithScores(key, max, min, offset, count);
}
});
}
public static final Long zremrangeByRank(final String key, final int start, final int end) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.zremrangeByRank(key, start, end);
}
});
}
public static final Long zremrangeByScore(final String key, final double start, final double end) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.zremrangeByScore(key, start, end);
}
});
}
public static final Long linsert(final String key, final LIST_POSITION where, final String pivot,
final String value) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.linsert(key, where, pivot, value);
}
});
}
public static final String set(final byte[] key, final byte[] value) {
return JedisTemplate.run(key, new Executor<String>() {
public String execute(ShardedJedis jedis) {
return jedis.set(key, value);
}
});
}
public static final byte[] get(final byte[] key) {
return JedisTemplate.run(key, new Executor<byte[]>() {
public byte[] execute(ShardedJedis jedis) {
return jedis.get(key);
}
});
}
public static final Boolean exists(final byte[] key) {
return JedisTemplate.run(key, new Executor<Boolean>() {
public Boolean execute(ShardedJedis jedis) {
return jedis.exists(key);
}
});
}
public static final String type(final byte[] key) {
return JedisTemplate.run(key, new Executor<String>() {
public String execute(ShardedJedis jedis) {
return jedis.type(key);
}
});
}
public static final Long expire(final byte[] key, final int seconds) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.expire(key, seconds);
}
}, true);
}
public static final Long expireAt(final byte[] key, final long unixTime) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.expireAt(key, unixTime);
}
});
}
public static final Long ttl(final byte[] key) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.ttl(key);
}
});
}
public static final Long del(final byte[] key) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.del(key);
}
});
}
public byte[] getSet(final byte[] key, final byte[] value) {
return JedisTemplate.run(key, new Executor<byte[]>() {
public byte[] execute(ShardedJedis jedis) {
return jedis.getSet(key, value);
}
});
}
public Long setnx(final byte[] key, final byte[] value) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.setnx(key, value);
}
});
}
public String setex(final byte[] key, final int seconds, final byte[] value) {
return JedisTemplate.run(key, new Executor<String>() {
public String execute(ShardedJedis jedis) {
return jedis.setex(key, seconds, value);
}
}, true);
}
public Long decrBy(final byte[] key, final long integer) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.decrBy(key, integer);
}
});
}
public Long decr(final byte[] key) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.decr(key);
}
});
}
public Long incrBy(final byte[] key, final long integer) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.incrBy(key, integer);
}
});
}
public Long incr(final byte[] key) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.incr(key);
}
});
}
public Long append(final byte[] key, final byte[] value) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.append(key, value);
}
});
}
public byte[] substr(final byte[] key, final int start, final int end) {
return JedisTemplate.run(key, new Executor<byte[]>() {
public byte[] execute(ShardedJedis jedis) {
return jedis.substr(key, start, end);
}
});
}
public Long hset(final byte[] key, final byte[] field, final byte[] value) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.hset(key, field, value);
}
});
}
public byte[] hget(final byte[] key, final byte[] field) {
return JedisTemplate.run(key, new Executor<byte[]>() {
public byte[] execute(ShardedJedis jedis) {
return jedis.hget(key, field);
}
});
}
public Long hsetnx(final byte[] key, final byte[] field, final byte[] value) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.hsetnx(key, field, value);
}
});
}
public String hmset(final byte[] key, final Map<byte[], byte[]> hash) {
return JedisTemplate.run(key, new Executor<String>() {
public String execute(ShardedJedis jedis) {
return jedis.hmset(key, hash);
}
});
}
public List<byte[]> hmget(final byte[] key, final byte[]... fields) {
return JedisTemplate.run(key, new Executor<List<byte[]>>() {
public List<byte[]> execute(ShardedJedis jedis) {
return jedis.hmget(key, fields);
}
});
}
public Long hincrBy(final byte[] key, final byte[] field, final long value) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.hincrBy(key, field, value);
}
});
}
public Boolean hexists(final byte[] key, final byte[] field) {
return JedisTemplate.run(key, new Executor<Boolean>() {
public Boolean execute(ShardedJedis jedis) {
return jedis.hexists(key, field);
}
});
}
public Long hdel(final byte[] key, final byte[] field) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.hdel(key, field);
}
});
}
public Long hlen(final byte[] key) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.hlen(key);
}
});
}
public static final Set<byte[]> hkeys(final byte[] key) {
return JedisTemplate.run(key, new Executor<Set<byte[]>>() {
public Set<byte[]> execute(ShardedJedis jedis) {
return jedis.hkeys(key);
}
});
}
public static final Collection<byte[]> hvals(final byte[] key) {
return JedisTemplate.run(key, new Executor<Collection<byte[]>>() {
public Collection<byte[]> execute(ShardedJedis jedis) {
return jedis.hvals(key);
}
});
}
public static final Map<byte[], byte[]> hgetAll(final byte[] key) {
return JedisTemplate.run(key, new Executor<Map<byte[], byte[]>>() {
public Map<byte[], byte[]> execute(ShardedJedis jedis) {
return jedis.hgetAll(key);
}
});
}
public static final Long rpush(final byte[] key, final byte[] string) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.rpush(key, string);
}
});
}
public static final Long lpush(final byte[] key, final byte[] string) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.lpush(key, string);
}
});
}
public static final Long llen(final byte[] key) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.llen(key);
}
});
}
public static final List<byte[]> lrange(final byte[] key, final int start, final int end) {
return JedisTemplate.run(key, new Executor<List<byte[]>>() {
public List<byte[]> execute(ShardedJedis jedis) {
return jedis.lrange(key, start, end);
}
});
}
public static final String ltrim(final byte[] key, final int start, final int end) {
return JedisTemplate.run(key, new Executor<String>() {
public String execute(ShardedJedis jedis) {
return jedis.ltrim(key, start, end);
}
});
}
public static final byte[] lindex(final byte[] key, final int index) {
return JedisTemplate.run(key, new Executor<byte[]>() {
public byte[] execute(ShardedJedis jedis) {
return jedis.lindex(key, index);
}
});
}
public static final String lset(final byte[] key, final int index, final byte[] value) {
return JedisTemplate.run(key, new Executor<String>() {
public String execute(ShardedJedis jedis) {
return jedis.lset(key, index, value);
}
});
}
public static final Long lrem(final byte[] key, final int count, final byte[] value) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.lrem(key, count, value);
}
});
}
public static final byte[] lpop(final byte[] key) {
return JedisTemplate.run(key, new Executor<byte[]>() {
public byte[] execute(ShardedJedis jedis) {
return jedis.lpop(key);
}
});
}
public static final byte[] rpop(final byte[] key) {
return JedisTemplate.run(key, new Executor<byte[]>() {
public byte[] execute(ShardedJedis jedis) {
return jedis.rpop(key);
}
});
}
public static final Long sadd(final byte[] key, final byte[] member) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.sadd(key, member);
}
});
}
public static final Set<byte[]> smembers(final byte[] key) {
return JedisTemplate.run(key, new Executor<Set<byte[]>>() {
public Set<byte[]> execute(ShardedJedis jedis) {
return jedis.smembers(key);
}
});
}
public static final Long srem(final byte[] key, final byte[] member) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.srem(key, member);
}
});
}
public static final byte[] spop(final byte[] key) {
return JedisTemplate.run(key, new Executor<byte[]>() {
public byte[] execute(ShardedJedis jedis) {
return jedis.spop(key);
}
});
}
public static final Long scard(final byte[] key) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.scard(key);
}
});
}
public static final Boolean sismember(final byte[] key, final byte[] member) {
return JedisTemplate.run(key, new Executor<Boolean>() {
public Boolean execute(ShardedJedis jedis) {
return jedis.sismember(key, member);
}
});
}
public static final byte[] srandmember(final byte[] key) {
return JedisTemplate.run(key, new Executor<byte[]>() {
public byte[] execute(ShardedJedis jedis) {
return jedis.srandmember(key);
}
});
}
public static final Long zadd(final byte[] key, final double score, final byte[] member) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.zadd(key, score, member);
}
});
}
public static final Set<byte[]> zrange(final byte[] key, final int start, final int end) {
return JedisTemplate.run(key, new Executor<Set<byte[]>>() {
public Set<byte[]> execute(ShardedJedis jedis) {
return jedis.zrange(key, start, end);
}
});
}
public static final Long zrem(final byte[] key, final byte[] member) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.zrem(key, member);
}
});
}
public static final Double zincrby(final byte[] key, final double score, final byte[] member) {
return JedisTemplate.run(key, new Executor<Double>() {
public Double execute(ShardedJedis jedis) {
return jedis.zincrby(key, score, member);
}
});
}
public static final Long zrank(final byte[] key, final byte[] member) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.zrank(key, member);
}
});
}
public static final Long zrevrank(final byte[] key, final byte[] member) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.zrevrank(key, member);
}
});
}
public static final Set<byte[]> zrevrange(final byte[] key, final int start, final int end) {
return JedisTemplate.run(key, new Executor<Set<byte[]>>() {
public Set<byte[]> execute(ShardedJedis jedis) {
return jedis.zrevrange(key, start, end);
}
});
}
public static final Set<Tuple> zrangeWithScores(final byte[] key, final int start, final int end) {
return JedisTemplate.run(key, new Executor<Set<Tuple>>() {
public Set<Tuple> execute(ShardedJedis jedis) {
return jedis.zrangeWithScores(key, start, end);
}
});
}
public static final Set<Tuple> zrevrangeWithScores(final byte[] key, final int start, final int end) {
return JedisTemplate.run(key, new Executor<Set<Tuple>>() {
public Set<Tuple> execute(ShardedJedis jedis) {
return jedis.zrevrangeWithScores(key, start, end);
}
});
}
public static final Long zcard(final byte[] key) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.zcard(key);
}
});
}
public static final Double zscore(final byte[] key, final byte[] member) {
return JedisTemplate.run(key, new Executor<Double>() {
public Double execute(ShardedJedis jedis) {
return jedis.zscore(key, member);
}
});
}
public static final List<byte[]> sort(final byte[] key) {
return JedisTemplate.run(key, new Executor<List<byte[]>>() {
public List<byte[]> execute(ShardedJedis jedis) {
return jedis.sort(key);
}
});
}
public static final List<byte[]> sort(final byte[] key, final SortingParams sortingParameters) {
return JedisTemplate.run(key, new Executor<List<byte[]>>() {
public List<byte[]> execute(ShardedJedis jedis) {
return jedis.sort(key, sortingParameters);
}
});
}
public static final Long zcount(final byte[] key, final double min, final double max) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.zcount(key, min, max);
}
});
}
public static final Set<byte[]> zrangeByScore(final byte[] key, final double min, final double max) {
return JedisTemplate.run(key, new Executor<Set<byte[]>>() {
public Set<byte[]> execute(ShardedJedis jedis) {
return jedis.zrangeByScore(key, min, max);
}
});
}
public static final Set<byte[]> zrangeByScore(final byte[] key, final double min, final double max,
final int offset, final int count) {
return JedisTemplate.run(key, new Executor<Set<byte[]>>() {
public Set<byte[]> execute(ShardedJedis jedis) {
return jedis.zrangeByScore(key, min, max, offset, count);
}
});
}
public static final Set<Tuple> zrangeByScoreWithScores(final byte[] key, final double min, final double max) {
return JedisTemplate.run(key, new Executor<Set<Tuple>>() {
public Set<Tuple> execute(ShardedJedis jedis) {
return jedis.zrangeByScoreWithScores(key, min, max);
}
});
}
public static final Set<Tuple> zrangeByScoreWithScores(final byte[] key, final double min, final double max,
final int offset, final int count) {
return JedisTemplate.run(key, new Executor<Set<Tuple>>() {
public Set<Tuple> execute(ShardedJedis jedis) {
return jedis.zrangeByScoreWithScores(key, min, max, offset, count);
}
});
}
public static final Set<byte[]> zrevrangeByScore(final byte[] key, final double max, final double min) {
return JedisTemplate.run(key, new Executor<Set<byte[]>>() {
public Set<byte[]> execute(ShardedJedis jedis) {
return jedis.zrevrangeByScore(key, max, min);
}
});
}
public static final Set<byte[]> zrevrangeByScore(final byte[] key, final double max, final double min,
final int offset, final int count) {
return JedisTemplate.run(key, new Executor<Set<byte[]>>() {
public Set<byte[]> execute(ShardedJedis jedis) {
return jedis.zrevrangeByScore(key, max, min, offset, count);
}
});
}
public static final Set<Tuple> zrevrangeByScoreWithScores(final byte[] key, final double max, final double min) {
return JedisTemplate.run(key, new Executor<Set<Tuple>>() {
public Set<Tuple> execute(ShardedJedis jedis) {
return jedis.zrevrangeByScoreWithScores(key, max, min);
}
});
}
public static final Set<Tuple> zrevrangeByScoreWithScores(final byte[] key, final double max, final double min,
final int offset, final int count) {
return JedisTemplate.run(key, new Executor<Set<Tuple>>() {
public Set<Tuple> execute(ShardedJedis jedis) {
return jedis.zrevrangeByScoreWithScores(key, max, min, offset, count);
}
});
}
public static final Long zremrangeByRank(final byte[] key, final int start, final int end) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.zremrangeByRank(key, start, end);
}
});
}
public static final Long zremrangeByScore(final byte[] key, final double start, final double end) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.zremrangeByScore(key, start, end);
}
});
}
public static final Long linsert(final byte[] key, final LIST_POSITION where, final byte[] pivot,
final byte[] value) {
return JedisTemplate.run(key, new Executor<Long>() {
public Long execute(ShardedJedis jedis) {
return jedis.linsert(key, where, pivot, value);
}
});
}
public static final String getKeyTag(final String key) {
return JedisTemplate.run(key, new Executor<String>() {
public String execute(ShardedJedis jedis) {
return jedis.getKeyTag(key);
}
});
}
}