Giter Club home page Giter Club logo

gomemcached's Introduction

gomemcached

Memcached protocol implementation for memcached server. You can use it to create a memcached server easily.

License: MIT GoDoc travis Go Report Card Coverage Status

import this lib:

go get -u github.com/rpcxio/gomemcached

And register handlers.

addr := "127.0.0.1:" + strconv.Itoa(port)
// or use unix domain socket, like:
// addr := "unix:///tmp/memcached.sock"

mockServer := NewServer(addr)

mockServer.RegisterFunc("get", DefaultGet)
mockServer.RegisterFunc("gets", DefaultGet)
mockServer.RegisterFunc("set", DefaultSet)
mockServer.RegisterFunc("delete", DefaultDelete)
mockServer.RegisterFunc("incr", DefaultIncr)
mockServer.RegisterFunc("flush_all", DefaultFlushAll)
mockServer.RegisterFunc("version", DefaultVersion)

mockServer.Start()

This project refers to the below projects:

I added more implementation and fix some issues, for example, panic on reading long value. I also add Context in handlers so that we can pass more info to handlers.

gomemcached's People

Contributors

hunts avatar smallnest avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

gomemcached's Issues

提几个bug。。

  1. delete 里面,这里应该是 key,delete 是单key的命令
    req.Keys = arr[1:]
  2. 所有的 exptime 矫正都不适当,应该要透传,如果你确实想只记录结束时间,除 1e9 也是错的。。time.Now().Unix() 单位是秒
    if req.Exptime > 0 {
    if req.Exptime <= RealtimeMaxDelta {
    req.Exptime = time.Now().Unix()/1e9 + req.Exptime
    }
    }
  3. 协议里 incr/decr 参数应该是 uint64
    req.Value, err = strconv.ParseInt(arr[2], 10, 64)

    参考 https://github.com/memcached/memcached/blob/ddee3e27a031be22f5f28c160be18fd3cb9bc63d/doc/protocol.txt#L369-L370

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.