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

Return counter value after incrementing/decrementing #72

Merged

Conversation

pbstriker38
Copy link
Contributor

  • Redis multi return an array with the responses of each command that
    was run. Use [-1] to get the last value of the array and return it.

closes: #62

- Redis multi return an array with the responses of each command that
 was run. Use [-1] to get the last value of the array and return it.
@pbstriker38
Copy link
Contributor Author

I wasn't sure if we wanted to go for readability or performance. I can switch this to use .last if it's more clear.

response = [false, 4]
Benchmark.ips do |x|
  x.report("[1]")  { response[1] }
  x.report("[-1]")  { response[-1] }
  x.report("last") { response.last }
  x.compare!
end
Warming up --------------------------------------
                 [1]     2.138M i/100ms          
                [-1]     2.058M i/100ms          
                last     1.857M i/100ms          
Calculating -------------------------------------
                 [1]     21.546M (± 2.6%) i/s -    109.040M in   5.064581s
                [-1]     21.314M (± 2.2%) i/s -    107.028M in   5.024219s
                last     18.051M (± 5.1%) i/s -     90.974M in   5.054999s
                                                 
Comparison:                                      
                 [1]: 21546133.6 i/s
                [-1]: 21313633.8 i/s - same-ish: difference falls within error
                last: 18050678.0 i/s - 1.19x  (± 0.00) slower

Copy link
Member

@jeremy jeremy left a comment

Choose a reason for hiding this comment

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

#last does read better, but this works. Thanks @pbstriker38!

@jeremy jeremy merged commit 2beb74f into rails:main Apr 25, 2022
@pbstriker38 pbstriker38 deleted the change_counter_return_value_to_current_count branch April 28, 2022 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Counter increment and decrement return value
2 participants