|
|
@@ -20,6 +20,7 @@ import org.jetbrains.annotations.NotNull;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
|
|
import org.springframework.data.redis.core.ReactiveRedisTemplate;
|
|
|
+import org.springframework.data.redis.core.ScanOptions;
|
|
|
import org.springframework.data.relational.core.query.Criteria;
|
|
|
import org.springframework.data.relational.core.query.Query;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
@@ -52,7 +53,7 @@ public class SyncListeningAudioToRedis {
|
|
|
/**
|
|
|
*同步裂变计划
|
|
|
*/
|
|
|
- @Scheduled(cron="0 */1 * * * ?")
|
|
|
+ @Scheduled(cron="0 */30 * * * ?")
|
|
|
@SchedulerLock(name = "launch:SyncListeningAudioToRedis:syncLinteningAudioPlan", lockAtLeastFor = "PT5S", lockAtMostFor = "PT15M")
|
|
|
public void syncLinteningAudioPlan(){
|
|
|
Mono<List<ListeningAudio>> listMono = template.select(Query.query(Criteria.empty())
|
|
|
@@ -91,12 +92,28 @@ public class SyncListeningAudioToRedis {
|
|
|
public Mono<Void> setRedisValue(ListeningAudio planNew) {
|
|
|
String stringBuilder = getSetValue(planNew);
|
|
|
String json= getPlanNewToString(planNew);
|
|
|
- reactiveRedisTemplate
|
|
|
- .opsForValue()
|
|
|
- .set(LinteningAudioRedisKey.PLAN_NEW_INFO_KEY + stringBuilder, json).subscribe();
|
|
|
+ reactiveRedisTemplate.opsForHash().put(LinteningAudioRedisKey.lintening_Audio_INFO_HASH , stringBuilder, json).subscribe();
|
|
|
reactiveRedisTemplate.opsForSet().add(LinteningAudioRedisKey.PLAN_NEW_INFO_SET,stringBuilder ).subscribe();
|
|
|
return Mono.empty();
|
|
|
}
|
|
|
+ public Mono<Void> deleteAll() {
|
|
|
+ deleteByPattern("sync_image_*").subscribe();
|
|
|
+ deleteByPattern("sync_lintening_*").subscribe();
|
|
|
+ deleteByPattern("sync_plan_new_*").subscribe();
|
|
|
+ // reactiveRedisTemplate.delete("sync_lintening_*").subscribe();
|
|
|
+ return Mono.empty();
|
|
|
+ }
|
|
|
+ public Mono<Long> deleteByPattern(String pattern) {
|
|
|
+ return reactiveRedisTemplate
|
|
|
+ .scan(ScanOptions.scanOptions().match(pattern).build())
|
|
|
+ .collectList()
|
|
|
+ .flatMap(keys -> {
|
|
|
+ if (keys.isEmpty()) {
|
|
|
+ return Mono.just(0L);
|
|
|
+ }
|
|
|
+ return reactiveRedisTemplate.delete(Flux.fromIterable(keys));
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
@NotNull
|
|
|
private String getSetValue(ListeningAudio planNew) {
|
|
|
@@ -121,14 +138,14 @@ public class SyncListeningAudioToRedis {
|
|
|
public Mono<Void> deleteRedis(ListeningAudio planNew) {
|
|
|
String setValue = getSetValue(planNew);
|
|
|
reactiveRedisTemplate.opsForSet().remove(LinteningAudioRedisKey.PLAN_NEW_INFO_SET, setValue).subscribe();
|
|
|
- reactiveRedisTemplate.opsForValue().delete(LinteningAudioRedisKey.PLAN_NEW_INFO_KEY + setValue).subscribe();
|
|
|
+ reactiveRedisTemplate.opsForHash().remove(LinteningAudioRedisKey.lintening_Audio_INFO_HASH, setValue).subscribe();
|
|
|
return Mono.empty();
|
|
|
}
|
|
|
@NotNull
|
|
|
public Mono<Void> getDelete(String key) {
|
|
|
- Mono<Long> remove = reactiveRedisTemplate.opsForSet().remove(LinteningAudioRedisKey.PLAN_NEW_INFO_SET, key);
|
|
|
- Mono<Boolean> delete = reactiveRedisTemplate.opsForValue().delete(LinteningAudioRedisKey.PLAN_NEW_INFO_KEY + key);
|
|
|
- return remove.then(delete).then();
|
|
|
+ reactiveRedisTemplate.opsForSet().remove(LinteningAudioRedisKey.PLAN_NEW_INFO_SET, key).subscribe();
|
|
|
+ reactiveRedisTemplate.opsForHash().remove(LinteningAudioRedisKey.lintening_Audio_INFO_HASH, key).subscribe();
|
|
|
+ return Mono.empty();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -169,11 +186,11 @@ public class SyncListeningAudioToRedis {
|
|
|
.limit(size)
|
|
|
.collect(Collectors.toList());
|
|
|
return Flux.fromIterable(collect).flatMap(f -> reactiveRedisTemplate
|
|
|
- .opsForValue()
|
|
|
- .get(LinteningAudioRedisKey.PLAN_NEW_INFO_KEY + f))
|
|
|
+ .opsForHash()
|
|
|
+ .get(LinteningAudioRedisKey.lintening_Audio_INFO_HASH , f))
|
|
|
.flatMap(str -> {
|
|
|
if (Objects.nonNull(str) && !"".equals(str)) {
|
|
|
- return Mono.just(strParsePlanNew(str));
|
|
|
+ return Mono.just(strParsePlanNew(String.valueOf(str)));
|
|
|
}
|
|
|
return Mono.empty();
|
|
|
}).collectList();
|