Client.NewFromClient
Overview
NewFromClient wraps an existing client.
Part of the redis package — Node.js analog: ioredis.
Method on Client — call it on a value of that type after constructing or receiving one from a constructor.
Signature
go
func NewFromClient(c *goredis.Client) *ClientCompare: Node.js · Standard Go · gox
js
// Typical ioredis pattern in Node.jsgo
rdb := redis.NewClient(&redis.Options{Addr: addr})
val, err := rdb.Get(ctx, key).Result()go
import "github.com/sahilkhaire/gox/redis"
wrapper := redis.NewFromClient(rdb)Example
go
import "github.com/sahilkhaire/gox/redis"
wrapper := redis.NewFromClient(rdb)Tips
Pass context.Context as the first argument so cancellation and deadlines propagate correctly.
Standard library alternative
Use the standard library directly:
go
rdb := redis.NewClient(&redis.Options{Addr: addr})
val, err := rdb.Get(ctx, key).Result()