springboot+redis配置

一、工程目录


 

二、主要配置文件

(1)父类pom文件

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

	<modelVersion>4.0.0</modelVersion>
	<groupId>com.demo</groupId>
	<artifactId>springboot</artifactId>
	<packaging>pom</packaging>
	<version>1.0</version>
    <modules>
        <module>platform</module>
    </modules>
    <name>springboot</name>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.3.RELEASE</version>
    </parent>

    <properties>
        <main.basedir>${basedir}</main.basedir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.7</java.version>
        <project.deploy.directory>${basedir}/target</project.deploy.directory>
        <mybatis-spring-boot.version>1.3.1</mybatis-spring-boot.version>
        <druid.version>1.0.26</druid.version>
    </properties>

    <dependencyManagement>

    </dependencyManagement>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.2</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.1</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>


</project>

 

(2)子类pom文件

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>springboot</artifactId>
        <groupId>com.demo</groupId>
        <version>1.0</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <packaging>jar</packaging>
    <artifactId>platform</artifactId>
    <name>platform</name>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- mybatis -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>${mybatis-spring-boot.version}</version>
        </dependency>
        <!-- 数据源 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.47</version>
        </dependency>
        <!-- druid 连接池 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>${druid.version}</version>
        </dependency>
        <!-- redis -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- 该插件为Spring Boot应用提供了执行Maven操作的 -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <!-- 打包后的输出路径 -->
                    <outputDirectory>${project.deploy.directory}</outputDirectory>
                </configuration>
            </plugin>
            <!-- 编译插件,用于指定编译的jdk版本 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <!-- 将当前项目打包为Jar包 -->
            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            </plugin>
            <!-- 用于定制化打包方式 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <id>config-zip</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <skipAssembly>false</skipAssembly>
                            <!-- 打包输出路径 -->
                            <outputDirectory>${project.deploy.directory}</outputDirectory>
                            <!-- 描述符文件,用于描述那些文件需要被打包 -->
                            <descriptor>src/main/assembly/config-zip.xml</descriptor>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>


</project>

 

(3)application.properties文件

spring.application.name=springboot_demo

#tomcat访问上下文路径
server.context-path=/springboot_demo
#指定tomcat端口
server.port=8090
#指定tomcat的编码格式
server.tomcat.uri-encoding=UTF-8
#配置字符集过滤器
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true

################## Redis单机模式配置  ##################
## Redis数据库索引(默认为0)
spring.redis.database=5
## Redis服务器地址
spring.redis.host=xxxxxxx
## Redis服务器连接端口
spring.redis.port=xxx
## 连接池最大连接数(使用负值表示没有限制)
spring.redis.pool.max-active=150
## 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.pool.max-wait=-1
## 连接池中的最大空闲连接
spring.redis.pool.max-idle=30
## 连接池中的最小空闲连接
spring.redis.pool.min-idle=10
## 连接超时时间(毫秒)
spring.redis.timeout=10000
################## Redis服务器端集群模式配置  ##################
#spring.redis.cluster.nodes=xxxxxxxx,xxxxxxxx,xxxxxxx
#spring.redis.cluster.max-redirects=3

 

(4)redis配置文件

@Configuration
@EnableCaching
public class RedisConfig extends CachingConfigurerSupport {

    @Bean
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>();
        redisTemplate.setConnectionFactory(connectionFactory);

        //采用StringRedisSerializer来序列化/反序列化key
        RedisSerializer<String> stringSerializer = new StringRedisSerializer();
        redisTemplate.setKeySerializer(stringSerializer);
        redisTemplate.setHashKeySerializer(stringSerializer);
        redisTemplate.afterPropertiesSet();

        //使用Jackson2JsonRedisSerializer来序列化/反序列化value
		Jackson2JsonRedisSerializer<Object> jackson2JsonSerializer = new Jackson2JsonRedisSerializer<Object>(Object.class);
		ObjectMapper objectMapper = new ObjectMapper();
		objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
		objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
        jackson2JsonSerializer.setObjectMapper(objectMapper);
        redisTemplate.setValueSerializer(jackson2JsonSerializer);
        redisTemplate.setHashValueSerializer(jackson2JsonSerializer);

        return redisTemplate;
    }

    @Bean
    public ValueOperations<String, Object> valueOperations(RedisTemplate<String, Object> redisTemplate) {
        return redisTemplate.opsForValue();
    }

    @Bean
    public HashOperations<String, String, Object> hashOperations(RedisTemplate<String, Object> redisTemplate) {
        return redisTemplate.opsForHash();
    }

    @Bean
    public ListOperations<String, Object> listOperations(RedisTemplate<String, Object> redisTemplate) {
        return redisTemplate.opsForList();
    }

    @Bean
    public SetOperations<String, Object> setOperations(RedisTemplate<String, Object> redisTemplate) {
        return redisTemplate.opsForSet();
    }

    @Bean
    public ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) {
        return redisTemplate.opsForZSet();
    }

    @Bean
    public CacheManager cacheManager(RedisTemplate<String, Object> redisTemplate) {
        CacheManager cacheManager = new RedisCacheManager(redisTemplate);
        return cacheManager;
    }

}

 

(5)redis工具类

@Component
public class RedisClient {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Autowired
    private ValueOperations<String, Object> valueOperations;

    @Autowired
    private HashOperations<String, String, Object> hashOperations;

    @Autowired
    private ListOperations<String, Object> listOperations;

    @Autowired
    private SetOperations<String, Object> setOperations;

    @Autowired
    private ZSetOperations<String, Object> zSetOperations;

    /**
     * 设置key对应的值为对象类型的value。
     * <p>
     * 如果该key已经存在,则覆盖其原有值,忽略类型。
     * <p>
     * 对于某个原本带有生存时间(TTL)的key来说, 当SET命令在这个key上执行成功时, 这个键原有的 TTL将被清除。
     *
     * @param key
     * @param value
     */
    public void set(String key, Object value) {
        valueOperations.set(key, value);
    }

    /**
     * 设置key对应的值为字符串类型的value。
     * <p>
     * 如果key已经存在, 则覆盖其原有值,忽略类型。
     * <p>
     * 对于某个原本带有生存时间(TTL)的key来说, 当SET命令在这个key上执行成功时, 这个键原有的 TTL将被清除。
     *
     * @param key
     * @param value
     */
    public void setString(String key, String value) {
        final byte[] rawKey = rawKey(key);
        final byte[] rawValue = rawValue(value);
        redisTemplate.execute(new RedisCallback<Object>() {
            @Override
            public Object doInRedis(RedisConnection connection) throws DataAccessException {
                connection.set(rawKey, rawValue);
                return null;
            }
        }, true);
    }

    /**
     * 设置key对应的值为对象类型的value,并指定该键值对应的有效期(单位:秒)。
     * <p>
     * 如果key已经存在, 则覆盖其原有值,忽略类型。
     *
     * @param key
     * @param value
     * @param seconds
     */
    public void set(String key, Object value, long seconds) {
        valueOperations.set(key, value, seconds, TimeUnit.SECONDS);
    }

    /**
     * 设置key对应的值为字符串类型的value,并指定该键值对应的有效期(单位:秒)。
     * <p>
     * 如果key已经存在, 则覆盖其原有值,忽略类型。
     *
     * @param key
     * @param value
     * @param seconds 有效时间
     */
    public void setString(final String key, final String value, final long seconds) {
        final byte[] rawKey = rawKey(key);
        final byte[] rawValue = rawValue(value);
        redisTemplate.execute(new RedisCallback<Object>() {
            @Override
            public Object doInRedis(RedisConnection connection) throws DataAccessException {
                connection.setEx(rawKey, seconds, rawValue);
                return null;
            }
        }, true);
    }

    /**
     * 设置key对应的值为对象类型的value,并指定该键值对应的有效期(自定义时间粒度)。
     * <p>
     * 如果key已经存在, 则覆盖其原有值,忽略类型。
     *
     * @param key
     * @param value
     * @param timeout 有效时间
     * @param unit 时间单位
     */
    public void set(String key, Object value, long timeout, TimeUnit unit) {
        valueOperations.set(key, value, timeout, unit);
    }

    /**
     * 获取key所关联的对象值,如果key不存在返回null。
     *
     * @param key
     * @return
     */
    @SuppressWarnings("unchecked")
    public <T> T get(String key) {
        return (T) valueOperations.get(key);
    }

    /**
     * 获取key对应的字符串值,如果key不存在返回null。
     *
     * @param key
     * @return
     */
    public String getString(String key) {
        final byte[] rawKey = rawKey(key);
        return redisTemplate.execute(new RedisCallback<String>() {
            @Override
            public String doInRedis(RedisConnection connection) throws DataAccessException {
                byte[] result = connection.get(rawKey);
                return redisTemplate.getStringSerializer().deserialize(result);
            }
        }, true);
    }

    /**
     * 设置key对应对象类型的value,并返回key的旧值。
     *
     * @param key
     * @param value
     * @return 返回给定key的旧值。当key不存在时,返回null。

     */
    @SuppressWarnings("unchecked")
    public <T> T getSet(String key, Object value) {
        return (T) valueOperations.getAndSet(key, value);
    }

    /**
     * 检查指定的key是否存在。
     *
     * @param key
     * @return 若key存在,返回 true,否则返回false。
     */
    public Boolean exists(String key) {
        return redisTemplate.hasKey(key);
    }

    /**
     * 将key的值设为value,当且仅当 key不存在。
     *
     * 若给定的key已经存在,则 SETNX不做任何动作。
     *
     * @param key
     * @param value
     * @return 设置成功,返回true。设置失败,返回 false。
     */
    public Boolean setnx(String key, Object value) {
        return valueOperations.setIfAbsent(key, value);
    }

    /**
     * 为给定的key设置过期时间,当 key过期时(生存时间为 0),它会被自动删除。
     *
     * @param key
     * @param timeout 过期时间,单位为秒
     * @return 若设置成功返回 true ,否则当 key不存在或者不能为 key设置过期时间时,返回 false。
     */
    public Boolean expire(String key, long timeout) {
        return redisTemplate.expire(key, timeout, TimeUnit.SECONDS);
    }

    /**
     * 为给定的key设置过期时间,当 key过期时(生存时间为 0),它会被自动删除。
     *
     * @param key
     * @param timeout 过期时间
     * @param unit 时间单位
     * @return 若设置成功返回 true ,否则当 key不存在或者不能为 key设置过期时间时,返回 false。
     */
    public Boolean expire(String key, long timeout, TimeUnit unit) {
        return redisTemplate.expire(key, timeout, unit);
    }

    /**
     * 为给定的key设置过期时间,当 key过期时(到达过期时间),它会被自动删除。
     *
     * @param key
     * @param expire UNIX时间戳
     * @return 若过期时间设置成功,返回 true。否则当 key不存在或无法设置过期时间,返回 false。
     */
    public Boolean expireAt(final String key, final long expire) {
        final byte[] rawKey = rawKey(key);
        return redisTemplate.execute(new RedisCallback<Boolean>() {
            @Override
            public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
                return connection.expireAt(rawKey, expire);
            }
        });
    }

    /**
     * 为给定的key设置过期时间,当 key过期时(到达过期时间),它会被自动删除。
     *
     * @param key
     * @param expireTime 过期时间
     * @return 若过期时间设置成功,返回 true。否则当 key不存在或无法设置过期时间,返回 false。
     */
    public Boolean expireAt(String key, Date expireTime) {
        return redisTemplate.expireAt(key, expireTime);
    }

    /**
     * 获取给定key的剩余生存时间(TTL, time to live),以秒为单位。
     *
     * @param key
     * @return 返回key的剩余生存时间,若 key不存在时,返回 -2;若key存在但没有设置生存时间时,返回 -1 。
     */
    public Long getExpire(String key) {
        return redisTemplate.getExpire(key);
    }

    /**
     * 获取给定key的剩余生存时间(TTL, time to live)。
     *
     * @param key
     * @param timeUnit 时间单位
     * @return 返回key的剩余生存时间,若 key不存在时,返回 -2;若key存在但没有设置生存时间时,返回 -1 。
     */
    public Long getExpire(String key, TimeUnit timeUnit) {
        return redisTemplate.getExpire(key, timeUnit);
    }

    /**
     * 移除给定key的生存时间,将这个 key从带生存时间的转换成永不过期的key。
     *
     * @param key
     * @return 若生存时间移除成功,返回 true, 否则如果key不存在或 key没有设置生存时间,返回 false。
     */
    public Boolean persist(String key) {
        return redisTemplate.persist(key);
    }

    /**
     * 删除指定的一个 key,不存在的 key会被忽略。
     *
     * @param key
     */
    public void del(String key) {
        redisTemplate.delete(key);
    }

    /**
     * 删除指定的多个 key,不存在的 key会被忽略。
     *
     * @param keys
     */
    public void del(Collection<String> keys) {
        redisTemplate.delete(keys);
    }

    /**
     * 返回 key所储存的值的类型。
     *
     * @param key
     * @return none(key不存在)、string(字符串)、list(列表)、set(集合)、zset(有序集)、hash(哈希表)
     */
    public String type(String key) {
        return redisTemplate.type(key).name();
    }

    /**
     * 设置在key对应指定offset上bit的值(value),该值只能为1或者0,返回该offset上原有的bit值。
     * <p>
     * 如果key不存在,将创建一个新值,并在指定的offset上设定bit值。
     * <p>
     * 如果offset大于value的字符串长度,redis将拉长value值并在指定offset上设置参数中的bit值,之间添加的bit值为0。
     *
     * @param key
     * @param offset
     * @param value
     * @return 指定偏移量原来储存的位。
     */
    public Boolean setBit(String key, long offset, boolean value) {
        return valueOperations.setBit(key, offset, value);
    }

    /**
     * 获取key对应offset上的bit值,如果offset大于value的长度,或者key不存在,或者非二进制型字符串,返回0。
     *
     * @param key
     * @param offset
     * @return 字符串值指定偏移量上的位(bit)。
     */
    public boolean getBit(String key, long offset) {
        return valueOperations.getBit(key, offset);
    }

    /**
     * 将指定key对应的value原子性的递增1,返回递增后的value值。
     * <p>
     * 如果key不存在,设其初始值为0,再递增1。如果value的值不能表示为数字,则会返回失败信息。
     *
     * @param key
     * @return 返回递增后key的值。
     */
    public Long incr(String key) {
        final byte[] rawKey = rawKey(key);
        return redisTemplate.execute(new RedisCallback<Long>() {
            @Override
            public Long doInRedis(RedisConnection connection) throws DataAccessException {
                return connection.incr(rawKey);
            }
        }, true);
    }

    /**
     * 将指定key对应的value原子性的递增increment,返回递增后的value值。
     * <p>
     * 如果key不存在, 设其初始值为0,再递增increment。如果value的值不能表示为数字,则会返回失败信息。
     *
     * @param key
     * @param value
     * @return 返回递增increment之后key的值。
     */
    public Long incrBy(String key, long value) {
        return valueOperations.increment(key, value);
    }

    /**
     * 将指定key对应的value原子性的递增increment,返回递增后的value值。
     * <p>
     * 如果key不存在, 设其初始值为0,再递增increment。如果value的值不能表示为数字,则会返回失败信息。
     *
     * @param key
     * @param value
     * @return 返回递增increment之后key的值。
     */
    public Double incrBy(String key, double value) {
        return valueOperations.increment(key, value);
    }

    /**
     * 将指定key对应的value原子性的递减,返回递减后的value值。
     * <p>
     * 如果key不存在,设其初始值为0,再递减1。如果value的值不能表示为数字,则会返回失败信息。
     *
     * @param key
     * @return 返回递减后key的值。
     */
    public Long decr(String key) {
        final byte[] rawKey = rawKey(key);
        return redisTemplate.execute(new RedisCallback<Long>() {
            @Override
            public Long doInRedis(RedisConnection connection) throws DataAccessException {
                return connection.decr(rawKey);
            }
        }, true);
    }

    /**
     * 将指定key对应的value原子性的递减increment,返回递减后的value值。
     * <p>
     * 如果key不存在, 设其初始值为0,再递减increment。如果value的值不能表示为数字,则会返回失败信息。
     *
     * @param key
     * @param value
     * @return 返回递减increment之后key的值。
     */
    public Long decrBy(final String key, final long value) {
        final byte[] rawKey = rawKey(key);
        return redisTemplate.execute(new RedisCallback<Long>() {
            @Override
            public Long doInRedis(RedisConnection connection) throws DataAccessException {
                return connection.decrBy(rawKey, value);
            }
        }, true);
    }

    /**
     * 将指定key对应的value原子性的递减increment,返回递增后的value值。
     * <p>
     * 如果key不存在, 设其初始值为0,再递减increment。如果value的值不能表示为数字,则会返回失败信息。
     *
     * @param key
     * @param value
     * @return 返回递减increment之后key的值。
     */
    /*
    public Double decrBy(String key, double value) {
		return valueOperations.increment(key, -value);
    }*/

    /**
     * 如果key已经存在并且是一个字符串, append命令将value追加到key原来的值的末尾。<br>
     * 如果key不存在, append就简单地将给定key设为value,跟set方法一样。
     *
     * @param key
     * @param value
     * @return 返回追加value之后, key中字符串的长度。
     */
    public Integer append(String key, String value) {
        return valueOperations.append(key, value);
    }

    /**
     * 获取key对应value的子字符串,从start开始到end结束。
     * <br>
     * 如果end(为正)小于start(为正),或者key不存在,则返回空字符串""。
     * <br>
     * 如果end超出value的长度,则返回start到value末尾之间的字符串。
     * <br>
     * 其中,start和end可以为负,字符串左边的下标从0开始,右边的下标从-1开始。
     *
     * @param key
     * @param start
     * @param end
     * @return 截取得出的子字符串。
     */
    public String substr(String key, int start, int end) {
        return valueOperations.get(key, start, end);
    }

    public void hset(String key, String field, Object value) {
        hashOperations.put(key, field, value);
    }

    @SuppressWarnings("unchecked")
    public <T> T hget(String key, String field) {
        return (T) hashOperations.get(key, field);
    }

    public Boolean hsetnx(String key, String field, Object value) {
        return hashOperations.putIfAbsent(key, field, value);
    }

    public void hmset(String key, Map<String, Object> values) {
        hashOperations.putAll(key, values);
    }

    public List<?> hmget(String key, Collection<String> fields) {
        return hashOperations.multiGet(key, fields);
    }

    public Boolean hexists(String key, String field) {
        return hashOperations.hasKey(key, field);
    }

    public Long hdel(String key, String field) {
        return hashOperations.delete(key, field);
    }

    public Long hlen(String key) {
        return hashOperations.size(key);
    }

    public Set<String> hkeys(String key) {
        return hashOperations.keys(key);
    }

    public List<?> hvals(String key) {
        return hashOperations.values(key);
    }

    public Map<String, ?> hgetAll(String key) {
        return hashOperations.entries(key);
    }

    public Long rpush(String key, Object value) {
        return listOperations.rightPush(key, value);
    }

    public Long lpush(String key, Object value) {
        return listOperations.leftPush(key, value);
    }

    public Long llen(String key) {
        return listOperations.size(key);
    }

    public List<?> lrange(String key, long start, long end) {
        return listOperations.range(key, start, end);
    }

    public void ltrim(String key, long start, long end) {
        listOperations.trim(key, start, end);
    }

    @SuppressWarnings("unchecked")
    public <T> T lindex(String key, long index) {
        return (T) listOperations.index(key, index);
    }

    public void lset(String key, long offset, Object value) {
        listOperations.set(key, offset, value);
    }

    public Long lrem(String key, long index, Object value) {
        return listOperations.remove(key, index, value);
    }

    @SuppressWarnings("unchecked")
    public <T> T lpop(String key) {
        return (T) listOperations.leftPop(key);
    }

    @SuppressWarnings("unchecked")
    public <T> T rpop(String key) {
        return (T) listOperations.rightPop(key);
    }

    public Long sadd(String key, Object... values) {
        return setOperations.add(key, values);
    }

    public Set<?> smembers(String key) {
        return setOperations.members(key);
    }

    public Long srem(String key, Object... values) {
        return setOperations.remove(key, values);
    }

    @SuppressWarnings("unchecked")
    public <T> T spop(String key) {
        return (T) setOperations.pop(key);
    }

    public Long scard(String key) {
        return setOperations.size(key);
    }

    public Boolean sismember(String key, Object member) {
        return setOperations.isMember(key, member);
    }

    @SuppressWarnings("unchecked")
    public <T> T srandmember(String key) {
        return (T) setOperations.randomMember(key);
    }

    public Boolean zadd(String key, Object value, double score) {
        return zSetOperations.add(key, value, score);
    }

    public Set<?> zrange(String key, long start, long end) {
        return zSetOperations.range(key, start, end);
    }

    public Long zrem(String key, Object... values) {
        return zSetOperations.remove(key, values);
    }

    public Double zincrby(String key, Object value, double delta) {
        return zSetOperations.incrementScore(key, value, delta);
    }

    public Long zrank(String key, Object value) {
        return zSetOperations.rank(key, value);
    }

    public Set<?> zrevrange(String key, int start, int end) {
        return zSetOperations.reverseRange(key, start, end);
    }

    public Set<?> zrangeWithScores(String key, int start, int end) {
        return zSetOperations.rangeWithScores(key, start, end);
    }

    public Set<?> zrevrangeWithScores(String key, int start, int end) {
        return zSetOperations.reverseRangeWithScores(key, start, end);
    }

    public Long zcard(String key) {
        return zSetOperations.size(key);
    }

    public Double zscore(String key, Object value) {
        return zSetOperations.score(key, value);
    }

    public List<?> sort(String key) {
        return redisTemplate.sort(null);
    }

    public List<?> sort(String key, SortingParams sortingParameters) {
        return redisTemplate.sort(null);
    }

    public Long zcount(String key, double min, double max) {
        return zSetOperations.count(key, min, max);
    }

    public Set<?> zrangeByScore(String key, double min, double max) {
        return zSetOperations.rangeByScore(key, min, max);
    }

    public Set<?> zrevrangeByScore(String key, double max, double min) {
        return zSetOperations.reverseRangeByScore(key, max, max);
    }

    public Set<?> zrangeByScore(String key, double min, double max, int offset, int count) {
        return zSetOperations.rangeByScore(key, min, max, offset, count);
    }

    public Set<?> zrevrangeByScore(String key, double max, double min, int offset, int count) {
        return zSetOperations.reverseRangeByScore(key, min, max, offset, count);
    }

    public Set<?> zrangeByScoreWithScores(String key, double min, double max) {
        return zSetOperations.rangeByScoreWithScores(key, min, max);
    }

    public Set<?> zrevrangeByScoreWithScores(String key, double max, double min) {
        return zSetOperations.reverseRangeByScoreWithScores(key, min, max);
    }

    public Set<?> zrangeByScoreWithScores(String key, double min, double max, int offset, int count) {
        return zSetOperations.rangeByScoreWithScores(key, min, max, offset, count);
    }

    public Set<?> zrevrangeByScoreWithScores(String key, double max, double min, int offset, int count) {
        return zSetOperations.reverseRangeByScoreWithScores(key, min, max, offset, count);
    }

    public Long zremrange(String key, long start, long end) {
        return zSetOperations.removeRange(key, start, end);
    }

    public Long zremrangeByScore(String key, double start, double end) {
        return zSetOperations.removeRangeByScore(key, start, end);
    }

    public Long linsert(String key, BinaryClient.LIST_POSITION where, String pivot, String value) {
        return null;
    }

    public void setList(String key, List<?> value) {
        listOperations.leftPush(key, value);
    }

    public List<?> getList(String key) {
        return (List<?>) listOperations.leftPop(key);
    }

    public void setSet(String key, Set<?> value) {
        setOperations.add(key, value);
    }
    public Set<?> getSet(String key) {
        return setOperations.members(key);
    }

    public void setMap(String key, Map<String, ?> value) {
        hashOperations.putAll(key, value);
    }

    public Map<String, ?> getMap(String key) {
        return hashOperations.entries(key);
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    private byte[] rawKey(Object key) {
        Assert.notNull(key, "non null key required");
        RedisSerializer keySerializer = redisTemplate.getKeySerializer();
        if (keySerializer == null && key instanceof byte[]) {
            return (byte[]) key;
        }
        return keySerializer.serialize(key);
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    private byte[] rawValue(Object value) {
        RedisSerializer valueSerializer = redisTemplate.getValueSerializer();
        if (value != null && value instanceof String) {
            return redisTemplate.getStringSerializer().serialize((String) value);
        }
        return valueSerializer.serialize(value);
    }

}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值