Issues with Go

11 views
Skip to first unread message

Gabriel Tomazi

unread,
Jan 17, 2020, 1:38:56 PM1/17/20
to RedisJSON Discussion Forum
Hi,

I'm trying to use the RedisJSON2 new functionalities with Go, but the go-rejson still don't have them. I tried to do the functions manually and they work in parts. 
I can get the data with queries, I can insert, but when the data is inserted via Go, the fields are not being able to be filtered.
Any ideias how can I fix it, or if there is another repo where I can get these funcions.

Here is the repo I forked and with the new functions:


Guy Korland

unread,
Jan 19, 2020, 4:11:17 AM1/19/20
to RedisJSON Discussion Forum
Hi Gabriel,

Thank you very much for the effort to extend the go-rejson client!

Can you please add an example code? How to run and recreate the issue with the new go client?

Guy

Gabriel Tomazi

unread,
Jan 19, 2020, 2:44:11 PM1/19/20
to RedisJSON Discussion Forum

Just do a simple (in my case) goredis connection
rh := rejson.NewReJSONHandler()
conn := rh.SetGoRedisClient(goredis.NewClient(&goredis.Options{Addr: HostRedis}))


Inserting and index
_, err = conn.JSONIndexAdd("users", "last", ".last")

And inserting the json
_, err = conn.JSONSetWithIndex("user1", ".", document, "users")

Where de var document is a map[string]interface{} with data.
The function JSONSetWithIndex, do the same Marshal as JSONSet, so the map turn in a json.

Then a JSONQGet i`m using:
test, _ := conn.JSONQGet("users", "@last:Smith", "@first:Joe")
Just pass the params as in the string of query.

The weird is that the data is stored in Redis as JSON, but the are not find by the index. If I add the JSON.SET command line direct in cli, the function o QGET works fine.

Gabriel Tomazi

unread,
Jan 20, 2020, 7:51:14 AM1/20/20
to RedisJSON Discussion Forum


I think that the marshal may be the problem, the output of the command:


Captura de tela de 2020-01-20 09-47-48.png


The document is in an []byte.

I tried without marshal too, putting the same command line string on a Do function of redis. It inserts in Redis, but the fields are not filtered.
PS: Yes, i'm adding the fields to the index
Reply all
Reply to author
Forward
0 new messages