Skip to content

Commit

Permalink
Redis: propagate redis query syntax though "filter" (openai#209)
Browse files Browse the repository at this point in the history
* fix: remove the * wildcard from the TAG escape characters. Add notebook to demo behaviour of the filter feature.

* fix: remove print

* fix: remove parentheses

* fix: remove whitespace

---------

Co-authored-by: Ben Lasscock <[email protected]>
  • Loading branch information
blasscoc and blasscoc-tgs authored May 9, 2023
1 parent 919e543 commit 51579b6
Show file tree
Hide file tree
Showing 2 changed files with 515 additions and 3 deletions.
7 changes: 4 additions & 3 deletions datastore/providers/redis_datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
{"name": "search", "ver": 20600},
{"name": "ReJSON", "ver": 20404}
]
REDIS_DEFAULT_ESCAPED_CHARS = re.compile(r"[,.<>{}\[\]\\\"\':;!@#$%^&*()\-+=~\/ ]")

REDIS_DEFAULT_ESCAPED_CHARS = re.compile(r"[,.<>{}\[\]\\\"\':;!@#$%^&()\-+=~\/ ]")

# Helper functions
def unpack_schema(d: dict):
Expand All @@ -59,7 +60,7 @@ async def _check_redis_module_exist(client: redis.Redis, modules: List[dict]):
installed_modules = {module["name"]: module for module in installed_modules}
for module in modules:
if module["name"] not in installed_modules or int(installed_modules[module["name"]]["ver"]) < int(module["ver"]):
error_message = "You must add the RediSearch (>= 2.6) and ReJSON (>= 2.4) modules from Redis Stack. " \
error_message = "You must add the RediSearch (>= 2.6) and ReJSON (>= 2.4) modules from Redis Stack. " \
"Please refer to Redis Stack docs: https://redis.io/docs/stack/"
logging.error(error_message)
raise AttributeError(error_message)
Expand Down Expand Up @@ -207,7 +208,7 @@ def _typ_to_str(typ, field, value) -> str: # type: ignore
if isinstance(typ, TagField):
return f"@{field}:{{{self._escape(value)}}} "
elif isinstance(typ, TextField):
return f"@{field}:{self._escape(value)} "
return f"@{field}:{value} "
elif isinstance(typ, NumericField):
num = to_unix_timestamp(value)
match field:
Expand Down
Loading

0 comments on commit 51579b6

Please sign in to comment.