{"id":22275849,"url":"https://github.com/zigzagak/lua-resty-couchbase","last_synced_at":"2025-10-13T10:20:58.041Z","repository":{"id":148036397,"uuid":"112849669","full_name":"ZigzagAK/lua-resty-couchbase","owner":"ZigzagAK","description":"Nginx lua couchbase module","archived":false,"fork":false,"pushed_at":"2020-07-22T20:56:30.000Z","size":57,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-11T10:46:32.834Z","etag":null,"topics":["couchbase","lua","lua-couchbase","lua-resty-couchbase","memcached","n1ql","nginx","nginx-couchbase","nginx-module","resty"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ZigzagAK.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-12-02T14:44:08.000Z","updated_at":"2024-12-15T11:32:18.000Z","dependencies_parsed_at":"2023-05-28T06:45:24.782Z","dependency_job_id":null,"html_url":"https://github.com/ZigzagAK/lua-resty-couchbase","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ZigzagAK/lua-resty-couchbase","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZigzagAK%2Flua-resty-couchbase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZigzagAK%2Flua-resty-couchbase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZigzagAK%2Flua-resty-couchbase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZigzagAK%2Flua-resty-couchbase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZigzagAK","download_url":"https://codeload.github.com/ZigzagAK/lua-resty-couchbase/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZigzagAK%2Flua-resty-couchbase/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279014686,"owners_count":26085554,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["couchbase","lua","lua-couchbase","lua-resty-couchbase","memcached","n1ql","nginx","nginx-couchbase","nginx-module","resty"],"created_at":"2024-12-03T14:12:37.777Z","updated_at":"2025-10-13T10:20:58.023Z","avatar_url":"https://github.com/ZigzagAK.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lua-resty-couchbase\nNginx lua couchbase client (binary memcached protocol)\n\nThank's for the ideas: [Lua-couchbase](https://github.com/kolchanov/Lua-couchbase)\n\nTable of Contents\n=============\n\n* [Status](#status)\n* [Synopsis](#synopsis)\n\t* [Module](#module)\n\t* [Config](#config)\n* [Cluster API](#cluster_api)\n* [Bucket API](#bucket_api)\n* [Session API](#session_api)\n    * [noop](#noop)\n    * [close](#close)\n    * [setkeepalive](#setkeepalive)\n    * [set](#set)\n    * [setQ](#setq)\n    * [add](#add)\n    * [replace](#replace)\n    * [replaceQ](#replaceq)\n    * [get](#get)\n    * [getK](#getk)\n    * [touch](#touch)\n    * [gat](#gat)\n    * [delete](#delete)\n    * [deleteQ](#deleteq)\n    * [increment](#increment)\n    * [incrementQ](#incrementq)\n    * [decrement](#decrement)\n    * [decrementQ](#decrementq)\n    * [append](#append)\n    * [appendQ](#appendq)\n    * [prepend](#prepend)\n    * [prependQ](#prependq)\n    * [stat](#stat)\n    * [version](#version)\n    * [sasl_list](#sasl_list)\n* [Async API](#async_api)\n    * [send](#send)\n    * [receive](#receive)\n    * [batch](#receive)\n* [N1QL](#n1ql)\n\nStatus\n=====\n\nProduction ready.\n\nSynopsis\n=======\n\nModule\n-------\n```\nlocal _M = {\n  _VERSION = \"1.0\"\n}\n\nlocal couchbase = require \"resty.couchbase\"\n\n-- cluster\nlocal cluster = couchbase.cluster {\n  host = \"10.0.10.2\",\n  user = \"Administrator\",\n  password = \"Administrator\"\n}\n\n-- one bucket\nlocal bucket1 = cluster:bucket {\n  name = \"b1\",\n  password = \"1111\",\n  VBUCKETAWARE = true\n}\n\n-- second bucket\nlocal bucket2 = cluster:bucket {\n  name = \"b2\",\n  password = \"2222\",\n  VBUCKETAWARE = true\n}\n\nfunction _M.test_b1(key, value)\n  local cb = bucket1:session()\n  local r = cb:set(key, value)\n  r = cb:get(key)\n  cb:setkeepalive()\n  return r\nend\n\nfunction _M.test_b2(key, value)\n  local cb = bucket2:session()\n  local r = cb:set(key, value)\n  r = cb:get(key)\n  cb:setkeepalive()\n  return r\nend\n\nreturn _M\n\n```\n\nConfig\n------\n```\nserver {\n  listen 4444;\n  location /test_b1 {\n    content_by_lua_block {\n      local cb = require \"cb\"\n      local cjson = require \"cjson\"\n      ngx.say(cjson.encode(cb.test_b1(ngx.var.arg_key, ngx.var.arg_value)))\n    }\n  }\n  location /test_b2 {\n    content_by_lua_block {\n      local cb = require \"cb\"\n      local cjson = require \"cjson\"\n      ngx.say(cjson.encode(cb.test_b2(ngx.var.arg_key, ngx.var.arg_value)))\n    }\n  }\n}\n```\n\n\u003ca name=\"cluster_api\"\u003e\u003c/a\u003e\nCluster API\n========\ncluster\n------\n**syntax:** `cluster(opts)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nCreate the cluster object.\n\n`opts` - the table with parameters.\n\n* host - Couchbase REST API host.\n* port - Couchbase REST API port (default 8091).\n* user, password - username and password for REST api.\n* timeout - http timeout.\n\n```\nlocal couchbase = require \"resty.couchbase\"\n\nlocal cluster = couchbase.cluster {\n  host = \"10.0.10.2\",\n  user = \"Administrator\",\n  password = \"Administrator\"\n}\n```\n\n**return:** cluster object or throws the error.\n\nbucket\n------\n**syntax:** `cluster:bucket(opts)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nCreate the bucket object.\n\n```\nlocal bucket = cluster:bucket {\n  name = \"b\",\n  password = \"1111\",\n  VBUCKETAWARE = true\n}\n```\n\n`opts` - the table with parameters.\n\n* name - Couchbase BUCKET name (default: `default`).\n* password - SASL password for the bucket `name`.\n* timeout - socket timeout.\n* pool_size - bucket keepalive pool size.\n* pool_idle - bucket keepalive pool idle in sec.\n* VBUCKETAWARE: `true` or `false`.\n\n**return:** bucket object or throws the error.\n\n\u003ca name=\"bucket_api\"\u003e\u003c/a\u003e\nBucket API\n========\nsession\n------\n**syntax:** `bucket:session()`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nCreate the session object.\n\n```\nlocal bucket = bucket:session()\n```\n\n**return:** session object or throws the error.\n\n\u003ca name=\"session_api\"\u003e\u003c/a\u003e\nSession API\n========\nnoop\n------\n**syntax:** `session:noop()`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nNo operation.\n\nNoop operation over all connections in the current bucket session is used.\n\n**return:** array with couchbase responses `[{\"header\":{\"opaque\":0,\"CAS\":[0,0,0,0,0,0,0,0],\"status_code\":0,\"status\":\"No error\",\"type\":0}}]`.\n\nclose\n------\n**syntax:** `session:close()`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nClose all connections to all vbuckets in the current bucket session.\n\n**return:** none\n\nsetkeepalive\n------------\n**syntax:** `session:setkeepalive()`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nReturn all connections in the current session to keepalive bucket pool.\n\n**return:** none\n\nset\n---\n**syntax:** `session:set(key, value, expire, cas)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nSets the `value` for the `key`.\n\nOptional parameter `expire` sets the TTL for key.  \nOptional parameter `cas` must be a CAS value from the `get()` method.  \n\n**return:** `{\"header\":{\"opaque\":0,\"CAS\":[0,164,136,177,61,99,242,140],\"status_code\":0,\"status\":\"No error\",\"type\":0}}` on success (or any valid couchbase status) or throws the error.  \nStatus MUST be retrieved from the header.\n\nsetQ\n----\n**syntax:** `session:setQ(key, value, expire, cas)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nSets the `value` for the `key`.\n\nOptional parameter `expire` sets the TTL for key.  \nOptional parameter `cas` must be a CAS value from the `get()` method.  \n\nCouchbase not sent the response on setQ command.\n\n**Example:**\n```\n  local peers = {}\n\n  for i=1,n\n  do\n    local w = session:setQ(key, \"xxxxxxxxxxxxxxx\")\n    local sock, pool = unpack(w.peer)\n    peers[pool] = w.peer\n  end\n\n  -- wait responses (only errors)\n\n  for peer in pairs(peers)\n  do\n    cb:receive(peer)\n  end\n```\n\n**return:** `{\"header\":{\"opaque\":0,\"CAS\":[0,164,136,177,61,99,242,140],\"status_code\":0,\"status\":\"No error\",\"type\":0}}` on success or throws the error.\n\nadd\n---\n**syntax:** `session:add(key, value, expire)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nAdd the `key` with `value`.\n\nOptional parameter `expire` sets the TTL for key.\n\n**return:** `{\"header\":{\"opaque\":0,\"CAS\":[0,164,136,177,61,99,242,140],\"status_code\":0,\"status\":\"No error\",\"type\":0}}` on success (or any valid couchbase status) or throws the error.  \nStatus MUST be retrieved from the header.\n\naddQ\n----\n**syntax:** `session:addQ(key, value, expire)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nAdd the `key` with `value`.\n\nOptional parameter `expire` sets the TTL for key.\n\nCouchbase not sent the response on addQ command.\n\n**return:** `{\"peer\":{\"sock\":userdata,\"pool\":\"addr/bucket\"},\"header\":{\"opaque\":2142342}}` on success or throws the error.\n\nreplace\n-------\n**syntax:** `session:replace(key, value, expire, cas)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nReplace the `value` for the `key`.\n\nOptional parameter `expire` sets the TTL for key.  \nOptional parameter `cas` must be a CAS value from the `get()` method.  \n\n**return:** `{\"header\":{\"opaque\":0,\"CAS\":[0,164,137,158,82,69,97,51],\"status_code\":0,\"status\":\"No error\",\"type\":0}}` on success (or any valid couchbase status) or throws the error.\nIf key is not exists `{\"header\":{\"opaque\":0,\"CAS\":[0,0,0,0,0,0,0,0],\"status_code\":1,\"status\":\"Key not found\",\"type\":0},\"value\":\"Not found\"}`.  \nStatus MUST be retrieved from the header.\n\nreplaceQ\n--------\n**syntax:** `session:replaceQ(key, value, expire, cas)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nReplace the `value` for the `key`.\n\nOptional parameter `expire` sets the TTL for key.  \nOptional parameter `cas` must be a CAS value from the `get()` method.  \n\nCouchbase not sent the response on replaceQ command.\n\n**return:** `{\"peer\":{\"sock\":userdata,\"pool\":\"addr/bucket\"},\"header\":{\"opaque\":2142342}}` on success or throws the error.\n\nget\n---\n**syntax:** `session:get(key)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nGet value for the `key`.\n\n**return:** `{\"header\":{\"opaque\":0,\"CAS\":[0,164,133,238,116,1,16,213],\"status_code\":0,\"status\":\"No error\",\"type\":0},\"value\":\"7\"}` on success (or any valid couchbase status) or throws the error.\nIf key is not exists `{\"header\":{\"opaque\":0,\"CAS\":[0,0,0,0,0,0,0,0],\"status_code\":1,\"status\":\"Key not found\",\"type\":0},\"value\":\"Not found\"}`.  \nStatus MUST be retrieved from the header.\n\ngetK\n----\n**syntax:** `session:getK(key)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nGet value for the `key`.\n\nK-version for `get` returns the `key` as additional parameter.\n\ntouch\n-----\n**syntax:** `session:touch(key, expire)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nGet value for the `key`.\n\nOptional parameter `expire` sets the TTL for key.\n\n**return:** `{\"header\":{\"opaque\":0,\"CAS\":[0,164,140,177,69,146,148,224],\"status_code\":0,\"status\":\"No error\",\"type\":0}}` on success (or any valid couchbase status) or throws the error.\nIf key is not exists `{\"header\":{\"opaque\":0,\"CAS\":[0,0,0,0,0,0,0,0],\"status_code\":1,\"status\":\"Key not found\",\"type\":0},\"value\":\"Not found\"}`.  \nStatus MUST be retrieved from the header.\n\ngat\n---\n**syntax:** `session:gat(key, expire)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nget() + touch()\n\ndelete\n------\n**syntax:** `session:delete(delete, cas)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nDelete the `key`.\n\nOptional parameter `cas` must be a CAS value from the `get()` method.\n\n**return:** `{\"header\":{\"opaque\":0,\"CAS\":[0,164,140,177,69,146,148,224],\"status_code\":0,\"status\":\"No error\",\"type\":0}}` on success (or any valid couchbase status) or throws the error.\nIf key is not exists `{\"header\":{\"opaque\":0,\"CAS\":[0,0,0,0,0,0,0,0],\"status_code\":1,\"status\":\"Key not found\",\"type\":0},\"value\":\"Not found\"}`.  \nStatus MUST be retrieved from the header.\n\ndeleteQ\n-------\n**syntax:** `session:deleteQ(delete, cas)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nDelete the `key`.\n\nOptional parameter `cas` must be a CAS value from the `get()` method.\n\nCouchbase not sent the response on deleteQ command.\n\n**return:** `{\"peer\":{\"sock\":userdata,\"pool\":\"addr/bucket\"},\"header\":{\"opaque\":2142342}}` on success or throws the error.\n\nincrement\n---------\n**syntax:** `session:increment(key, increment, initial, expire)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nIncrement value for the `key`.\n\nOptional parameter `increment` sets the increment value.\nOptional parameter `initial` sets the initial value.\nOptional parameter `expire` sets the TTL for key.\n\n**return:** `{\"header\":{\"opaque\":0,\"CAS\":[0,164,139,76,53,235,109,100],\"status_code\":0,\"status\":\"No error\",\"type\":0},\"value\":213}` on success (or any valid couchbase status) or throws the error.\nReturns the next value.  \nStatus MUST be retrieved from the header.  \n\nincrementQ\n----------\n**syntax:** `session:incrementQ(key, increment, initial, expire)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nIncrement value for the `key`.\n\nOptional parameter `increment` sets the increment value.  \nOptional parameter `initial` sets the initial value.  \nOptional parameter `expire` sets the TTL for key.  \n\nCouchbase not sent the response on incrementQ command.\n\n**return:** `{\"peer\":{\"sock\":userdata,\"pool\":\"addr/bucket\"},\"header\":{\"opaque\":2142342}}` on success or throws the error.\nStatus MUST be retrieved from the header.\n\ndecrement\n---------\n**syntax:** `session:decrement(key, increment, initial, expire)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nDecrement value for the `key`.\n\nOptional parameter `increment` sets the decrement value.  \nOptional parameter `initial` sets the initial value.  \nOptional parameter `expire` sets the TTL for key.  \n\n**return:** `{\"header\":{\"opaque\":0,\"CAS\":[0,164,139,76,53,235,109,100],\"status_code\":0,\"status\":\"No error\",\"type\":0},\"value\":213}` on success (or any valid couchbase status) or throws the error.\nReturns the next value.  \nStatus MUST be retrieved from the header.\n\ndecrementQ\n----------\n**syntax:** `session:decrementQ(key, increment, initial, expire)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nDecrement value for the `key`.\n\nOptional parameter `increment` sets the decrement value.  \nOptional parameter `initial` sets the initial value.  \nOptional parameter `expire` sets the TTL for key.  \n\nCouchbase not sent the response on decrementQ command.\n\n**return:** `{\"peer\":{\"sock\":userdata,\"pool\":\"addr/bucket\"},\"header\":{\"opaque\":2142342}}` on success or throws the error.  \nReturns the next value.  \nStatus MUST be retrieved from the header.\n\nappend\n------\n**syntax:** `session:append(key, value, cas)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nAppend the `key` with `value`.\n\nOptional parameter `cas` must be a CAS value from the `get()` method.\n\n**return:** `{\"header\":{\"opaque\":0,\"CAS\":[0,164,136,177,61,99,242,140],\"status_code\":0,\"status\":\"No error\",\"type\":0}}` on success (or any valid couchbase status) or throws the error.  \nStatus MUST be retrieved from the header.\n\nappendQ\n-------\n**syntax:** `session:appendQ(key, value, cas)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nAppend the `key` with `value`.\n\nOptional parameter `cas` must be a CAS value from the `get()` method.\n\nCouchbase not sent the response on appendQ command.\n\n**return:** `{\"peer\":{\"sock\":userdata,\"pool\":\"addr/bucket\"},\"header\":{\"opaque\":2142342}}` on success or throws the error.\n\nprepend\n-------\n**syntax:** `session:prepend(key, value, cas)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nPrepend the `key` with `value`.\n\nOptional parameter `cas` must be a CAS value from the `get()` method.\n\n**return:** `{\"header\":{\"opaque\":0,\"CAS\":[0,164,136,177,61,99,242,140],\"status_code\":0,\"status\":\"No error\",\"type\":0}}` on success (or any valid couchbase status) or throws the error.  \nStatus MUST be retrieved from the header.\n\nprependQ\n--------\n**syntax:** `session:prependQ(key, value, cas)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nPrepend the `key` with `value`.\n\nOptional parameter `cas` must be a CAS value from the `get()` method.\n\nCouchbase not sent the response on prependQ command.\n\n**return:** `{\"peer\":{\"sock\":userdata,\"pool\":\"addr/bucket\"},\"header\":{\"opaque\":2142342}}` on success or throws the error.\n\nstat\n----\n**syntax:** `session:stat(key)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nGet couchbase different parameters.\n\nIf the `key` parameter found, then only for `key` information will be returned.\n\n**return:** `[{\"header\":{\"opaque\":0,\"CAS\":[0,0,0,0,0,0,0,0],\"status_code\":0,\"status\":\"No error\",\"type\":0},\"key\":\"ep_config_file\"}]` on success (or any valid couchbase status) or throws the error.\n\nversion\n-------\n**syntax:** `session:version()`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nGet couchbase version.\n\n**return:** `{\"header\":{\"opaque\":0,\"CAS\":[0,0,0,0,0,0,0,0],\"status_code\":0,\"status\":\"No error\",\"type\":0},\"value\":\"3.1.6\"}` on success (or any valid couchbase status) or throws the error.\n\nsasl_list\n---------\n**syntax:** `session:sasl_list()`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nGet available sasl methods.\n\n**return:** `{\"header\":{\"opaque\":0,\"CAS\":[0,0,0,0,0,0,0,0],\"status_code\":0,\"status\":\"No error\",\"type\":0},\"value\":\"CRAM-MD5 PLAIN\"}` on success (or any valid couchbase status) or throws the error.\n\n\u003ca name=\"async_api\"\u003e\u003c/a\u003e\nAsync API\n=========\nsend\n----\n**syntax:** `session:send(op, opts)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nSend request to couchbase .\n\nParameters `op` must be a constant.\n\n**Example 1:**\n```\n  local c = require \"resty.couchbase.consts\"\n\n  ...\n\n  local w = session:send(c.op_code.Set, {\n    key = 88, value = 1234567890, expire = 0\n  })\n\n  local l = session:receive(w.peer, {\n    opaque = w.header.opaque\n  })\n\n  ...\n```\n\n**Example 2:**\n```\n  local c = require \"resty.couchbase.consts\"\n\n  ...\n\n  local batch = {\n    { 77, \"1234567890\", expire = 0 },\n    { 88, \"1234567890\", expire = 0 },\n    { 99, \"1234567890\", expire = 0 }\n  }\n\n  local peers = {}\n  local opaques = {}\n\n  for _,req in ipairs(batch)\n  do\n    local key, value = unpack(req)\n    local w = session:send(c.op_code.SetQ, {\n      key = key, value = value, expire = 0\n    })\n    local peer, opaque = w.peer, w.header.opaque\n    peers[peer] = true\n    opaques[opaque] = req\n  end\n\n  -- wait responses (only errors)\n\n  for peer in pairs(peers)\n  do\n    local fails = session:receive(peer)\n    for _,fail in ipairs(fails)\n    do\n      local header, key, value = fail.header, fail.key, fail.value\n      local request = opaques[header.opaque]\n      opaques[header.opaque] = {\n        header = header, key = key, value = value, request = request\n      }\n    end\n  end\n\n  ...\n```\n\n**return:** `{\"header\":{\"opaque\":0}}` on success or throws the error.\n\nreceive\n-------\n**syntax:** `session:receive(peer, opts)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nReceive responses from couchbase.\n\nParameters `ops` is optional.\n\n`opts` is a table:\n* opaque - got from `send`.\n* limit - limit number of received messages.\n\n[Examples](#send)\n\n**return:**\n```\n{\n  {\"header\":{\"opaque\":23234234,\"CAS\":[0,234,134,218,216,1,160,113],\"status_code\":0,\"status\":\"No error\",\"type\":0},\"value\":\"1312\"},\n  {\"header\":{\"opaque\":56756756,\"CAS\":[0,222,132,248,116,1,112,212],\"status_code\":0,\"status\":\"No error\",\"type\":0},\"value\":\"1231\"},\n  {\"header\":{\"opaque\":24234234,\"CAS\":[0,121,142,278,16,12,196,211],\"status_code\":0,\"status\":\"No error\",\"type\":0},\"value\":\"4222\"}\n}\n```\n\n```\n{\n  {\"header\":{\"opaque\":23234234,\"CAS\":[0,234,134,218,216,1,160,113],\"status_code\":1,\"status\":\"Key not found\",\"type\":0},\"value\":\"Key not found\"},\n  {\"header\":{\"opaque\":56756756,\"CAS\":[0,222,132,248,116,1,112,212],\"status_code\":1,\"status\":\"Key not found\",\"type\":0},\"value\":\"Key not found\"},\n  {\"header\":{\"opaque\":24234234,\"CAS\":[0,121,142,278,16,12,196,211],\"status_code\":1,\"status\":\"Key not found\",\"type\":0},\"value\":\"Key not found\"}\n}\n```\n\non success or throws the error.\n\nbatch\n-----\n**syntax:** `session:batch(b, opts)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nBatch request to couchbase.\n\nParameter `b` is a table with single requests.\n\nParameters `ops` is optional.\n\n`opts` is a table:\n* unacked_window - unacknowledged request/response window.\n* thread_pool_size - number of concurent threads.\n\n**Example:**\n```\n  local b = {\n    { op = c.op_code.Set, opts = { key = 1, value = \"1234567890\" },\n    { op = c.op_code.Set, opts = { key = 2, value = \"1234567890\" },\n    { op = c.op_code.Set, opts = { key = 3, value = \"1234567890\" },\n    { op = c.op_code.Set, opts = { key = 4, value = \"1234567890\" },\n    { op = c.op_code.Set, opts = { key = 5, value = \"1234567890\" },\n    { op = c.op_code.Set, opts = { key = 6, value = \"1234567890\" },\n    { op = c.op_code.Set, opts = { key = 7, value = \"1234567890\" },\n    { op = c.op_code.Set, opts = { key = 8, value = \"1234567890\" },\n    { op = c.op_code.Set, opts = { key = 10, value = \"1234567890\" },\n    { op = c.op_code.Set, opts = { key = 11, value = \"1234567890\" },\n    { op = c.op_code.Set, opts = { key = 12, value = \"1234567890\" },\n    { op = c.op_code.Set, opts = { key = 13, value = \"1234567890\" },\n    { op = c.op_code.Set, opts = { key = 14, value = \"1234567890\" },\n    { op = c.op_code.Set, opts = { key = 15, value = \"1234567890\" },\n    { op = c.op_code.Set, opts = { key = 16, value = \"1234567890\" },\n    { op = c.op_code.Set, opts = { key = 17, value = \"1234567890\" },\n    { op = c.op_code.Set, opts = { key = 18, value = \"1234567890\" },\n    { op = c.op_code.Set, opts = { key = 19, value = \"1234567890\" },\n    { op = c.op_code.Set, opts = { key = 20, value = \"1234567890\" }\n  }\n\n  session:batch(b, {\n    unacked_window = 2,\n    thread_pool_size = 4\n  })\n```\n\nUpdates every item in  `b` table with `result` field.\n\n**return:** none or throws the error.\n\nN1QL\n----\n**syntax:** `session:query(statement, args, timeout_ms)`\n\n**context:** rewrite_by_lua, access_by_lua, content_by_lua, timer\n\nN1QL query.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzigzagak%2Flua-resty-couchbase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzigzagak%2Flua-resty-couchbase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzigzagak%2Flua-resty-couchbase/lists"}