1

We recently started to work with redis-json (github.com/nitishm/go-rejson/v4) and redis-search (github.com/RediSearch/redisearch-go/redisearch) clients in Golang.

We need to support bulk insert operations of json objects and we don't want to use transactions. Is there a way to implement a pipeline with redis-json (we want to pipeline a bunch of json.set operations)? or if someone can refer me to a golang package which does support this kind of pipeline?

Thank you :)

nadavtsa
  • 19
  • 1
  • Questions seeking recommendations for packages are offtopic on StackOverflow. That said, you can use [Redigo](https://github.com/gomodule/redigo) to [pipeline](https://pkg.go.dev/github.com/gomodule/redigo/redis#hdr-Pipelining) the json.set command. – Charlie Tumahai Aug 31 '22 at 15:26

2 Answers2

3

I am the author of https://github.com/rueian/rueidis.

Here is an example of how to use rueidis for bulk insert and bulk read:

package main

import (
    "context"
    "strconv"

    "github.com/rueian/rueidis"
)

func main() {
    client, err := rueidis.NewClient(rueidis.ClientOption{InitAddress: []string{"127.0.0.1:6379"}})
    if err != nil {
        panic(err)
    }
    cmds := make(rueidis.Commands, 10000)
    for i := 0; i < len(cmds); i++ {
        cmds[i] = client.B().JsonSet().Key(strconv.Itoa(i)).Path("$").Value(rueidis.JSON(i)).Build()
    }
    for _, resp := range client.DoMulti(context.Background(), cmds...) { // bulk insert
        if err := resp.Error(); err != nil {
            panic(err)
        }
    }
    for i := 0; i < len(cmds); i++ {
        cmds[i] = client.B().JsonGet().Key(strconv.Itoa(i)).Build()
    }
    for i, resp := range client.DoMulti(context.Background(), cmds...) { // bulk read
        if v, err := resp.AsInt64(); err != nil || v != int64(i) {
            panic("unexpected response")
        }
    }
}
Rueian
  • 143
  • 2
  • 8
0

In the redis documentation itself there are recommended clients specific to each language.

https://redis.io/docs/stack/json/clients/

rueian/rueidis has the support for Pipelining https://github.com/rueian/rueidis/blob/master/pipe.go

Edit : https://github.com/gomodule/redigo <-- has more stars and seems to be recommended

  • I still can't figure out a way to pipeline a bunch of json.set commands, even with this client. Can you help me with that? maybe I'm missing something – nadavtsa Sep 01 '22 at 14:13