redis / node-redis

Redis Node.js client

Home Page:https://redis.js.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SORTBY causes the query to not be sent as javascript query.

hypo-thesis opened this issue · comments

I have a query as such

 const searchOption = {
    LIMIT: { from: (page - 1) * 10, size: 10 },
    // SORTBY: { BY: "date", DIRECTION: "DESC" },
  };
    const query =? await router.R.ft.search("U", `*`, searchOption)

Which gives me valid javascript object in return with res.status(200).json(query)

yet introducing SORTBY: { BY: "date", DIRECTION: "DESC" }, to the options will cause the output to be sent like this :

{
    "id": "U_dummy103",
    "value": {
        "date": "1669115481580",
        "$": "{\"email\":\"asd@asd.com\",\"name\":\"shan shahab\",\"answers\":[],\"language\":\"E\",\"company\":\"hfp\",\"welcomeMessage\":\"\",\"noq\":{\"reading\":1,\"listening\":0,\"writing\":1,\"speaking\":2},\"score\":{\"reading\":1,\"writing\":1,\"speaking\":1,\"listening\":1},\"questions\":[],\"logCount\":0,\"status\":\"pending\",\"date\":1669115481580}"
    }
}

How can I get a valid javascript object while using sortby?

Environment:

  • Node.js Version: 19.0.1
  • Node Redis Version: 4.5.1
  • Platform: Ubuntu 18

So it would appear that this requires a RETURN and if there is no RETURN the date structure comes back as the one above.

Adding RETURN : ['email' , 'name' , 'date' , 'status'] to the query solved the issue.