valkey-io / valkey-go

A fast Golang Valkey client that supports Client Side Caching and Auto Pipelining.
Apache License 2.0
158 stars 10 forks source link

Add support for redis.Pipeliner, redis.Tx, redis.Nil, redis.Script, UniversalClient.Watch in adapter of valkey-go similar to go-redis #12

Closed royatanu94 closed 3 months ago

royatanu94 commented 3 months ago

Discussed in https://github.com/orgs/valkey-io/discussions/797

Add support for pipeline.go available in go-redis in valkey-go adapter Add support for tx.go available in go-redis in valkey-go adapter Add support for script.go available in go-redis in valkey-go adapter Add support for UniversalClient.Watch in valkey-go adapter

Add support for redis.Nil available in go-redis in valkey.go // Nil reply returned by Redis when key does not exist. const Nil = proto.Nil

Need to migrate below code with valkey-go

func (s *RedisStore) StoreData(_ context.Context, data *test.testData) error {

    pp := s.rc.Pipeline()
    pp.HSet(s.ctx, testData.key, testData.name, testData)

    var internalData []byte
    if internal != nil {
        internalData, err = proto.Marshal(internal)
        if err != nil {
            return err
        }
        pp.HSet(s.ctx, InternalKey, testData.Name, internalData)
    } else {
        pp.HDel(s.ctx, InternalKey, testData.Name)
    }

    if _, err = pp.Exec(s.ctx); err != nil {
        err = routing.RemoveIpFromError(err)
        return errors.Wrap(err, "could not create")
    }
    return nil
}
...
results, err := tx.TxPipelined(s.ctx, func(p redis.Pipeliner) error {
            p.HSet(s.ctx, IngressKey, info.IngressId, data)
            if info.StreamKey != "" {
                p.HSet(s.ctx, StreamKeyKey, info.StreamKey, info.IngressId)
            }
yhc9311 commented 3 months ago

Hi @royatanu94 @rueian , I will add script.go.

rueian commented 3 months ago

Hi @royatanu94,

The Pipeliner, Tx, Nil, Script, and Watch are all available in the 1.0.44. Please refer to the https://github.com/valkey-io/valkey-go/blob/main/valkeycompat/README.md for more examples.