- 
                Notifications
    
You must be signed in to change notification settings  - Fork 83
 
Use block parameter to pipeline in Redis#multi #68
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
Conversation
In preparation of Redis 5, as info message alerts.
> Pipelining commands on a Redis instance is deprecated and will be removed in Redis 5.0.0.
>
> redis.multi do
>   redis.get("key")
> end
>
> should be replaced by
>
> redis.multi do |pipeline|
>   pipeline.get("key")
> end
>
> (called from /app/vendor/bundle/ruby/2.7.0/gems/kredis-1.0.1/lib/kredis/types/proxy.rb:13:in `multi'}>
    | 
           Looks like tests are failing?  | 
    
e176a1e    to
    b2ee8e4      
    Compare
  
    | 
           Ha true! My bad. I just fixed the calls adding the key to them, now   | 
    
        
          
                lib/kredis/types/unique_list.rb
              
                Outdated
          
        
      | multi do | ||
| remove elements | ||
| multi do |pipeline| | ||
| types_to_strings(elements, typed).each { |element| pipeline.lrem key, 0, element } | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It repeats List#remove's code, but making remove accept a pipeline optional parameter looked equally unideal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Man, this is a pretty nasty API regression. Need to take a look and see what else we can come up with.
        
          
                lib/kredis/types/set.rb
              
                Outdated
          
        
      | add members | ||
| multi do |pipeline| | ||
| pipeline.del key | ||
| pipeline.sadd key, types_to_strings(members, typed) if members.flatten.any? | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to extract types_to_strings(members, typed) if members.flatten.any? into a method. It's repeated three times.
        
          
                lib/kredis/types/unique_list.rb
              
                Outdated
          
        
      | multi do | ||
| remove elements | ||
| multi do |pipeline| | ||
| types_to_strings(elements, typed).each { |element| pipeline.lrem key, 0, element } | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Man, this is a pretty nasty API regression. Need to take a look and see what else we can come up with.
87cfd29    to
    e164798      
    Compare
  
    e164798    to
    8a40c02      
    Compare
  
    | 
           Here is what I came up with: 
 We could also have an optional keyword argument on all proxied methods, that would create less objects, but could be a little inelegant as we would need to pass  class Kredis::Types::Proxy
  def method_missing(method, *args, **kwargs)
    Kredis.instrument :proxy, **log_message(method, *args, **kwargs) do
      failsafe do
        (kwargs.delete(:pipeline) || redis).public_send method, key, *args, **kwargs
      end
    end
  endLet me know if you have any other ideas!  | 
    
| 
               | 
          ||
| def remove(*members) | ||
| srem types_to_strings(members, typed) if members.flatten.any? | ||
| def remove(*members, pipeline: nil) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency
| 
           Played with this and came up with something a little simpler: #78  | 
    
| 
           Going to merge this for now. @lewispb we can take a swing at the ivar version if we determine that's a thread safe approach afterwards.  | 
    
* main: Bump version for 1.2.0 Use pipeline for migration too Ensure to pass the pipeline to super Use block parameter to pipeline in Redis#multi (rails#68) Note tested / supported versions of Redis in the Readme (rails#79) Return counter value after incrementing/decrementing Enum Bang setter (rails#82) Add reset to Cycle after_change callbacks Add example in Readme.md Support configuring custom keys via method invocation Use bundle add instead (rails#81)
This reverts commit 88b8c29.
* main: Bump version for 1.2.0 Use pipeline for migration too Ensure to pass the pipeline to super Use block parameter to pipeline in Redis#multi (rails#68) Note tested / supported versions of Redis in the Readme (rails#79) Return counter value after incrementing/decrementing Enum Bang setter (rails#82) Add reset to Cycle after_change callbacks Add example in Readme.md Support configuring custom keys via method invocation Use bundle add instead (rails#81)
* main: Coalesce "current pipeline or redis" into the redis method itself Pefer a thread_mattr_accessor over a thread local variable Delete list of keys in batch (rails#90) Use a thread-local variable for pipeline Revert "Use block parameter to pipeline in Redis#multi (rails#68)" Resolve pipelining deprecation warnings
* main: Coalesce "current pipeline or redis" into the redis method itself Pefer a thread_mattr_accessor over a thread local variable Delete list of keys in batch (rails#90) Use a thread-local variable for pipeline Revert "Use block parameter to pipeline in Redis#multi (rails#68)" Resolve pipelining deprecation warnings
* main: (21 commits) Bump version for 1.4.0 Update nokogiri for compatibility Revert "Improved version of UniqueList: OrderedSet (rails#76)" (rails#111) Add `last` to lists (rails#97) Improved version of UniqueList: OrderedSet (rails#76) Return Time objects instead of deprecated DateTime (rails#106) Fix possible deserialization of untrusted data Typecast return of Set#take (rails#105) Declare Active Model dependency (rails#107) Address LogSubscriber deprecation (rails#98) Account for time zones in DateTime serializations (rails#102) Add sample to set (rails#100) Bump version for 1.3.0 Allow Redis 5.x Add ltrim to lists Coalesce "current pipeline or redis" into the redis method itself Pefer a thread_mattr_accessor over a thread local variable Delete list of keys in batch (rails#90) Use a thread-local variable for pipeline Revert "Use block parameter to pipeline in Redis#multi (rails#68)" ...
In preparation of Redis 5, as info message alerts.
Using block parameter is compatible down to
redisgem version 3.0, current dependency toredisis defined as~> 4.2.