需求说明
需要实现一个检索功能,需要查询到最近所有的所有热词,自定需求为所有一个月内检索数量最多的10个热词;这里使用Redis的内存数据库功能,其中Redis的ZSet格式提供的功能完全贴合该需求;
后台服务使用SpringBoot实现,由于不想起多余的服务,所以从maven上找了一个可内嵌如SpringBoot的Redis服务。
SpringBoot整合内嵌Redis
pom文件添加,虽然下面这个包两三年没更新了,但亲测可放心使用
com.github.kstyrc
embedded-redis
0.6
application.xml配置
spring:
redis:
host: localhost
port: 6379
Redis配置类
package cn.com.casic.thinkdata.configuration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SetOperations;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
@Configuration
public class RedisConfig {
/**