memorystore_go

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: MIT Imports: 8 Imported by: 0

README

memorystore-go

memorystore-go is a Go module that makes it easy to connect, read, and write to GCP's managed MemoryStore service.

Usage

Google Cloud's MemoryStore currently supports Redis and Memcache.

Unit Tests

You'll need Redis running on your local machine to run unit tests. To run them, navigate to the /tests/ directory and run

REDIS_ADDRESS=localhost REDIS_PORT=55000 REDIS_PASSWORD=put_your_password_here go test

MemoryStore

The MemoryStore interface will require Redis and Memcache implementations to look like this:

type MemoryStore interface {
	Delete(key string) error
	Health() error
	Get(key string) (string, error)
	Set(key string, value interface{}, expiration time.Duration) error
}

Redis

Create a new Redis Store
import memorystore_go "github.com/clearchanneloutdoor/memorystore-go"

func main() {
	config := memorystore_go.RedisConfig {
	    Address: "localhost",
		CACertFile: "file/to/cacert",
		Port: "6379",
		Password: "password",
    }

	redis, err := memorystore_go.NewRedis(config)
	if err != nil {
	    // Handle error
    }
}
Health Check

Health checks can be configured to ensure your service has a working connection to MemoryStore.

func main() {
	if err := redis.Health(); err != nil {
	    // Handle error
    }
}
Get
value, err := redis.Get("key")
Set
var value interface{}
if err := redis.Set("key", value, 0); err != nil {
    // Handle error
}
Delete
if err := redis.Delete("key"); err != nil {
    // Handle error
}

Memcache

Create a new Memcache Store

Not Supported Yet

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MemoryStore

type MemoryStore interface {
	Delete(key string) error
	Health() error
	Get(key string) (string, error)
	Set(key string, value interface{}, expiration time.Duration) error
}

type Redis

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

func NewRedis

func NewRedis(config RedisConfig) (Redis, error)

func NewRedisMock added in v1.0.1

func NewRedisMock(client *redis.Client) Redis

func (Redis) Delete

func (r Redis) Delete(key string) error

func (Redis) Get

func (r Redis) Get(key string) (string, error)

func (Redis) Health

func (r Redis) Health() error

func (Redis) Set

func (r Redis) Set(key string, value interface{}, expiration time.Duration) error

type RedisClient added in v1.0.1

type RedisClient interface {
	Del(ctx context.Context, keys ...string) *redis.IntCmd
	Ping(ctx context.Context) *redis.StatusCmd
	Get(ctx context.Context, key string) *redis.StringCmd
	Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd
}

type RedisConfig

type RedisConfig struct {
	Address    string
	CACertFile string
	Port       string
	Password   string
}

Jump to

Keyboard shortcuts

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