redis 查找key使用正在表达式与java的区别

redis与java的正则表达式语法有些区别,需要特别注意一下。

Redis支持的正则表达式规则如下‌:

  • *:匹配任意数量的字符。
  • ?:匹配零或一个字符。
  • []:匹配指定范围内的字符‌12。

Redis中使用正则表达式的命令和示例‌:

  • KEYS pattern:该命令可以返回与指定模式匹配的所有键名。例如,KEYS user*可以获取所有以"user"开头的键‌3。
  • SCAN:这是一个迭代器命令,用于逐步遍历键空间。它支持使用正则表达式,但需要注意的是,SCAN命令本身不支持直接使用正则表达式,而是通过模式匹配来实现类似的功能。例如,SCAN 0 MATCH *pattern*可以逐步返回匹配指定模式的键‌。

Keys

Another way to iterate over the keyspace is to use the KEYS command, but this approach should be used with care, since KEYS will block the Redis server until all keys are returned.

Warning : consider KEYS as a command that should only be used in production environments with extreme care.

KEYS may ruin performance when it is executed against large databases. This command is intended for debugging and special operations, such as changing your keyspace layout. Don't use KEYS in your regular application code. If you're looking for a way to find keys in a subset of your keyspace, consider using SCAN or sets.

Supported glob-style patterns:

  • h?llo matches hello, hallo and hxllo
  • h*llo matches hllo and heeeello
  • h[ae]llo matches hello and hallo, but not hillo
  • h[^e]llo matches hallo, hbllo, ... but not hello
  • h[a-b]llo matches hallo and hbllo

Use \ to escape special characters if you want to match them verbatim.

相关推荐
Tao____18 分钟前
通用性物联网平台
java·物联网·mqtt·低代码·开源
曹轲恒25 分钟前
SpringBoot整合SpringMVC(上)
java·spring boot·spring
Mr__Miss26 分钟前
说下Mysql的MVCC机制
数据库·mysql
曾经的三心草37 分钟前
redis-3-Hash-List
redis·list·哈希算法
老徐电商数据笔记1 小时前
BI工具与数据分析平台:数据价值呈现的最后一公里
数据库·数据挖掘·数据分析·bi·bi选型思考
JH30731 小时前
Java Spring中@AllArgsConstructor注解引发的依赖注入异常解决
java·开发语言·spring
码农水水1 小时前
米哈游Java面试被问:机器学习模型的在线服务和A/B测试
java·开发语言·数据库·spring boot·后端·机器学习·word
2601_949575862 小时前
Flutter for OpenHarmony二手物品置换App实战 - 表单验证实现
android·java·flutter
酉鬼女又兒2 小时前
SQL24 统计每个用户的平均刷题数
数据库·sql·mysql
血小板要健康3 小时前
如何计算时间复杂度(上)
java·数据结构·算法