GithubHelp home page GithubHelp logo

thompsonlabs / go-elasticache Goto Github PK

View Code? Open in Web Editor NEW

This project forked from integralist/go-elasticache

0.0 0.0 0.0 1.72 MB

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

License: MIT License

Go 99.33% Makefile 0.67%

go-elasticache's Introduction

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

go-elasticache's People

Contributors

integralist avatar thompsonlabs avatar alrs avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.