当前位置:网站首页>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
边栏推荐
- Here are all the MySQL interview questions you can't expect (the latest version of 2022)
- nacos显示服务注册地址错误
- What if MySQL database forgets its password???
- Music rhythm colorful gradient lamp chip -- dlt8s04a- Jericho
- 阿里p8总结的10条 SQL 优化方案(非常实用)
- Have you ever stumbled on MySQL's order by
- 订单超时取消 及 按类别查询商品
- 内网的公司邮箱服务器怎么发外部邮件
- 订单的提交
- Wechat payment and payment callback
猜你喜欢

全自动吸奶器芯片-DLTAP703SD

MySQL 04 高级查询(二)

Vue uses keep alive to realize page caching

nacos显示服务注册地址错误

MySQL 06 事务、视图、索引、备份和恢复

Full automatic breast pump chip dltap703sd

MySQL 01 relational database design

What does the number of network request interface layers (2/3 layers) mean

The song of the virtual idol was originally generated in this way!

Household mute mosquito repellent lamp chip-dltap703sd-jericho
随机推荐
TypeError: conv2d(): argument ‘padding‘ (position 5) must be tuple of ints, not str【报错】
飞机大战英雄出场加子弹实现
图文结合,完美解释MySQL逻辑备份的实现流程
阿里p8总结的10条 SQL 优化方案(非常实用)
百度地图鹰眼轨迹服务
这样的API网关查询接口优化,我是被迫的
TS learning notes interface
Low noise anion fan touch IC
我人都傻了,CompletableFuture和OpenFegin一起使用竟然报错
Arrays and objects in JS
Typeerror: conv2d(): argument 'padding' (position 5) must be multiple of ints, not STR [error]
【npm】 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
INSUFFICIENT_ ACCESS_ ON_ CROSS_ REFERENCE_ ENTITY APEX / SALESFORCE
Use ETL tools for data migration in salesforce project
全身多功能按摩仪芯片-DLTAP602SD
TypeScript安装
飞机大战碰撞检测
Matplotlib(基本用法)
订单的提交
Household mute mosquito repellent lamp chip-dltap703sd-jericho