From c1c4d4f7c930d559902983688ee8f0287f01f460 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Thu, 30 May 2024 13:33:15 +0200 Subject: [PATCH] docs: clarify about atomic operations --- README.md | 6 ++++++ dump.rdb | Bin 0 -> 118199 bytes examples/server/package.json | 4 ++++ package.json | 8 ++++---- test/usage.js | 26 ++++++++++++++++++++++++++ 5 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 dump.rdb diff --git a/README.md b/README.md index 4c94e4a..23ad0df 100644 --- a/README.md +++ b/README.md @@ -365,6 +365,12 @@ Originally this library was implemented using [hashes](https://redis.io/docs/dat Since we need to do that all the time, we prefer to use key/value. Also this approach allow to customize serializer/deserializer, which is JSON by default. +## Are writting operations atomic? + +No, writes operatoins are not atomic because there are very few use cases where that matters. **openkey** is designed to process a constant stream of requests, where the only thing important to control reaching the limit of each plan. + +In case you need it, you can combine **openkey** with [superlock](https://github.com/Kikobeats/superlock), check the following [example](https://github.com/microlinkhq/openkey/blob/9df977877e5066478020332bffb0c1677a5cd89e/test/usage.js#L115-L138). + # License **openkey** © [microlink.io](https://microlink.io), released under the [MIT](https://github.com/microlinkhq/openkey/blob/master/LICENSE.md) License.
diff --git a/dump.rdb b/dump.rdb new file mode 100644 index 0000000000000000000000000000000000000000..57edd1a49261041d3678f666393416f89840af91 GIT binary patch literal 118199 zcmb`wcbHvO^#**;ojWy^P6#Cg2uVob^mA??Fv(0Z!!%}6CIt{?GLxA}GAUEiAaqd# zM4BQf0*Yb*u^>g!yG~F+n!SL6{6vvv!GgjTzV{}d_uia!wjb+z=Fgeu?q{FfS9#xe zEm>55`cl)h%(tqCdV2V@C((4Ucq< z49^?hv});srK4L0dscN0*0pV(XPdS=*YxJv0e#s}mnO96>s{5=yu5B}ceu2!Zi!WB zVYzg0xvGAX^|8>(u4~-5WySFN#=1of-pXPNhkkaL`YZ3lUAkpe`{JIg?c3|K_O^yX z3)7;?Dm9h&Q8(JWX{c{~_m-CJ8;5&Zmlj&sF5P#C`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?iVSX(yh@SkJHj_Fk52*)XuVftbk=+ryLmakSGAc_yj?f{bDT`e z8sV6a%~415Io6ii0VH)?T784J&;k_T(tH`gdOi}pT!uqmJV5Q{eQ0^3fPR)w6xm+b zUGo#cqFUMy_WWDZWOxLNPODJg;^WYsE9{ixYYO3-xWh0Oq#qmQ-+=lNiH!O*vs#vM z@FS}lk-?Agq3bga9z9Zus1NdyYq486xTssUp105w2tqpEP;c-S`U^Nqe;F^M%y`sXDWlCgG_g#k zQ)JVn$s~{%MzpX?aMY2*tl=Zq=KfGk4a&0L<}I{G9j3%DtJUXt3q8>m%Cf?u8$q7% zEsC9ol&TY%^T;&3TQ5@(3g~92$McbEmC&#r0J%u2Y6BH_X zhjV2l9xwXN+qkhLiB-VIt~O+&hmS*>`owPhR7S>uaL5-HF-Os|a+!j*8}$bW zc09sIqBXSOh)+)^!G^S$cL4f+QI1|jlscQW`kKu-?76Jub zXO zm*)aQ6(GV#DCh`qOxI1pg}SzJkm8X~2Vd3oQiM zc5=%^b&;%W^lV=A{~X?l7NUWC!JCFG`sC8=O4Y)5uhz>2&Ec%8uzM36MEy~>=;o@D z_){DtR*XMoy=)S$$ITaB5>=J5q8Eqol_KeUEBf6iVm+d|QZ}t`l*!oHbcSE>;NxMz zvB*O2sn-2VzHPMW9Kb~XP%Q)chxCllo59JimQ}Wd5=Bau;J2tUEvwDv(Z+*h0bZ9n z!9C&!W;jN`D!xHbkDezIM8$gi6NTw{A6oTjREl`M1Gcj$iD%P~_Lm(HJ39CuNEM1w zOm1}fO}NHHhsuh2PDCoJiSOaKqE%s*@fN`&pTJvaJ#s6rQ!BzJ`gshb$QbtMjtUWV z9=HC{z|fc6m2uu@kr-upu5V_On5w=9z0arlTeD@w-d*;`>%JA9`O@qE4=hjRF#rGn literal 0 HcmV?d00001 diff --git a/examples/server/package.json b/examples/server/package.json index 3e41a90..9763c0b 100644 --- a/examples/server/package.json +++ b/examples/server/package.json @@ -1,5 +1,9 @@ { "scripts": { "dev": "watchexec --on-busy-update=restart --exts js,yml --clear=clear 'node index.js'" + }, + "dependencies": { + "http-body": "latest", + "send-http": "latest" } } diff --git a/package.json b/package.json index 901d275..afb7bb9 100644 --- a/package.json +++ b/package.json @@ -30,10 +30,9 @@ }, "keywords": [], "dependencies": { - "http-body": "~1.0.11", + "json-buffer": "~3.0.1", "mri": "~1.2.0", - "ms": "~2.1.3", - "send-http": "~1.0.6" + "ms": "~2.1.3" }, "devDependencies": { "@commitlint/cli": "latest", @@ -62,7 +61,8 @@ "postcss-focus": "latest", "simple-git-hooks": "latest", "standard": "latest", - "standard-version": "latest" + "standard-version": "latest", + "superlock": "latet" }, "engines": { "node": ">= 18" diff --git a/test/usage.js b/test/usage.js index 369124d..7fb0086 100644 --- a/test/usage.js +++ b/test/usage.js @@ -1,6 +1,7 @@ 'use strict' const { setTimeout } = require('timers/promises') +const { withLock } = require('superlock') const { randomUUID } = require('crypto') const Redis = require('ioredis') const test = require('ava') @@ -110,3 +111,28 @@ test(".increment # don't increment more than the limit", async t => { t.is(usage.remaining, 0) } }) + +test('.increment # handle race conditions (using superlock)', async t => { + const lock = withLock() + + const plan = await openkey.plans.create({ + id: randomUUID(), + limit: 1000, + period: '100ms' + }) + const key = await openkey.keys.create({ plan: plan.id }) + + await Promise.all( + [...Array(100).keys()].map(() => + lock(async () => { + const { pending, ...usage } = await openkey.usage.increment(key.value) + await pending + return usage + }) + ) + ) + + const usage = await openkey.usage(key.value) + t.is(usage.limit, 1000) + t.is(usage.remaining, 900) +})