Comments (9)
client.del({ key: counter.key(), bucket: 'mybucket' })
from no-riak.
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.
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.
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.
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.
Yes, removing a key in Riak won't remove or update existing JS objects, such as Riak.CRDT.Counter
instance.
from no-riak.
from no-riak.
You should remove existing counters when the key is deleted and not re-use them.
from no-riak.
Okay. I will keep that in mind.
from no-riak.
Related Issues (3)
- LICENSE HOT 3
- List of Bucket Types HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from no-riak.