Git Product home page Git Product logo

Comments (2)

saaros avatar saaros commented on August 26, 2024

I'm not sure what would be a good, generic C interface for asynchronous operations so async mechanisms are currently left to the users to implement. It's possible to do it using omcache_command and omcache_io similar to how the Python client does it.

Also, in case you're not interested in command statuses and just want to push updates to the servers (and potentially wait for operations to complete or fail without distinguishing between the results) it's possible to just use the plain command api (omcache_set and friends) with a zero timeout and later on call omcache_io to make sure all commands were sent. This is what https://github.com/ohmu/pgmemcache/ does by default.

from omcache.

filonenko-mikhail avatar filonenko-mikhail commented on August 26, 2024

Ok, I will do.

For google indexing for people, who searches async memcached c++ interface.

struct protocol_binary_set_request_body_s {
  uint32_t flags;
  uint32_t expiration;
} __attribute__((packed));

static int async_omc_set_cmd(omcache_t *mc, protocol_binary_command opcode,
                             const unsigned char *key, size_t key_len,
                             const unsigned char *value, size_t value_len,

                             protocol_binary_set_request_body_s* expiration_and_flags,

                             uint64_t cas,

                             omcache_req_t *requests,
                             size_t *req_count,
                             omcache_value_t *values,
                             size_t *value_count,

                             int32_t timeout_msec)
{
  if (req_count == NULL || *req_count == 0)
    return OMCACHE_INVALID;

  memset(requests, 0, sizeof(*requests) * *req_count);
  if (values && value_count)
    memset(values, 0, sizeof(*values) * *value_count);


  size_t extra_len = sizeof(protocol_binary_set_request_body_s);
  if (opcode == PROTOCOL_BINARY_CMD_APPEND || opcode == PROTOCOL_BINARY_CMD_APPENDQ ||
      opcode == PROTOCOL_BINARY_CMD_PREPEND || opcode == PROTOCOL_BINARY_CMD_PREPENDQ)
    extra_len = 0;

  omcache_req_t& req = requests[0];
  req.server_index = -1;
  req.header.opcode = opcode;
  req.header.extlen = extra_len;
  req.header.keylen = htobe16(key_len);
  req.header.bodylen = htobe32(key_len + value_len + extra_len);
  req.header.cas = htobe64(cas);
  req.extra = expiration_and_flags;
  req.key = key;
  req.data = value;

  return omcache_command(mc, requests, req_count, values, value_count, timeout_msec);
}


int async_omcache_add(omcache_t *mc,
                      const unsigned char *key, size_t key_len,
                      const unsigned char *value, size_t value_len,

                      protocol_binary_set_request_body_s* expiration_and_flags,

                      omcache_req_t *requests,
                      size_t *req_count,
                      omcache_value_t *values,
                      size_t *value_count,

                      int32_t timeout_msec)
{
  return async_omc_set_cmd(mc, QCMD(PROTOCOL_BINARY_CMD_ADD),
                           key, key_len, value, value_len,
                           expiration_and_flags, 0,

                           requests,
                           req_count,
                           values,
                           value_count,

                           timeout_msec);
}

int async_omcache_delete(omcache_t *mc,
                         const unsigned char *key, size_t key_len,

                         omcache_req_t *requests,
                         size_t *req_count,
                         omcache_value_t *values,
                         size_t *value_count,
                         int32_t timeout_msec)
{
  if (req_count == NULL || *req_count == 0)
    return OMCACHE_INVALID;

  memset(requests, 0, sizeof(*requests) * *req_count);
  if (values && value_count)
    memset(values, 0, sizeof(*values) * *value_count);

  omcache_req_t *req = &requests[0];
  req->server_index = -1;
  req->header.opcode = QCMD(PROTOCOL_BINARY_CMD_DELETE);
  req->header.keylen = htobe16(key_len);
  req->header.bodylen = htobe32(key_len);
  req->key = key;
  return omcache_command(mc, requests, req_count, values, value_count, timeout_msec);
}

from omcache.

Related Issues (14)

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.