File tree Expand file tree Collapse file tree
backend/framework/src/main/java/cn/cordys/common/uid Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2020public class SerialNumGenerator {
2121
2222 private static final int RULE_SIZE = 5 ;
23+ private static final int DATE_KEY_IDX = 3 ;
2324 private static final String PREFIX = "serial" ;
2425
2526 private final StringRedisTemplate redis ;
@@ -77,19 +78,22 @@ private boolean equals(Rule other) {
7778 }
7879 }
7980
80- @ QuartzScheduled (cron = "0 0 1 1,16 * ?" )
81+ @ QuartzScheduled (cron = "0 25 11 * * ?" )
8182 public void clean () {
82- log .info ("开始清理过期流水号 " );
83+ log .info ("开始清理过期流水号Key " );
8384
8485 String currentMonth = new SimpleDateFormat ("yyyyMM" ).format (new Date ());
85-
86- try (Cursor <String > cursor = redis .scan (ScanOptions .scanOptions ().match ("serial:*:*:*" ).count (1000 ).build ())) {
86+ try (Cursor <String > cursor = redis .scan (ScanOptions .scanOptions ().match ("serial:*:*:*:*" ).count (1000 ).build ())) {
8787 cursor .forEachRemaining (key -> {
88- String serialDate = key .substring (key .lastIndexOf (":" ) + 1 );
89- if (!currentMonth .equals (serialDate )) {
90- redis .delete (key );
91- log .info ("删除过期Key: {}" , key );
92- }
88+ String [] ks = key .split (":" );
89+ if (ks .length != RULE_SIZE ) {
90+ log .warn ("存在脏Key: {}" , key );
91+ return ;
92+ }
93+ if (!currentMonth .equals (ks [DATE_KEY_IDX ])) {
94+ redis .delete (key );
95+ log .info ("删除过期Key: {}" , key );
96+ }
9397 });
9498 } catch (Exception e ) {
9599 log .error ("流水号过期Key清理异常: " , e );
You can’t perform that action at this time.
0 commit comments