正确的删除姿势

This commit is contained in:
ZZ 2021-09-07 15:05:32 +08:00
parent fe4edbd686
commit 639bc37804
2 changed files with 3 additions and 5 deletions

View File

@ -105,11 +105,11 @@ public class RedisService
} }
/** /**
* 删除单个key下的某个 * 删除单个key下的
* *
* @param key * @param key
*/ */
public void deleteSetVal(final String key, final Object val) { public void deleteSetVal(final String key, final Object... val) {
redisTemplate.opsForSet().remove(key, val); redisTemplate.opsForSet().remove(key, val);
} }

View File

@ -50,9 +50,7 @@ public class PileController {
@PostMapping("pile/whitelist/delete/{stationId}") @PostMapping("pile/whitelist/delete/{stationId}")
public Object deleteWhitelist(@PathVariable("stationId") Long stationId, @RequestBody Set<String> pileNoSet) { public Object deleteWhitelist(@PathVariable("stationId") Long stationId, @RequestBody Set<String> pileNoSet) {
Set<String> cacheWhitelist = REDIS.getCacheSet("PILE_WHITELIST"); REDIS.deleteSetVal("PILE_WHITELIST", pileNoSet.toArray());
cacheWhitelist.removeAll(pileNoSet);
REDIS.setCacheSet("PILE_WHITELIST", cacheWhitelist);
String stationKey = "station:".concat(stationId.toString()); String stationKey = "station:".concat(stationId.toString());
ChargingStationDto cacheStation = REDIS.getCacheObject(stationKey); ChargingStationDto cacheStation = REDIS.getCacheObject(stationKey);
cacheStation.getPiles().removeAll(pileNoSet); cacheStation.getPiles().removeAll(pileNoSet);