Created
February 23, 2024 20:14
-
-
Save purplecabbage/2be653383b613b31f6f81e6676e49625 to your computer and use it in GitHub Desktop.
Use aio-lib-state to increment a counter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Core, Files, State } = require('@adobe/aio-sdk') | |
async function main(params) { | |
let runCounter = { value: 0 } | |
// call state lib | |
const stateLib = await State.init() | |
try { | |
runCounter = await stateLib.get('runCounter') || { value: 0 } | |
console.log('runCounter = ', runCounter) | |
stateLib.put('runCounter', runCounter.value + 1, { ttl: 100 }) | |
} catch (e) { | |
console.log('ERROR getting state', e.message) | |
} | |
const response = { | |
statusCode: 200, | |
body: { | |
content, | |
runCounter | |
} | |
} | |
return response | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment