From e88faf6e24a0d745b9c35613a136518dad3895d3 Mon Sep 17 00:00:00 2001 From: Amit Levy Date: Fri, 25 Sep 2020 10:47:43 -0400 Subject: [PATCH] Use simpler wrap logic to maximize range --- lib/memjs/memjs.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/memjs/memjs.js b/lib/memjs/memjs.js index c5f1cd4..1832293 100644 --- a/lib/memjs/memjs.js +++ b/lib/memjs/memjs.js @@ -798,13 +798,12 @@ Client.prototype.perform = function(key, request, seq, callback, retries) { // Increment the seq value Client.prototype.incrSeq = function() { - // Prevent seq from being larger than 2^31 - // so that range errors do not occur. In event - // this occurs we simply roll over the value. - if (this.seq > Math.pow(2,31)) { + // Wrap `this.seq` to 32-bits since the field we fit it into is only 32-bits. + if (this.seq == 0xffffffff) { this.seq = 0; + } else { + this.seq++; } - this.seq++; }; exports.Client = Client;