Code Monkey home page Code Monkey logo

gomemcache's Introduction

About

This is a memcache client library for the Go programming language (http://golang.org/).

It is a fork of https://github.com/bradfitz/gomemcache/memcache, with support for Autodiscovery client based on https://cloud.google.com/memorystore/docs/memcached/auto-discovery-overview

Installing

Using go get

$ go get github.com/google/gomemcache/memcache

After this command gomemcache is ready to use. Its source will be in:

$GOPATH/src/github.com/google/gomemcache/memcache

Example without Autodiscovery

import (
        "fmt"
        "github.com/google/gomemcache/memcache"
)

func main() {
     // Create a client by providing the list of memcached servers.
     mc := memcache.New("10.0.0.1:11211", "10.0.0.2:11211", "10.0.0.3:11212")

     // For data queries (e.g., SET/GET), the client will first select a
     // memcached server based on computed hash of the key and then send
     // the query to that server.
     mc.Set(&memcache.Item{Key: "foo", Value: []byte("my value")})

     it, _ := mc.Get("foo")
     fmt.Println(string(it.Value)) // Expecting "my value" to be printed
}

Example with Autodiscovery

import (
        "fmt"
        "time"
        "github.com/google/gomemcache/memcache"
)

func main() {
     // Create a client by providing the autodiscovery endpoint. Behind the
     // scene, the client queries the autodiscovery endpoint to fetch the
     // list of memcached servers.
     mcDiscovery, _ := memcache.NewDiscoveryClient("10.0.0.1:11211", 30 * time.Second)

     // For data queries (e.g., SET/GET), the client will first select a
     // memcached server based on computed hash of the key and then send
     // the query to that server.
     mcDiscovery.Set(&memcache.Item{Key: "foo", Value: []byte("my value")})

     it, _ := mcDiscovery.Get("foo")
     fmt.Println(string(it.Value)) // Expecting "my value" to be printed

     mcDiscovery.StopPolling()
}

Note

Remember to call StopPolling() on the discovery enabled client to stop the polling, else this can leak "go" methods.

Full docs, see:

See https://godoc.org/github.com/google/gomemcache/memcache

Or run:

$ godoc github.com/google/gomemcache/memcache

gomemcache's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gomemcache's Issues

Prevent autodiscovery to go to old version if new version has been seen

Currently, autodiscovery can go to an older discovery information after it has already discovered new information.

To fix this, configID extracted on line:[1] should be checked with the last discovered config ID and clusterConfig.NodeAddresses should be updated only if clusterConfig.ConfigID < newConfigID

[1]

configID, parseError := strconv.ParseInt(configIDLine, 10, 64)

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.