"use strict";(self.webpackChunkdocs_site=self.webpackChunkdocs_site||[]).push([[4424],{5928:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>d,contentTitle:()=>o,default:()=>c,frontMatter:()=>l,metadata:()=>r,toc:()=>a});const r=JSON.parse('{"id":"XXTLanControl.lua/kvdb/dict/put","title":"Write Key And Return Previous Value (LCC.kvdb.dict.put)","description":"Signature","source":"@site/i18n/en/docusaurus-plugin-content-docs/current/XXTLanControl.lua/kvdb/dict/put.md","sourceDirName":"XXTLanControl.lua/kvdb/dict","slug":"/XXTLanControl.lua/kvdb/dict/put","permalink":"/docs/en/XXTLanControl.lua/kvdb/dict/put","draft":false,"unlisted":false,"tags":[],"version":"current","sidebarPosition":20,"frontMatter":{"sidebar_position":20},"sidebar":"tutorialSidebar","previous":{"title":"Dictionary APIs","permalink":"/docs/en/XXTLanControl.lua/kvdb/dict/"},"next":{"title":"Move A Key (LCC.kvdb.dict.move_value)","permalink":"/docs/en/XXTLanControl.lua/kvdb/dict/move_value"}}');var s=t(4848),i=t(8453);const l={sidebar_position:20},o="Write Key And Return Previous Value (LCC.kvdb.dict.put)",d={},a=[{value:"Signature",id:"signature",level:2},{value:"Parameters",id:"parameters",level:2},{value:"Returns",id:"returns",level:2},{value:"Notes",id:"notes",level:2},{value:"Example",id:"example",level:2}];function u(e){const n={blockquote:"blockquote",br:"br",code:"code",h1:"h1",h2:"h2",header:"header",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.header,{children:(0,s.jsx)(n.h1,{id:"write-key-and-return-previous-value-lcckvdbdictput",children:"Write Key And Return Previous Value (LCC.kvdb.dict.put)"})}),"\n",(0,s.jsx)(n.h2,{id:"signature",children:"Signature"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-lua",children:"old_value, err = LCC.kvdb.dict.put(name, key, value, timeout?)\n"})}),"\n",(0,s.jsx)(n.h2,{id:"parameters",children:"Parameters"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["name",(0,s.jsx)(n.br,{}),"\n","String. Dictionary name (non-empty, max ",(0,s.jsx)(n.code,{children:"256"})," bytes)."]}),"\n",(0,s.jsxs)(n.li,{children:["key",(0,s.jsx)(n.br,{}),"\n","String. Key (must be valid UTF-8 and non-empty)."]}),"\n",(0,s.jsxs)(n.li,{children:["value",(0,s.jsx)(n.br,{}),"\n","String. New value (must be valid UTF-8)."]}),"\n",(0,s.jsxs)(n.li,{children:["timeout",(0,s.jsx)(n.br,{}),"\n","Number, optional. Request timeout in seconds, default ",(0,s.jsx)(n.code,{children:"60"}),"."]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"returns",children:"Returns"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["old_value",(0,s.jsx)(n.br,{}),"\n","String or ",(0,s.jsx)(n.code,{children:"nil"}),". Previous value when the key existed; ",(0,s.jsx)(n.code,{children:"nil"})," for new keys."]}),"\n",(0,s.jsxs)(n.li,{children:["err",(0,s.jsx)(n.br,{}),"\n","String or ",(0,s.jsx)(n.code,{children:"nil"}),". ",(0,s.jsx)(n.code,{children:"nil"})," on success; contains the error message when the request fails."]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"notes",children:"Notes"}),"\n",(0,s.jsxs)(n.blockquote,{children:["\n",(0,s.jsxs)(n.p,{children:['Writes a key and atomically returns its previous value\u2014useful for "set-and-get-old" operations.',(0,s.jsx)(n.br,{}),"\n","When the request fails, the function returns ",(0,s.jsx)(n.code,{children:"false"})," followed by the error message."]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"example",children:"Example"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-lua",children:'local old, err = LCC.kvdb.dict.put("settings", "retry", "3")\nif old == false then\n    error(err)\nend\n'})})]})}function c(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(u,{...e})}):u(e)}},8453:(e,n,t)=>{t.d(n,{R:()=>l,x:()=>o});var r=t(6540);const s={},i=r.createContext(s);function l(e){const n=r.useContext(i);return r.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:l(e.components),r.createElement(i.Provider,{value:n},e.children)}}}]);