You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const client = createClient();
await client.connect();
await client.disconnect(); // After that any client.executeIsolated() is impossible
await client.connect();
The code fails with Error: pool is draining and cannot accept work error.
Full source code of the modified `transaction-with-watch.js`
import { createClient, WatchError } from 'redis';
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const client = createClient();
const client = createClient();
await client.connect();
await client.disconnect(); // After that any client.executeIsolated() is impossible
await client.connect();
function restrictFunctionCalls(fn, maxCalls) {
let count = 1;
return function (...args) {
return count++ < maxCalls ? fn(...args) : false;
};
}
const fn = restrictFunctionCalls(transaction, 4);
async function transaction() {
try {
await client.executeIsolated(async (isolatedClient) => {
await isolatedClient.watch('paymentId:1259');
const multi = isolatedClient
.multi()
.set('paymentId:1259', 'Payment Successfully Completed!')
.set('paymentId:1260', 'Refund Processed Successfully!');
await delay(5000); // Do some changes to the watched key during this time...
await multi.exec();
console.log('Transaction completed Successfully!');
client.quit();
});
} catch (error) {
if (error instanceof WatchError) {
console.log('Transaction Failed Due To Concurrent Modification!');
fn();
} else {
console.log(`Error: ${error}`);
client.quit();
}
}
}
transaction();
Node.js Version
v16.17.1
Redis Server Version
6.2.7
Node Redis Version
4.6.4
Platform
Linux
Logs
No response
The text was updated successfully, but these errors were encountered:
Description
Example code https://github.com/redis/node-redis/blob/master/examples/transaction-with-watch.js does not work if instead of
we do
The code fails with
Error: pool is draining and cannot accept work
error.Full source code of the modified `transaction-with-watch.js`
Node.js Version
v16.17.1
Redis Server Version
6.2.7
Node Redis Version
4.6.4
Platform
Linux
Logs
No response
The text was updated successfully, but these errors were encountered: