Redis does not provide the implementation of the fuzzy deletion directly, we can combine the implementation according to the existing instruction:
Importjava.util.Arrays;ImportJava.util.Set;ImportJavax.annotation.Resource;Importorg.springframework.data.redis.core.RedisTemplate;ImportOrg.springframework.stereotype.Service;ImportCom.nonobank.application.service.RedisCacheService; @Service ("Rediscacheservice") Public classRediscacheserviceimplImplementsrediscacheservice{//private final Logger Logger = Loggerfactory.getlogger (GetClass ());@Resource (Name= "Stringredistemplate") PrivateRedistemplate<string, string>redistemplate; @Override Public voidDeletebykey (String key) {redistemplate.delete (key); } @Override Public voidDeletebyprex (String prex) {Set<String> Keys=redistemplate.keys (prex+ "*"); /*For Test *iterator<string> it=keys.iterator (); * while (It.hasnext ()) {Logger.info (It.next ()); }*/redistemplate.delete (keys); } @Override Public voiddeletebysuffix (String suffix) {Set<String> Keys=redistemplate.keys ("*" +suffix); Redistemplate.delete (keys); } @Override Public voidDeletebykeys (String ... keys) {Redistemplate.delete (arrays.aslist (keys)); }}
Redis Fuzzy Removal implementation