Skip to content

Instantly share code, notes, and snippets.

@purplecabbage
Created February 23, 2024 20:14
Show Gist options
  • Save purplecabbage/2be653383b613b31f6f81e6676e49625 to your computer and use it in GitHub Desktop.
Save purplecabbage/2be653383b613b31f6f81e6676e49625 to your computer and use it in GitHub Desktop.
Use aio-lib-state to increment a counter
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