// 获取登录key Set<String> tokenKeySet = stringRedisTemplate.execute((RedisCallback<Set<String>>) connection -> { Set<String> keysTmp = new HashSet<>(); try (Cursor<byte[]> cursor = connection.scan(new ScanOptions.ScanOptionsBuilder() .match(CacheConstants.LOGIN_TOKEN_KEY + "*") .count(1000).build())) { while (cursor.hasNext()) { keysTmp.add(new String(cursor.next(), StandardCharsets.UTF_8)); } } catch (Exception e) { log.error("获取所有的在线用户key报错", e); } return keysTmp; });
获取redis所有的key 游标遍历
最新推荐文章于 2025-02-07 18:38:14 发布