您可以使用
RedisCallbackon
RedisOperations来这样做。
redisTemplate.execute(new RedisCallback<Iterable<byte[]>>() { @Override public Iterable<byte[]> doInRedis(RedisConnection connection) throws DataAccessException { List<byte[]> binaryKeys = new ArrayList<byte[]>(); Cursor<byte[]> cursor = connection.scan(ScanOptions.NONE); while (cursor.hasNext()) { binaryKeys.add(cursor.next()); } try { cursor.close(); } catch (IOException e) { // do something meaningful } return binaryKeys; }});


