Back-end query the data dictionary tables, startup is loaded into the redis code:
@ Component
@ AllArgsConstructor
@ Slf4j
Public class InitDictionariesCacheRunner implements CommandLineRunner {
Private final RedisTemplate RedisTemplate;
Private final DictionaryBizService DictionaryBizService;
@ Override
Public void run (String... The args) throws the Exception {
RedisTemplate. Delete (AuthConstants. DICTIONARIES_KEY);
//query all the data dictionary
ListUipDictionaries=dictionaryBizService. List ();
//define a dictionary type array
ListTypeCodeList=new ArrayList<> (a);
//type_code was obtained from the traversal of all the data in the data
UipDictionaries. ForEach (entity - & gt; {
String typeCode=entity. GetTypeCode ();
TypeCodeList. Add (typeCode);
});
//traverse type_code array
TypeCodeList. ForEach (STR - & gt; {
//according to type_code query the corresponding name and value
ListListmap=dictionaryBizService. QueryByTypeCode (STR);
MapDictionariesMap=new TreeMap<> (a);
Optional. OfNullable (listmap). OrElse (new ArrayList<> ()). The forEach (uipDictionary - & gt; {
DictionariesMap. Put (STR, listmap);
});
RedisTemplate. OpsForHash (.) putAll (AuthConstants DICTIONARIES_KEY, dictionariesMap);
});
}
}
Service query code:
@ Override
Public ListQueryByTypeCode (String typeCode) {
QueryWrapper queryWrapper=new QueryWrapper();
QueryWrapper. Eq (" type_code, "typeCode);
ListListEntity=this. BaseMapper. SelectList (queryWrapper);
ListMaplist=new ArrayList<> (a);
ListEntity. ForEach (entity - & gt; {
String value=(https://bbs.csdn.net/topics/entity.getValue);
String name=entity. The getName ();
RedisDictionariesVO vo=new RedisDictionariesVO ();
Vo. Elegantly-named setName (" NAME: "+ NAME);
Vo. SetValue (" VALUE: "+ VALUE);
Maplist. Add (vo);
});
Return maplist;
}
The contents of the view to Redis is as follows:
Excuse me:
1, using the vue obtain redis cache data is directly obtained from the redis or call code, redis by background check? Vue and back-end code what to write?
2, the front end to add and delete dictionary information, call the backend method after how to refresh the redis cache data, redis service does not need to restart?
CodePudding user response:
1 in general is to call the background, what is your background? If it is a nodejs, can refer tohttps://www.jb51.net/article/139223.htm
Or Google baidu nodejs redis and ioredis package
How to use other languages, of course, also have the corresponding package, it is good to oneself Google baidu
2 cache management by the redis server, redis our club is as a cache, so there's no need to restart the redis service
CodePudding user response:
In principle, the Java code docking redis vue don't need to care about the Java code to handle data only need to care about so and so Java code interactionSo since the Java code and docking redis so all should be Java code to the operation of the redis,
Refresh the problem usually is to remove the key to write again