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.

相关推荐
颜如玉3 分钟前
动态拼接SQL实践备忘📝
java·sql·mybatis
952363 分钟前
数据结构-堆
java·数据结构·学习·算法
while(1){yan}13 分钟前
MYSQL索引的底层数据结构
数据结构·数据库·mysql
by__csdn15 分钟前
Spring Boot 全面解析
java·数据库·spring boot·后端·spring
她说..16 分钟前
基于Redis实现的分布式唯一编号生成工具类
java·数据库·redis·分布式·springboot
西岭千秋雪_18 分钟前
Kafka客户端参数(一)
java·分布式·后端·kafka·linq
合作小小程序员小小店24 分钟前
web网页开发,在线%人力资源管理%系统,基于Idea,html,css,jQuery,java,jsp,ssh,mysql。
java·前端·css·数据库·mysql·html·intellij-idea
ASKED_201927 分钟前
常用 Linux 命令大全(文件、网络、时间、进程、数据库、工具全覆盖)
linux·网络·数据库
Felix_XXXXL28 分钟前
28.<Spring博客系统⑤(部署的整个过程
java·后端
Ace_317508877628 分钟前
拼多多商品详情接口深度解析:从加密参数破解到数据全量获取
前端·数据库·github