redis实现查询功能
作者:互联网
redis实现like查询功能
redis实现like 查询功能,针对此项功能做如下处理
key值存入要查询的关键字
java实现 插入要搜索的字段(代码片段)
String goods1 = "{\"goodsId\":1,\"goodsName\":\"金桔柠檬茶\",\"price\":13.5}";
redisTemplate.opsForValue().set("shop-金桔柠檬", goods1 );
String goods2 = "{\"goodsId\":2,\"goodsName\":\"丝滑奶茶\",\"price\":11.5}";
redisTemplate.opsForValue().set("shop-丝滑奶茶", goods2 );
String goods3 = "{\"goodsId\":3,\"goodsName\":\"原味奶茶\",\"price\":11.5}";
redisTemplate.opsForValue().set("shop-原味奶茶", goods3 );
String goods4 = "{\"goodsId\":4,\"goodsName\":\"木瓜奶茶\",\"price\":11.5}";
redisTemplate.opsForValue().set("shop-木瓜奶茶", goods4 );
String goods5 = "{\"goodsId\":4,\"goodsName\":\"珍珠奶茶\",\"price\":11.5}";
redisTemplate.opsForValue().set("shop-珍珠奶茶", goods5 );
redis 命令查询
redis命令
keys shop-*
结果展示:
1) "shop-木瓜奶茶"
2) "shop-金桔柠檬"
3) "shop-原味奶茶"
4) "shop-丝滑奶茶"
5) "shop-珍珠奶茶"
结果为存在redis中的key值
利用key进行查询
java代码实现(代码片段)
Set sets = stringRedisTemplate.keys("shop-茶*");
List<String> ids = stringRedisTemplate.opsForValue().multiGet(sets);
茶为传入参数,根据传入参数进行模糊查询。
标签:shop,功能,set,opsForValue,redis,查询,奶茶,redisTemplate 来源: https://blog.csdn.net/yeyuezhihun/article/details/106649785