Search code examples
redisredis-om

How to fetch data using redis-om?


I want to fetch a certain user from Redis database using redis-om

const album = await albumRepository.fetch('01FJYWEYRHYFT8YTEGQBABJ43J')
album.artist // "Mushroomhead"
album.title // "The Righteous & The Butterfly"
album.year // 2014
album.genres // [ 'metal' ]
album.outOfPublication // true

I know that the code below will fetch it. Problem is, how would you know the UID redis-om provides ('01FJYWEYRHYFT8YTEGQBABJ43J') on page load?

All tutorials use redis insight to get the id, but in a real life project. You wouldn’t have that?

The only solution i can think of is to make my own UID instead of the one redis-om provides. That way i can fetch it ('ihavethisuid'). Can someone please share insight or best practice here?

Or am I suppose to use redis search? I’m not doing a “google” app. Or a search bar. I just need redis as a database. On page load. It needs to load xyz data. Like Facebook.


Solution

  • When you create an Entity with Redis OM, the object returned has the entityId on it. You can get it there.

    Your suggested solution is also perfectly viable and I have done this myself. Works well for things like user IDs and whatnot. Be sure to make it a 'string' and not a 'text' in the Schema.