Skip to content

Latest commit

 

History

History
70 lines (48 loc) · 2.14 KB

README.md

File metadata and controls

70 lines (48 loc) · 2.14 KB

go-elasticache

Thin abstraction over the Memcache client package gomemcache
allowing it to support AWS ElastiCache cluster nodes

Explanation

When using the memcache client gomemcache you typically call a constructor and pass it a list of memcache nodes like so:

mc := memcache.New("10.0.0.1:11211", "10.0.0.2:11211", "10.0.0.3:11212")

But when using the AWS ElastiCache service you need to query a particular internal endpoint via a socket connection and manually parse out the details of the available cluster.

In Ruby it seems most Memcache clients are setup to handle this for you, but in Go that doesn't appear to be the case. Hence I've created this package as a thin abstraction layer on top of the gomemcache package.

Example

Below is an example of how to use this package.

To run it locally you will need the following dependencies installed and running:

  • Memcache (e.g. docker run -d -p 11211:11211 memcached)
  • fake_elasticache (e.g. gem install fake_elasticache && fake_elasticache)
package main

import (
	"fmt"
	"log"

	"github.com/integralist/go-elasticache/elasticache"
)

func main() {
	mc, err := elasticache.New()
	if err != nil {
		log.Fatalf("Error: %s", err.Error())
	}

	if err := mc.Set(&elasticache.Item{Key: "foo", Value: []byte("my value")}); err != nil {
		log.Println(err.Error())
	}

	it, err := mc.Get("foo")
	if err != nil {
		log.Println(err.Error())
		return
	}

	fmt.Printf("%+v", it) 
  // &{Key:foo Value:[109 121 32 118 97 108 117 101] Flags:0 Expiration:0 casid:9}
}

Note: when running in production make sure to set the environment variable ELASTICACHE_ENDPOINT

Licence

The MIT License (MIT)

Copyright (c) 2016 Mark McDonnell