Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds transaction with watched key example script. #2297

Merged
merged 5 commits into from
Oct 19, 2022

Conversation

sailingwithsandeep
Copy link
Contributor

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

  • Does npm test pass with this change (including linting)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?

* 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sailingwithsandeep please see @simonprickett's question above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't rush @sailingwithsandeep and only change the things that are necessary :) please change it back and we will re-review.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simonprickett @SuzeShardlow Hey i committed the changes hopefully this time there won't be an issue. Again sorry for the trouble.

@codecov-commenter
Copy link

Codecov Report

Base: 95.85% // Head: 95.85% // No change to project coverage 👍

Coverage data is based on head (81738e8) compared to base (d0bfa77).
Patch has no changes to coverable lines.

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.
📢 Do you have feedback about the report comment? Let us know in this issue.

@simonprickett simonprickett changed the title transction example improved Adds transaction with watched key example script. Oct 18, 2022
Copy link
Contributor

@simonprickett simonprickett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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();

@sailingwithsandeep
Copy link
Contributor Author

Hello @simonprickett , i have added the delay which you have mentioned in previous review!

@SuzeShardlow SuzeShardlow requested review from simonprickett and removed request for simonprickett and SuzeShardlow October 19, 2022 12:05
@SuzeShardlow
Copy link
Contributor

@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.

@sailingwithsandeep
Copy link
Contributor Author

Hello, @SuzeShardlow @simonprickett i have handled that pooling error please have a look!

Copy link
Contributor

@simonprickett simonprickett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - both cases (concurrent modification and success) work for me, @SuzeShardlow this is good to merge.

@SuzeShardlow SuzeShardlow merged commit 64e982d into redis:master Oct 19, 2022
@SuzeShardlow
Copy link
Contributor

Thanks for your contribution @sailingwithsandeep :)

@sailingwithsandeep
Copy link
Contributor Author

@SuzeShardlow @simonprickett Thank you! for supporting me! this was my first open source contribution.

@SuzeShardlow
Copy link
Contributor

Welcome to the open source world 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants