简体   繁体   English

我可以对 Redis 值执行正则表达式搜索吗?

[英]Can I perform a regex search on Redis values?

I tried using RedisSearch but there you can perform a fuzzy search, but I need to perform a regex search like:我尝试使用 RedisSearch 但您可以执行模糊搜索,但我需要执行正则表达式搜索,例如:

key: "12345"
value: { name: "Maruti"}

searching "aru" will give the result "Mumbai", basically the regex formed is *aru* .搜索“aru”将给出结果“Mumbai”,基本上形成的正则表达式是*aru* Can anyone help me out how can I achieve it using Redis?谁能帮助我如何使用 Redis 实现它?

This can be done, but I do not recommend it - performance will be greatly impacted.可以这样做,但我不建议这样做 - 性能会受到很大影响。

If you must, however, you can use RedisGears for ad-hoc regex queries like so:但是,如果必须,您可以使用RedisGears进行临时正则表达式查询,如下所示:

127.0.0.1:6379> HSET mykey name Maruti
(integer) 1
127.0.0.1:6379> HSET anotherkey name Moana
(integer) 1
127.0.0.1:6379> RG.PYEXECUTE "import re\np = re.compile('.*aru.*')\nGearsBuilder().filter(lambda x: p.match(x['value']['name'])).map(lambda x: x['key']).run()"
1) 1) "mykey"
2) (empty array)

Here's the Python code for readability:这是 Python 代码以提高可读性:

import re
p = re.compile('.*aru.*')
GearsBuilder() \
    .filter(lambda x: p.match(x['value']['name'])) \
    .map(lambda x: x['key']) \
    .run()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 spring 数据在 redis 哈希表中搜索具有特定值的实体? - How can I search a redis hash table for entities that have a particular values using spring data? 我可以在Java中对邮件服务器执行搜索吗? - Can I perform a search on mail server in Java? 如何与java.util.regex执行部分匹配。*? - How can I perform a partial match with java.util.regex.*? 如何编写Java正则表达式,对不在注释中的组执行.replaceFirst? - How can I write a regex in Java that will perform a .replaceFirst on a group that is not in a comment? 我可以使用正则表达式或其他方法更快地执行此操作吗? - Can I perform this operation faster with regex or something else? 如何在Spring中对Solr搜索结果进行分组? - How can I perform grouping on Solr search results in Spring? 我如何在 android 中使用自定义适配器按字母顺序进行搜索 - how i can perform search alphabetical with custom adapter in android JAVA:算法:如何在加密值中执行减法运算 - JAVA: Algorithms : How can i perform Subtraction Operation in Encrypted Values 如何在Java中更改正则表达式搜索以忽略大小写 - How can I change Regex search in java to overlook case Sonar-ws-client返回401错误,即使我可以在UI中执行搜索 - Sonar-ws-client returning 401 error even though I can perform a search in the UI
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM