Skip to content
Node: ioredisgithub.com/sahilkhaire/gox/redis

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) *Client

Compare: Node.js · Standard Go · gox

js
// Typical ioredis pattern in Node.js
go
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()

Back to redis package overview

MIT Licensed · Built for Node.js developers moving to Go