Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Use incr operation to update hits and read new value #1

Open
jhecking opened this issue Oct 6, 2017 · 0 comments
Open

Comments

@jhecking
Copy link

jhecking commented Oct 6, 2017

You might want to consider using the incr operation to increment the "hits" bin of a record and read the new value in a single database operation:

const ops = [
  Aerospike.operations.incr('hits', 1),
  Aerospike.operations.read('hits')
]
const meta = {
  ttl: Aerospike.ttl.DONT_UPDATE
}
client.operate(key, ops, meta).then(result => {
  if (result.hits >= limit) {
    console.info('limit exceeded!')
  }
})

Setting ttl to DONT_UPDATE will prevent the record's expiry time to get updated.
The incr operation will even create a new record for you automatically if there is no record for the key yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant