解决redis存储key乱码问题
This commit is contained in:
parent
f8db3543a4
commit
2b1aa5448e
@ -8,6 +8,10 @@ import org.redisson.config.Config;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||||
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Data
|
@Data
|
||||||
@ -46,4 +50,22 @@ public class AppConfig {
|
|||||||
return redisson;
|
return redisson;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解决redis key乱码
|
||||||
|
*
|
||||||
|
* @param factory
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
|
||||||
|
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||||
|
redisTemplate.setConnectionFactory(factory);
|
||||||
|
|
||||||
|
RedisSerializer redisSerializer = new StringRedisSerializer();
|
||||||
|
|
||||||
|
redisTemplate.setKeySerializer(redisSerializer);
|
||||||
|
redisTemplate.setValueSerializer(redisSerializer);
|
||||||
|
|
||||||
|
return redisTemplate;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user