当前位置:网站首页>Redis annotation
Redis annotation
2022-07-27 18:55:00 【Get lazy】
@Autowired
private StringRedisTemplate redisTemplate; @Autowired
private RedisTemplate redisTemplate;The upper and lower ones are the same, but using the following one will cause garbled code. You have to use
@Configuration
public class RedisConfig {
@Bean(name = "redisTemplate")
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<Object, Object> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory);
// Customized Serialization tools customized for values
Jackson2JsonRedisSerializer jacksonSerializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jacksonSerializer.setObjectMapper(om);
// To key Set the serialization tool
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
// Set up customized serialization tools
// Using annotations @Bean return RedisTemplate When , Simultaneous configuration hashKey And hashValue How to serialize .
// key use String How to serialize
template.setKeySerializer(stringRedisSerializer);
// value The serialization method adopts jackson
template.setValueSerializer(jacksonSerializer);
// hash Of key Also used String How to serialize
template.setHashKeySerializer(stringRedisSerializer);
// hash Of value The serialization method adopts jackson
template.setHashValueSerializer(jacksonSerializer);
template.afterPropertiesSet();
// Customization ends
return template;
}
}ListOperations、ValueOperations、SetOperations、ZSetOperations、HashOperations How to use the interface
@Resource(name="redisTemplate")
private ValueOperations valueOperations;And so on .
Why use Resource Annotation is because ValueOperations yes StringRedisTemplate Subclasses of
This is a redisTemplate elective
ValueOperations<String, String> ValueOperations1 = redisTemplate.opsForValue();This is the choice redisTemplate.opforValue(). Things will be found with the following direct use ValueOperations It's the same


So choose ValueOperations Yes, I skipped redisTemplate.opforValue(). But the results are the same
边栏推荐
- 【npm】 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
- Infrared hyperspectral survey
- Music rhythm colorful gradient lamp chip -- dlt8s04a- Jericho
- 阿里p8总结的10条 SQL 优化方案(非常实用)
- 内网的公司邮箱服务器怎么发外部邮件
- Interviewer: what do you think is your biggest weakness?
- 建木持续集成平台v2.5.2发布
- INSUFFICIENT_ ACCESS_ ON_ CROSS_ REFERENCE_ ENTITY APEX / SALESFORCE
- PyGame aircraft war game background implementation
- Baidu map eagle eye track service
猜你喜欢

Order timeout cancellation and commodity query by category

图文结合,完美解释MySQL逻辑备份的实现流程

Jianmu continuous integration platform v2.5.2 release

nacos显示服务注册地址错误

【npm】 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。

Intelligent insomnia therapeutic instrument product dlt8p68sa Jericho

MySQL 03 高级查询(一)

The combination of text and words perfectly explains the implementation process of MySQL logical backup

LeetCode 刷题 第二天

Matplotlib (basic usage)
随机推荐
Conflict between blur event and click event in input box
PyGame aircraft war game background implementation
Commodity comment information and comment information classification
The hero of the aircraft war comes out with bullets
Jianmu continuous integration platform v2.5.2 release
Full automatic breast pump chip dltap703sd
SQL server stored procedures multi angle introduction suggestions collection
Redis注解
MySQL 04 高级查询(二)
内网的公司邮箱服务器怎么发外部邮件
Nacos display service registration address error
订单超时取消 及 按类别查询商品
Wechat applet multi file upload
Have you ever stumbled on MySQL's order by
LeetCode 刷题 第三天
ERROR 1366 (HY000): Incorrect string value: ‘\xE8\xB5\xB5\xE9\x9B\xB7‘ for column ‘s_ name‘ at row 1
pygame飞机大战游戏背景实现
Run the uniapp to the mobile phone (real machine debugging)
如何实现Word、PDF、TXT文件的全文内容检索?
MySQL set validate_ Adding skip grant tables after password=off failed to start the service