elasticache

package module
v0.0.0-...-ea83fa6 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2017 License: MIT Imports: 11 Imported by: 0

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 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.

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/apalmblad/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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NEW_COMMAND = "config get cluster"
View Source
var NEW_COMMAND_AVAILABLE_VERSION, _ = version.NewVersion("1.4.14")
View Source
var NODE_SEPARATOR = " "
View Source
var OLD_COMMAND = "get AmazonElastiCache:cluster"
View Source
var OUTPUT_END_MARKER = "END"
View Source
var STATS_COMMAND = "stats"
View Source
var VERSION_REGEX = regexp.MustCompile("^STAT version ([0-9.]+)\\s*$")

Functions

This section is empty.

Types

type Client

type Client struct {
	*memcache.Client
}

Client embeds the memcache client so we can hide those details away

func New

func New() (*Client, error)

New returns an instance of the memcache client

func (*Client) Set

func (c *Client) Set(item *Item) error

Set abstracts the memcache client details away, by copying over the values provided by the user into the Set method, as coercing the custom Item type to the required memcache.Item type isn't possible. Downside is if memcache client fields ever change, it'll introduce a break

type Item

type Item memcache.Item

Item embeds the memcache client's type of the same name

type Node

type Node struct {
	Host string
	IP   string
	Port int
}

func (Node) URL

func (node Node) URL() string

type NodeList

type NodeList *[]Node

type StatInformation

type StatInformation struct {
	Version *version.Version
}

Jump to

Keyboard shortcuts

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