使用redis的Hscan


hscan 查看一个hscan中符合条件的属性;

HashOperations hashOperations  =redisTemplate.opsForHash();
   Cursor
<Map.Entry<String, Date>> cursor =hashOperations.scan("hash:test", ScanOptions.scanOptions().match("*123456*").count(1).build()); while(cursor.hasNext()){ Map.Entry<String, Date> next = cursor.next(); String key = next.getKey(); Date value = next.getValue(); System.out.println(key); System.out.println(value); } try { cursor.close(); }catch (Exception e){ }
Map.Entry<String, Date> 是泛型,和我们存入的数据类型对应
count()应该是代表一次取出多少个符合条件的属性;
这样就可以避免一次性查询过多的key造成redis堵塞;
但是我们在遍历
cursor的时候,所有的属性都已经在这里了;

最后一定要记得关闭连接
cursor.close();

如果是针对所有key模糊查询:
Set keys = stringRedisTemplate.keys(key);
opsfor***都是对针对具体数据类型的操作,会对数据做一些封装。
如果处理的key不考虑其数据的类型,都是在RedisTemplate中操作,



 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM