MCPcopy
hub / github.com/redis/node-redis / transaction

Function transaction

examples/transaction-with-watch.js:18–40  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16const pool = await client.createPool();
17
18async function transaction() {
19 try {
20 await pool.execute(async (isolatedClient) => {
21 await isolatedClient.watch('paymentId:1259');
22 const multi = isolatedClient
23 .multi()
24 .set('paymentId:1259', 'Payment Successfully Completed!')
25 .set('paymentId:1260', 'Refund Processed Successfully!');
26 await delay(5000); // Do some changes to the watched key during this time...
27 await multi.exec();
28 console.log('Transaction completed Successfully!');
29 client.quit();
30 });
31 } catch (error) {
32 if (error instanceof WatchError) {
33 console.log('Transaction Failed Due To Concurrent Modification!');
34 fn();
35 } else {
36 console.log(`Error: ${error}`);
37 client.quit();
38 }
39 }
40}
41
42transaction();

Callers 1

Calls 7

multiMethod · 0.80
logMethod · 0.80
delayFunction · 0.70
executeMethod · 0.45
setMethod · 0.45
execMethod · 0.45
quitMethod · 0.45

Tested by

no test coverage detected