Documentation

Overview

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

Index

Constants

View Source
const (
	DefaultMaxIdleConns   = 50
	DefaultMaxActiveConns = 200
)

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

Variables

This section is empty.

Functions

func AddrFromEnv

func AddrFromEnv() (string, error)

AddrFromEnv returns redis server address from environment variables.

Types

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

type FakeServer struct {
	// contains filtered or unexported fields
}

FakeServer is a fake redis server for stress test.

func NewFakeServer

func NewFakeServer(tb testing.TB) *FakeServer

NewFakeServer starts a new fake redis server.

func (*FakeServer) Addr

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

Addr returns address of the fake redis server.

func (*FakeServer) Close

func (s *FakeServer) Close()

Close shuts down the fake redis server.

type Opts

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
}

Opts is redis client option.