当前位置: 首页 > 工具软件 > Zscan > 使用案例 >

* Redis —— Scan、SScan、HScan、ZScan

牟波
2023-12-01

一、数据库基本命令

1. 扫描所有数据表

scan 0

 

2. 扫描hash表Real_Gps中的两条记录

HSCAN Real_Gps 0 MATCH * COUNT 2

 

 

二、RedisTemplate操作scan

//1. 一次性获取Real_Gps中数据
        Map<Object, Object> map1 = redisTemplate.opsForHash().entries("5555");
        map1.forEach((o, o2) -> {
            System.out.println(o);
            System.out.println(o2);
        });
//2. 使用Scan方式遍历获取Real_Gps中的数据
        ScanOptions scanOptions = ScanOptions.scanOptions().count(1).match("*").build();
        Cursor<Map.Entry<Object, Object>> cursor = redisTemplate.opsForHash().scan("5555", scanOptions);
        while (cursor.hasNext()) {
            Map.Entry<Object, Object> entry = cursor.next();
            entry.getKey();
            entry.getValue();
            System.out.println("111111" + entry.getKey());
            System.out.println("222222" + entry.getValue());


        }
    }
 类似资料: