Git Product home page Git Product logo

mc's Introduction

mc.go: A Go client for Memcached

godoc Build Status

This is a (pure) Go client for Memcached. It supports the binary Memcached protocol and SASL authentication. It's thread-safe. It allows connections to entire Memcached clusters and supports connection pools, timeouts, and failover.

Install

Module-aware mode:

$ go get github.com/memcachier/mc/v3

Legacy GOPATH mode:

$ go get github.com/memcachier/mc

Use

import "github.com/memcachier/mc/v3"
// Legacy GOPATH mode:
// import "github.com/memcachier/mc"

func main() {
	// Error handling omitted for demo

	// Only PLAIN SASL auth supported right now
	c := mc.NewMC("localhost:11211", "username", "password")
	defer c.Quit()

	exp := 3600 // 2 hours
	cas, err = c.Set("foo", "bar", flags, exp, cas)
	if err != nil {
		...
	}

	val, flags, cas, err = c.Get("foo")
	if err != nil {
		...
	}

	err = c.Del("foo")
	if err != nil {
		...
	}
}

Missing Feature

There is nearly coverage of the Memcached protocol. The biggest missing protocol feature is support for multi_get and other batched operations.

There is also no support for asynchronous IO.

Performance

Right now we use a single per-connection mutex and don't support pipe-lining any operations. There is however support for connection pools which should make up for it.

Get involved!

We are happy to receive bug reports, fixes, documentation enhancements, and other improvements.

Please report bugs via the github issue tracker.

Master git repository:

  • git clone git://github.com/memcachier/mc.git

Licensing

This library is MIT-licensed.

Authors

This library is written and maintained by MemCachier. It was originally written by Blake Mizerany.

mc's People

Contributors

alevy avatar bmizerany avatar camdencheek avatar devjoes avatar dterei avatar moukoublen avatar saschat avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mc's Issues

Version function breaks on multi-node setup.

Hello and thanks for this library 😎

Right now message object (msg) is being reused for both send and receive in perform functionality.

mc/client.go

Lines 413 to 420 in ae22d23

for _, s := range c.servers {
if s.isAlive {
err = s.perform(m)
if err == nil {
vers[s.address] = m.val
}
}
}

There are some cases (e.g. Version()) in which the message is being sent to all nodes.

Because of that after the first send-receive the message msg is "mutated" as answer and thus not valid message to send in the next request.

Steps to reproduce

memcached -p 11289
memcached -p 11290
memcached -p 11291

And run

c := NewMC("localhost:11289 localhost:11290 localhost:11291", "", "")
vers, err := c.Version()

(I will open a PR for that with a fix suggestion)

Operator precedence issue in getServer when server is unreachable

When n servers have isAlive set to false the following line attempts to read out of the bounds of the c.servers array:

c.servers[idx+i%nServers]

If idx==1, i==1 and nServers==2 then 1+1%2 == 2

Should be rewritten as

c.servers[(idx+i)%nServers]

I'll raise a PR shortly.

Too many Ticker not be freed

every time Get() a key, server.perform create a Ticker ,so my CPU rate is grow slowly. As my option, should be used time.After().

Hasher in client config is unusable

type Config struct {
	Hasher     hasher
        ...
type hasher interface {
	update(servers []*server)
	getServerIndex(key string) (uint, error)
}

now Hasher should implement an interface with private methods with private types like *server so the only way to define a Hasher is to use a NewModuloHasher() function.

the problem is that Hasher field is public, but i cant really use it.

i purpose to change the interface this way:

type Hasher interface {
	Update(servers []strings)
	GetServerIndex(key string) (uint, error)
}

this will let us to make custom implemenation of Hasher interface

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.