mc

package
v0.0.0-...-fa9699e Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2015 License: GPL-3.0 Imports: 8 Imported by: 0

README

mc.go: A pure Go driver for Memcached (binary protocol, thread-safe)

Install

	$ go get github.com/bmizerany/mc

Use

	import "github.com/bmizerany/mc"

	func main() {
		// Error handling omitted for demo
		cn, err := mc.Dial("tcp", "localhost:11211")
		if err != nil {
			...
		}

		// Only PLAIN SASL auth supported right now
		// See: http://code.google.com/p/memcached/wiki/SASLHowto
		err = cn.Auth("foo", "bar")
		if err != nil {
			...
		}
		

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

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

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

Please Contribute

Not all of the commands are implemented. Only the ones I immedietly needed. Each command is trival to implement. If you'd like add one, please do so and send a pull request.

The current commands are:

Get, Set, Del, Incr, Decr

Performance

Right now the mutex is by far the largest bottleneck. There are thoughts on how to reduce it's impact. Any help is always appreciated.

LICENCE

Copyright (C) 2011 by Blake Mizerany

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

View Source
const (
	OpGet = uint8(iota)
	OpSet
	OpAdd
	OpReplace
	OpDelete
	OpIncrement
	OpDecrement
	OpQuit
	OpFlush
	OpGetQ
	OpNoop
	OpVersion
	OpGetK
	OpGetKQ
	OpAppend
	OpPrepend
	OpStat
	OpSetQ
	OpAddQ
	OpReplaceQ
	OpDeleteQ
	OpIncrementQ
	OpDecrementQ
	OpQuitQ
	OpFlushQ
	OpAppendQ
	OpPrependQ
)

Ops

View Source
const (
	OpAuthList = uint8(iota + 0x20)
	OpAuthStart
	OpAuthStep
)

Auth Ops

Variables

View Source
var (
	ErrNotFound       = errors.New("mc: not found")
	ErrKeyExists      = errors.New("mc: key exists")
	ErrValueTooLarge  = errors.New("mc: value to large")
	ErrInvalidArgs    = errors.New("mc: invalid arguments")
	ErrValueNotStored = errors.New("mc: value not stored")
	ErrNonNumeric     = errors.New("mc: incr/decr called on non-numeric value")
	ErrAuthRequired   = errors.New("mc: authentication required")
	ErrUnknownCommand = errors.New("mc: unknown command")
	ErrOutOfMemory    = errors.New("mc: out of memory")
)

Errors

Functions

This section is empty.

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

func Dial

func Dial(nett, addr string) (*Conn, error)

func (*Conn) Auth

func (cn *Conn) Auth(user, pass string) error

func (*Conn) Close

func (cn *Conn) Close() error

func (*Conn) Decr

func (cn *Conn) Decr(key string, delta, init, exp int) (n, cas int, err error)

func (*Conn) Del

func (cn *Conn) Del(key string) error

func (*Conn) Get

func (cn *Conn) Get(key string) (val string, cas int, flags uint32, err error)

func (*Conn) Incr

func (cn *Conn) Incr(key string, delta, init, exp int) (n, cas int, err error)

func (*Conn) Set

func (cn *Conn) Set(key, val string, ocas, flags, exp int) error

Jump to

Keyboard shortcuts

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