Git Product home page Git Product logo

Comments (9)

oleksiyk avatar oleksiyk commented on September 16, 2024

client.del({ key: counter.key(), bucket: 'mybucket' })

from no-riak.

thirdreplicator avatar thirdreplicator commented on September 16, 2024

Hi, I tried that but it doesn't seem to delete the counter.

$ node
> var Riak = require('no-riak')
undefined
> var client = new Riak.Client();
undefined
> var c2 = new Riak.CRDT.Counter(client, {bucket: 'counters', type: 'counters', key: 'my_first_counter'})
undefined
> c2.increment(5)
Counter {
  _value: Long { low: 0, high: 0, unsigned: false },
  updates: [ 5 ],
  dataType: 1,
  client: 
   Client {
     options: 
      { clientId: 'no-riak-client',
        connectionString: '127.0.0.1:8087',
        autoJSON: true,
        connectionTimeout: 3000,
        connectionBufSize: 262144,
        maxConnectionErrors: 3,
        maxConnectionErrorsPeriod: 60000,
        maxConnectionLifetime: 900000,
        retries: 3,
        pool: [Object],
        auth: false,
        tls: [Object] },
     servers: Pool { peers: [Object], i: 0, cw: 10, maxS: 10, gcdS: 10 },
     pool: 
      Pool {
        options: [Object],
        connections: [Object],
        waiting: [],
        lastBursted: null },
     _pinging: {} },
  params: { bucket: 'counters', type: 'counters', key: 'my_first_counter' },
  context: undefined }
> c2.load()
Promise {
  _bitField: 0,
  _fulfillmentHandler0: undefined,
  _rejectionHandler0: undefined,
  _promise0: undefined,
  _receiver0: undefined }
> c2.value().toNumber()
81
> client.del({key: c2.key(), bucket: 'counters'})
Promise {
  _bitField: 0,
  _fulfillmentHandler0: undefined,
  _rejectionHandler0: undefined,
  _promise0: undefined,
  _receiver0: undefined }
> c2.load()
Promise {
  _bitField: 0,
  _fulfillmentHandler0: undefined,
  _rejectionHandler0: undefined,
  _promise0: undefined,
  _receiver0: undefined }
> c2.value().toNumber()
81

from no-riak.

thirdreplicator avatar thirdreplicator commented on September 16, 2024

When create a new counter to load the same key, it still seems to persist.

> var c3 = new Riak.CRDT.Counter(client, {bucket: 'counters', type: 'counters', key: 'my_first_counter'})
undefined
> c3.load()
Promise {
  _bitField: 0,
  _fulfillmentHandler0: undefined,
  _rejectionHandler0: undefined,
  _promise0: undefined,
  _receiver0: undefined }
> c3.value().toNumber()
76

from no-riak.

oleksiyk avatar oleksiyk commented on September 16, 2024

As with all operations on custom type buckets you have to specify bucket type as well:

client.del({key: c2.key(), bucket: 'counters', type: 'counters'})

from no-riak.

thirdreplicator avatar thirdreplicator commented on September 16, 2024

Hi, I think that worked, because when I created a new instance of Riak.CRDT.Counter, then loaded the value, it evaluated to 0. However, if I used an existing counter, it retained the old value.

Existing counters retain the previous value for non-existing keys.

> c2.key()
'my_first_counter'
> client.del({key: c2.key(), bucket: 'counters', type: 'counters'})
Promise {
  _bitField: 0,
  _fulfillmentHandler0: undefined,
  _rejectionHandler0: undefined,
  _promise0: undefined,
  _receiver0: undefined }
> c3.value().toNumber()
76
> c3.key()
'my_first_counter'
> c3.load()
Promise {
  _bitField: 0,
  _fulfillmentHandler0: undefined,
  _rejectionHandler0: undefined,
  _promise0: undefined,
  _receiver0: undefined }
> c3.value().toNumber()
76

However if you create a new counter instance, it seems to start afresh:

> var c4 = new Riak.CRDT.Counter(client, {bucket: 'counters', type: 'counters', key: 'my_first_counter'})
undefined
> c4.load()
Promise {
  _bitField: 0,
  _fulfillmentHandler0: undefined,
  _rejectionHandler0: undefined,
  _promise0: undefined,
  _receiver0: undefined }
> c4.value().toNumber()
0

from no-riak.

oleksiyk avatar oleksiyk commented on September 16, 2024

Yes, removing a key in Riak won't remove or update existing JS objects, such as Riak.CRDT.Counter instance.

from no-riak.

thirdreplicator avatar thirdreplicator commented on September 16, 2024

from no-riak.

oleksiyk avatar oleksiyk commented on September 16, 2024

You should remove existing counters when the key is deleted and not re-use them.

from no-riak.

thirdreplicator avatar thirdreplicator commented on September 16, 2024

Okay. I will keep that in mind.

from no-riak.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.