Junjie
17 小时以前 c97c04770c17c36c554963bf8bb8d8fafc6a8d43
src/main/java/com/zy/common/utils/RedisUtil.java
@@ -118,6 +118,36 @@
        });
    }
    public int deleteByPrefix(String keyPrefix) {
        if (keyPrefix == null || keyPrefix.trim().isEmpty()) {
            return 0;
        }
        Integer deletedCount = (Integer) redisTemplate.execute((org.springframework.data.redis.core.RedisCallback<Integer>) connection -> {
            org.springframework.data.redis.core.ScanOptions options = org.springframework.data.redis.core.ScanOptions.scanOptions()
                    .match(keyPrefix + "*")
                    .count(1000)
                    .build();
            org.springframework.data.redis.core.Cursor<byte[]> cursor = connection.scan(options);
            int count = 0;
            try {
                while (cursor.hasNext()) {
                    byte[] key = cursor.next();
                    Long deleted = connection.keyCommands().del(key);
                    if (deleted != null) {
                        count += deleted.intValue();
                    }
                }
            } finally {
                try {
                    cursor.close();
                } catch (Exception e) {
                }
            }
            return count;
        });
        return deletedCount == null ? 0 : deletedCount;
    }
    public java.util.List<Object> multiGet(java.util.Collection<String> keys) {
        return redisTemplate.opsForValue().multiGet(keys);
    }