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