GithubHelp home page GithubHelp logo

Comments (1)

comandeo avatar comandeo commented on July 18, 2024 1

Hello @exts

Thank you very much for your comment. I read the link you provided, and it turned out this is about memcached text protocol. This library is based on the "new" binary protocol, which is described here: https://github.com/memcached/memcached/wiki/BinaryProtocolRevamped

As you can see, there is no dedicated CAS command in this protocol. Instead, there is a "version" of a value, which is returned as a result of GET command. In this library is it implemented as get_with_version method. Then, you can pass this version to set method. If the passed version differs from the actual version in memcached, the client will raise BadVersionException. I think it is in accordance with the protocol description:

If the Data Version Check (CAS) is nonzero, the requested operation MUST only succeed if the item exists and has a CAS value identical to the provided value.

Therefore, I assume that if you want to implement compare and set in your application, you should do something like this:

  • using get_with_version get a key value and its version (cas token) , and store them somewhere
  • when you want to update the value, call set and pass the version among other parameters
  • check for BadVersionException; if it is thrown, do something that makes sense for your app

This library is just an a thin wrapper around memcached protocol command. Therefore, I was not sure if it was a good idea to implement some additional CAS logic there. On the other hand, some other clients (dalli, for example) implement cas method. So, it may be a good idea to provide something like this here.

from crystal-memcached.

Related Issues (12)

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.