Client.New
Overview
New connects to addr (host:port).
If you are coming from Node.js, the closest pattern is new Redis().
Method on Client — call it on a value of that type after constructing or receiving one from a constructor.
Signature
go
func New(addr string) *ClientCompare: Node.js · Standard Go · gox
js
const redis = new Redis();go
rdb := redis.NewClient(&redis.Options{Addr: addr})
val, err := rdb.Get(ctx, key).Result()go
import "github.com/sahilkhaire/gox/redis"
rdb, err := redis.New("localhost:6379")Example
go
import "github.com/sahilkhaire/gox/redis"
rdb, err := redis.New("localhost:6379")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()