Adds transaction with watched key example script.#2297
Conversation
| * Use meaningful example data, let's not use `foo`, `bar`, `baz` etc! | ||
| * Leave an empty line at the end of your `.js` file | ||
| * Update this `README.md` file to add your example to the table | ||
| - Add your code in a single JavaScript or TypeScript file per example, directly in the `examples` folder |
There was a problem hiding this comment.
Is there any reason to change anything in this README.md at all except for adding a new line entry in the table for your new script?
There was a problem hiding this comment.
@sailingwithsandeep please see @simonprickett's question above.
There was a problem hiding this comment.
@simonprickett Hey so sorry i just realised i changed the order of readme file's coding guidelines list. it happened because i copied that readme file from previous pull request and somehow changed the order. i hope you understand my concern. Again extremely sorry for changing unwanted things. (P.S. I am so excited that i am contributing into redis community so, given that state i might have rushed it.)
There was a problem hiding this comment.
Please don't rush @sailingwithsandeep and only change the things that are necessary :) please change it back and we will re-review.
There was a problem hiding this comment.
@simonprickett @SuzeShardlow Hey i committed the changes hopefully this time there won't be an issue. Again sorry for the trouble.
Codecov ReportBase: 95.85% // Head: 95.85% // No change to project coverage 👍
Additional details and impacted files@@ Coverage Diff @@
## master #2297 +/- ##
=======================================
Coverage 95.85% 95.85%
=======================================
Files 433 433
Lines 4002 4002
Branches 451 451
=======================================
Hits 3836 3836
Misses 102 102
Partials 64 64 Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
simonprickett
left a comment
There was a problem hiding this comment.
@sailingwithsandeep I was able to test the happy path successfully, however if there's concurrent modification of paymentId:1259 the code errors like this:
$ node transaction-with-watch.js
Transaction Failed Due To Concurrent Modification!
Error: Error: pool is draining and cannot accept work`
to reproduce this, add a delay between the watch and exec during which you change the value stored at paymentId:1259 in a redis-cli session.
I added the delay using some temporary code that allows me time to modify the key in redis-cli:
async function slowDown() {
return new Promise(resolve => setTimeout(resolve, 5000));
}
and called it like this:
const multi = isolatedClient
.multi()
.set('paymentId:1259', 'Payment Successfully Completed!')
.set('paymentId:1260', 'Refund Processed Successfully!');
await slowDown();
await multi.exec();
|
Hello @simonprickett , i have added the delay which you have mentioned in previous review! |
|
@sailingwithsandeep you still need to look at your code. The delay which @simonprickett mentioned was purely to reproduce / demonstrate the error. It isn't a fix. You still need to fix the error. Please have another read of Simon's comment: #2297 (review) and amend your PR accordingly so the error no longer occurs. |
|
Hello, @SuzeShardlow @simonprickett i have handled that pooling error please have a look! |
simonprickett
left a comment
There was a problem hiding this comment.
Thanks - both cases (concurrent modification and success) work for me, @SuzeShardlow this is good to merge.
|
Thanks for your contribution @sailingwithsandeep :) |
|
@SuzeShardlow @simonprickett Thank you! for supporting me! this was my first open source contribution. |
|
Welcome to the open source world 🙂 |
* transction example improved * readme fixed * delay added for watched key changes * pooling error fixed on recursion * Minor comment update. Co-authored-by: Ajay <ajay.markana@yudiz.com> Co-authored-by: Simon Prickett <simon@redis.com> Closes redis#2280.
My pull request is about creating an example of redis transactions which shows a sample code that runs in isolated connection and provides optimistic locking with check-and-set (CAS) behavior.
#2280
Checklist
npm testpass with this change (including linting)?