往Redis中初始化几条测试数据:
china:beijing
china:shandong:heze
china:shandong:jinan
测试代码:
- Jedis jedis = new Jedis("10.110.20.152", 6379);
- Set<String> set = jedis.keys("china:shandong*");
- for (String key : set) {
- System.out.println(key);
- }
输出结果:
china:shandong:heze
china:shandong:jinan
测试代码:
- Jedis jedis = new Jedis("10.110.20.152", 6379);
- Set<String> set = jedis.keys("china:beijing?");
- for (String key : set) {
- System.out.println(key);
- }
输出结果:空
测试代码:
- Jedis jedis = new Jedis("10.110.20.152", 6379);
- Set<String> set = jedis.keys("china:beijing*");
- for (String key : set) {
- System.out.println(key);
- }
输出结果:
china:beijing
通配符说明:
* 0到任意多个字符
? 1个字符
文章转自:http://huangqiqing123.iteye.com/blog/2391139