Version: v0.0.26 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2022 License: BSD-3-Clause Imports: 18 Imported by: 0



Package redis provides cache service by redis (cloud memorystore).



View Source
const (
	DefaultMaxIdleConns   = 50
	DefaultMaxActiveConns = 200

default max number of connections. note: in GCP, redis quota is 65,000


This section is empty.


func AddrFromEnv

func AddrFromEnv() (string, error)

AddrFromEnv returns redis server address from environment variables.


type Client

type Client struct {
	// contains filtered or unexported fields

Client is cache service client for redis.

func NewClient

func NewClient(ctx context.Context, addr string, opts Opts) Client

NewClient creates new cache client for redis.

func (Client) Close

func (c Client) Close() error

Close releases the resources used by the client.

func (Client) Get

func (c Client) Get(ctx context.Context, in *pb.GetReq, opts ...grpc.CallOption) (*pb.GetResp, error)

Get fetches value for the key from redis.

func (Client) Put

func (c Client) Put(ctx context.Context, in *pb.PutReq, opts ...grpc.CallOption) (*pb.PutResp, error)

Put stores key:value pair on redis.

type FakeServer added in v0.0.17

type FakeServer struct {
	// contains filtered or unexported fields

FakeServer is a fake redis server for stress test.

func NewFakeServer added in v0.0.17

func NewFakeServer(tb testing.TB) *FakeServer

NewFakeServer starts a new fake redis server.

func (*FakeServer) Addr added in v0.0.17

func (s *FakeServer) Addr() net.Addr

Addr returns address of the fake redis server.

func (*FakeServer) Close added in v0.0.17

func (s *FakeServer) Close()

Close shuts down the fake redis server.

type Opts added in v0.0.17

type Opts struct {
	// Prefix is key prefix used by the client.
	Prefix string

	// MaxIdleConns is max number of idle connections.
	MaxIdleConns int

	// MaxActiveConns is max number of active connections.
	MaxActiveConns int

	// EntryTTL sets the expiration time of an entry, 0 means entry will never expire.
	EntryTTL time.Duration

Opts is redis client option.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL