| | |
| | | return keys; |
| | | } |
| | | |
| | | public Set<String> scanKeys(String key, int limit) { |
| | | return (Set<String>) redisTemplate.execute((org.springframework.data.redis.core.RedisCallback<Set<String>>) connection -> { |
| | | org.springframework.data.redis.core.ScanOptions options = org.springframework.data.redis.core.ScanOptions.scanOptions().match(key + "*").count(limit).build(); |
| | | org.springframework.data.redis.core.Cursor<byte[]> cursor = connection.scan(options); |
| | | java.util.LinkedHashSet<String> result = new java.util.LinkedHashSet<>(); |
| | | while (cursor.hasNext()) { |
| | | result.add(new String(cursor.next())); |
| | | if (result.size() >= limit) { |
| | | break; |
| | | } |
| | | } |
| | | try { cursor.close(); } catch (Exception e) {} |
| | | return result; |
| | | }); |
| | | } |
| | | |
| | | public java.util.List<Object> multiGet(java.util.Collection<String> keys) { |
| | | return redisTemplate.opsForValue().multiGet(keys); |
| | | } |
| | | |
| | | /** |
| | | * 普通缓存获取 |
| | | * |