0

I have a redis store with some JSON docs. I want to do a query matching {status: 'new'}

How do I do this with redis?

There are some docs that show the CLI but they assume I have already got an index.

redis.cloud:6379> FT.SEARCH myIdx "@category:{foo} @category:(hello)"

Not quite sure if I can query on any field. How to do this in python, or do I have to use FT.SEARCH via the driver like some caveman raw SQL approach?

There's a ft (fulltext?) search module but that's overkill/not relevant.

There's an ORM that will enable this, but for a simple query I'd rather avoid a whole ORM and defining schemas, etc.

Do I have to create and update an index on the fields I want to search on? I'm confused that redis doesn't handle this in 2023, I thought it was for more than a simple key-value store now.

STerliakov
  • 4,983
  • 3
  • 15
  • 37
dcsan
  • 11,333
  • 15
  • 77
  • 118
  • Try `FT.SEARCH myIdx @\$\.status:new`. Redis requirements on JSON fields is weird. `$` means the root and field access is done hierarchically via `.` But in some locations it needs escaping via `\\` such as search string. I was not able to find a proper documentation on this, I hope someone may give some pointers. For example I could not make wildcard search or infix/suffix matching work. – zahir Jan 26 '23 at 15:15
  • this seems to be the CLI syntax. is there anything equivalent for the python driver? – dcsan Jan 26 '23 at 22:39

1 Answers1

0

Redis has the redis-py client For Python. The repo includes some examples on how to use it for different commands. It natively supports the simple CLI syntax, as well as most if not every redis command, and redis-stack commands as well.

For your need I don’t see a simple way to do secondary indexing without redisearch. You can try to maintain a set of all keys that are new with native redis commands, but for general secondary indexing and querying redisearch is the simplest way to do so.

Although it was initially created for full text search, it can handle today numeric, geo-location, tag and even vector fields. Searching for a specific tag is a pretty common use case nowadays.

A. Guy
  • 500
  • 1
  • 3
  • 10