redis-om-node
redis-om-node copied to clipboard
Support for embedded objects, embedded collections, and lists of numbers
As far as I know you currently can't embed and index objects (schemas), collections (lists of objects/schemas), or lists of non-strings using the Schema model.
Is there currently a workaround for doing these things?
Embedding other objects is only supported by the Redis OM Python client. This has been asked for by multiple users. I am aware of the desirability of that feature. It's in the backlog and there are other issues asking for it. It's a significant change and won't be happening immediately. The workaround is to create two schemas and fetch what you need separately. You can add a custom method to your Entity that does that for you.
The other requests are more difficult because Redis OM has to work with both Hashes and JSON. Creating any sort of embedded collection of objects is not possible with a Hash. Just ain't gonna happen. Arrays are easier. I create the string arrays that are in there currently by parsing on a delimiter. This has gotchas and corners but works well enough. JSON is more forgiving and the arrays are stored as actual arrays. Adding new array types would be straightforward enough—parse on the delimiter and coerce the types—but the searchability of them would be inconsistent as RediSearch has limitations on the types that can be searched within arrays (which are just TAG fields in RediSearch) and this would vary between Hashes and JSON. As RediSearch becomes more powerful, so too will these capabilities in Redis OM.
If you just need to use collections of primitives, the workaround is to store them as strings and coerce them in your code. If you want to store collections of objects within a single document, the workaround is to create two schemas. See the first paragraph.
I expect to add new types of primitive arrays to Redis OM fairly soon as the capabilities of RediSearch are expanding. Arrays of booleans in JSON documents are now searchable in RediSearch and so they'll be an obvious next candidate. I believe arrays of numbers in JSON are being worked on too so that should happen soon.
My opinion is Redis OM Node is unusable until we have nested object. I will use normal node-redis package to store and retrieve json values. As JS and Python and Java developer is hard to understand the issue. JSON is javascript , so the native language itself does not support nesting ?? If it was the other way around it make sense.
So what can I do to help ?
This feature will be released with version 1.0.
When will 1.0 be released?
This was fixed with the release of Redis OM 0.4.0 Beta. Install it with npm install redis-om@beta
.
Except the non-string arrays. That still waiting on changes to RediSearch. But I'm gonna mark this as resolved.
@guyroyse any chance we could get an explicit example . . . for the criminally obtuse? 🤪
@humblecoder embedded objects is now available in v0.4.0. On the NPM page there is a section on working with JSON that shows embedded objects.
@wjohnsto yup, my concern was regarding specificity requirements without losing too much control of the object. Seeing that we don't have to specify all the fields, I'm now using a combination of nestjs-zod
with redis-om
. Appreciate the input!
@humblecoder embedded objects is now available in v0.4.0. On the NPM page there is a section on working with JSON that shows embedded objects.
i can not see any example,is there an exahle how you do it ?