skip to Main Content

I’m working with Redisgraph.

I have a node Person with three properties: name (string), age (number), isAlive (boolean).

If I store the age as number, without the quotes, it correctly store it as a number. So, if I query:

MATCH (p:Person) RETURN p

what I have is:

{ name: 'John', age: 30, isAlive: 'true' }

but there’s a way to query and get real booleans?

What I want is:

{ name: 'John', age: 30, isAlive: true }

Thank you!

2

Answers


  1. It sounds like you’re querying RedisGraph using redis-cli. The RESP protocol that processes module replies only allows strings and integers as primitive data types that can be passed, so your request can’t be accomplished through redis-cli.

    All of the client libraries, however, will decode replies to their correct type. I’d recommend using one as an intermediary to interact with RedisGraph – https://oss.redis.com/redisgraph/clients/.

    Login or Signup to reply.
  2. Redisgraph can return a compact format where the type of the values are included. In order to use this you need to pass the --compact flag (which also works in redis-cli):

    GRAPH.QUERY demo "MATCH (a) RETURN a" --compact
    

    Some client libraries takes advantage of this compact format in order to return the correct type. The type of value is returned as an integer:

    typedef enum {
        PROPERTY_UNKNOWN = 0,
        PROPERTY_NULL = 1,
        PROPERTY_STRING = 2,
        PROPERTY_INTEGER = 3,
        PROPERTY_BOOLEAN = 4,
        PROPERTY_DOUBLE = 5,
    } PropertyTypeUser;
    

    You can read more about the compact format here.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search