Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/integralist/go-elasticache

Thin abstraction over the Memcache client package gomemcache (https://github.com/bradfitz/gomemcache) allowing it to support AWS ElastiCache cluster nodes
https://github.com/integralist/go-elasticache

aws elasticache elasticache-clusters go golang memcache memcache-client memcached

Last synced: 4 months ago
JSON representation

Thin abstraction over the Memcache client package gomemcache (https://github.com/bradfitz/gomemcache) allowing it to support AWS ElastiCache cluster nodes

Awesome Lists containing this project

README

        

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](https://github.com/bradfitz/gomemcache) you typically call a constructor and pass it a list of memcache nodes like so:

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

But when using the [AWS ElastiCache](https://aws.amazon.com/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](https://github.com/stevenjack/fake_elasticache) (e.g. `gem install fake_elasticache && fake_elasticache`)

```go
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)](http://opensource.org/licenses/MIT)

Copyright (c) 2016 [Mark McDonnell](http://twitter.com/integralist)