Commit 43e9aa1eb3a2f227d0c13b53200c43a5e53997ae
1 parent
1a1c04fff5
Exists in
master
dispose and putBack
Showing 2 changed files with 30 additions and 1 deletions Side-by-side Diff
index.js
lib/redis-util.js
... | ... | @@ -148,6 +148,25 @@ const decrement = (product, xid) => new Promise((resolve) => { |
148 | 148 | }); |
149 | 149 | exports.decrement = decrement; |
150 | 150 | |
151 | +const increment = (product, xid) => new Promise((resolve) => { | |
152 | + const keyword = composeKeyword(product); | |
153 | + | |
154 | + redisClient.incr(keyword, (err, reply) => { | |
155 | + if (err) { | |
156 | + logger.warn(`8DA99C28 ${MODULE_NAME}: Error on incrementing`, { | |
157 | + xid, product, eCode: err.code, eMessage: err.message, | |
158 | + }); | |
159 | + | |
160 | + redisClient.expire(keyword, DEFAULT_TTL); | |
161 | + | |
162 | + resolve(null); | |
163 | + return; | |
164 | + } | |
165 | + | |
166 | + resolve(reply); | |
167 | + }); | |
168 | +}); | |
169 | + | |
151 | 170 | const incrementBy = (product, val, xid) => new Promise((resolve) => { |
152 | 171 | const keyword = composeKeyword(product); |
153 | 172 | |
... | ... | @@ -187,6 +206,15 @@ const dispose = async (product, xid) => { |
187 | 206 | }; |
188 | 207 | exports.dispose = dispose; |
189 | 208 | |
209 | +const putBack = async (product, xid) => { | |
210 | + if (!await isLimited(product, xid)) { | |
211 | + return; | |
212 | + } | |
213 | + | |
214 | + await increment(product, xid); | |
215 | +}; | |
216 | +exports.putBack = putBack; | |
217 | + | |
190 | 218 | const limitedList = (xid) => new Promise((resolve, reject) => { |
191 | 219 | redisClient.smembers(LIMITED_SET_NAME, (err, reply) => { |
192 | 220 | if (err) { |