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.

相关推荐
愤怒的代码9 分钟前
简析 Kotlin 内联函数:与inline相关的关键字
android·java·kotlin
java干货9 分钟前
拒绝应用层循环!用 MySQL 8.0 JSON_TABLE 一键把 JSON 数组“变”成表
数据库·mysql·json
用针戳左手中指指头9 分钟前
Spring源码篇(十三)循环依赖
java·后端·spring·循环依赖·相互依赖
To Be Clean Coder10 分钟前
【Spring源码】getBean源码实战(五)——MergedBean
java·后端·spring
蜗牛~turbo11 分钟前
云星空 应收款账龄分析取数SQL
数据库·sql·金蝶·云星空·k3 cloud
l1t14 分钟前
一个用SQL Sever求解数独的SQL
数据库·sql·sql server·数独·sudoku
SimonKing28 分钟前
局域网内跨平台传文件,没有比LocalSend更方便的了
java·后端·程序员
超级小龙虾28 分钟前
VS Code 本身没有内置像 IntelliJ IDEA 那样的完整书签(Bookmarks)
java
未来之窗软件服务38 分钟前
数据库(四)MySQL 数据表修复——东方仙盟练气
数据库·mysql·仙盟创梦ide·东方仙盟·数据库修复
万物挽挽39 分钟前
单例模式的优点和缺点分别是什么?
java