skip to Main Content

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 🙂

2

Answers


  1. 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

    Login or Signup to reply.
  2. 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")
            }
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search