1.redis为ä»ä¹è¦åºåå
redis为ä»ä¹è¦åºåå
åºååæç»çç®çæ¯ä¸ºäºå¯¹è±¡å¯ä»¥è·¨å¹³å°åå¨ï¼åè¿è¡ç½ç»ä¼ è¾ãèæ们è¿è¡è·¨å¹³å°åå¨åç½ç»ä¼ è¾çæ¹å¼å°±æ¯IOï¼èæ们çIOæ¯æçæ°æ®æ ¼å¼å°±æ¯åèæ°ç»ã ï¼æ¨èå¦ä¹ ï¼Redisè§é¢æç¨ï¼
éè¿ä¸é¢ææ³ä½ å·²ç»ç¥éäºå¡æ¯éè¦è¿è¡â跨平å°åå¨âåâç½ç»ä¼ è¾âçæ°æ®ï¼é½éè¦è¿è¡åºååã
æ¬è´¨ä¸åå¨åç½ç»ä¼ è¾ é½éè¦ç»è¿ æä¸ä¸ªå¯¹è±¡ç¶æä¿åæä¸ç§è·¨å¹³å°è¯å«çåèæ ¼å¼ï¼ç¶åå ¶ä»çå¹³å°æå¯ä»¥éè¿åèä¿¡æ¯è§£æè¿å对象信æ¯ã
redisåºååæ¹å¼å¯¹æ¯ï¼
redisçé»è®¤æ¹å¼æ¯JdkSerializationRedisSerializer
JdkSerializationRedisSerializer: 使ç¨JDKæä¾çåºåååè½ã
ä¼ç¹æ¯ååºååæ¶ä¸éè¦æä¾ç±»åä¿¡æ¯(class)ï¼ä½ç¼ºç¹æ¯éè¦å®ç°Serializableæ¥å£ï¼è¿æåºåååçç»æé常åºå¤§ï¼æ¯JSONæ ¼å¼ç5åå·¦å³ï¼è¿æ ·å°±ä¼æ¶èredisæå¡å¨ç大éå åã
Jackson2JsonRedisSerializerï¼ ä½¿ç¨Jacksonåºå°å¯¹è±¡åºåå为JSONå符串ã
ä¼ç¹æ¯é度快ï¼åºåååçå符串çå°ç²¾æï¼ä¸éè¦å®ç°Serializableæ¥å£ã
ä½ç¼ºç¹ä¹é常è´å½ï¼é£å°±æ¯æ¤ç±»çæé å½æ°ä¸æä¸ä¸ªç±»ååæ°ï¼å¿ é¡»æä¾è¦åºåå对象çç±»åä¿¡æ¯(.class对象)ã éè¿æ¥çæºä»£ç ï¼åç°å ¶åªå¨ååºååè¿ç¨ä¸ç¨å°äºç±»åä¿¡æ¯ã
é®é¢ï¼ä½¿ç¨é»è®¤çJDKåºååæ¹å¼ï¼å¨RDMå·¥å ·ä¸æ¥çk-vå¼æ¶ä¼åºç°âä¹±ç âï¼ä¸æ¹ä¾¿æ¥çã
解å³ï¼èªå®ä¹ç³»ååæ¹å¼ï¼ä½¿ç¨Jackson2JsonRedisSerializer
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/
*** Redisé ç½®
*
* @author LinJie
*/
@Configuration
public class RedisConfig {
/
*** Redis 码分收徒系统源码repository redis repository.
*
* @param redisTemplate the redis template
* @return the redis repository
*/
@Bean
public RedisRepository redisRepository(RedisTemplate redisTemplate) {
// 使ç¨Jackson2JsonRedisSerialize æ¿æ¢é»è®¤åºåå
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(objectMapper);
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
// keyéç¨Stringçåºååæ¹å¼
redisTemplate.setKeySerializer(stringRedisSerializer);
// hashçkeyä¹éç¨Stringçåºååæ¹å¼
redisTemplate.setHashKeySerializer(stringRedisSerializer);
// valueåºååæ¹å¼éç¨jackson
redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
// hashçvalueåºååæ¹å¼éç¨jackson
redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer);
redisTemplate.afterPropertiesSet();
return new RedisRepository(redisTemplate);
}
}æ´å¤Redisç¸å ³ææ¯æç« ï¼è¯·è®¿é®Redisæ°æ®åºä½¿ç¨å ¥é¨æç¨æ ç®è¿è¡å¦ä¹ ï¼
2024-11-28 00:252851人浏览
2024-11-27 23:572502人浏览
2024-11-27 23:262446人浏览
2024-11-27 22:561696人浏览
2024-11-27 22:561212人浏览
2024-11-27 22:50556人浏览
1.webview��ȡԴ��2.WebView的使用3.最简最全,一文搞定Android WebView编译+AOSP集成webview��ȡԴ�� webview js之间的交互,项目中马上用
1.????????ָ??Դ??ѡ?ɹ?ʽ2.通达信主力控盘指标公式(附源码)????????ָ??Դ??ѡ?ɹ?ʽ 以下是修改过的,按问题要求做的主力控盘选股公式,用软件实际测试过能达到要求,可
1.??ʵ??????????Դ??????2.SynthTIGER合成文本图像生成器配置文件解读3.ERP系统源码-云进销存web+app)搭建附源码PC+APP+H5+小程序)4.生成对抗网络Ge