- 
                Notifications
    
You must be signed in to change notification settings  - Fork 1.9k
 
Adding send_command_buf function sending reply as Buffers instead of Strings #1047
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
| 
           The general idea is fine, but I would not add a new function, but instead add a new parameter to the already existing function and more important: add a buffer function for each command. It won't work though as it's currently suggested. The function would have to make sure that the parser returns buffers from that point on without changing the results of any other call no matter what option is set. And using a try catch block around send_command destroys the purpose of the parameter validation.  | 
    
          
 I don't use try catch, I use try finally. 
 Calling command not added to node_redis yet will be uncomfortably because parameters will be too difficult. If you mean internal_send_command only then it's OK (and of course wrapper function can be also added). 
 I think great idea. And delete uppercase commands. If somebody use them he can just copy them by himself. Or you just can add Redis.createUpperCaseCommands() function that will copy all commands. Actually you can also add Redis.createBufferCommands() function. If need I can implement them. 
 Sorry, I didn't understand (I guess my English is bad). «It won't work» — my function (send_command_buf)? «without changing the results of any other call» — my function doesn't change other calls replies.  | 
    
          
 True indeed, that works and my comment should be ignored. One thing about the try finally though: it might be worth thinking about not having any rescue plan in case of a misuse. The only way how this would not end up in a crash is by listening for unhandled exceptions and in that case the app should at least restart and recovering is not intended. 
 I agree that it's uncomfortable for users, so yes it should only be used for internal_send_command (using a new state can be prevented therefore). 
 I'm +1 on removing the uppercase commands. That's already plannend, but this can only happen in the next major version. Adding the extra functions is not necessary in that case, as any user can just write an alias for the original to use it as uppercase command. 
 It's not about your function changing another call directly. But the default return value of node_redis is of type String. In that case, the parser setting has to be changed to return buffers. And then the handle_detect_buffers_reply has to be set as function for  const Redis = require('redis')
const assert = require('assert')
const client = Redis.createClient()
assert(!client.buffers) // Default is to return strings, therefore buffers is false
client.set('foo', 'bar')
// This has to trigger setting `client.buffers` to true and to reset the parser to return buffers
client.getBuffer('foo', function (err, res) {
  assert.strictEqual(res.inspect(), '<Buffer 62 61 72>')
})
// This has to keep on working even though the parser returns buffers
client.get('foo', function (err, res) {
  assert.strictEqual(res, 'bar')
}) | 
    
5cfff6a    to
    03a6922      
    Compare
  
    03a6922    to
    a1755b9      
    Compare
  
    | 
           Features: 
 Code changing: 
 
 I added parameter because it's easy for "b_" prefixed commands but send_command_buf still using this.cur_command_ret_buf because if some command overwritten then it must work without changing code (see comments in send_command_buf). Also I think detect_buffers option should be deprecated.  | 
    
51b82cf    to
    bdf86be      
    Compare
  
    | 
           Now it supports multi and batch. Also I have added tests.  | 
    
e07575b    to
    532a395      
    Compare
  
    | 
           Now it supports individual commands (including multi individual commands). @BridgeAR, there is no tests for individual commands but I can add if you say this PR can be merged.  | 
    
9040d1a    to
    f4b18ea      
    Compare
  
    | 
           I refactored passing the command_obj to be created in a earlier stage in #1074. If you rebase, this should allow to simplify some of the code.  | 
    
| 
           How to rebase?  | 
    
b4b0bde    to
    536f88e      
    Compare
  
    | 
           I just released v.2.6 and you can rebase to the master instead of the other branch. Just write something like: You'll get all the commits from the master and can rebase your against them to solve the issues individually. This is nicer than using a merge. And when you're done you can push your changed history to this branch.  | 
    
8530504    to
    136f43b      
    Compare
  
    136f43b    to
    60f8ee4      
    Compare
  
    | 
           rebased and improved tests  | 
    
e219a08    to
    8c8af87      
    Compare
  
    2b29875    to
    e06cbf9      
    Compare
  
    e06cbf9    to
    8077cb2      
    Compare
  
    | 
           @BridgeAR, what about merge?  | 
    
| 
           is the project alive?  | 
    
| 
           @vitaliylag Yep. Although I haven't seen Ruben around in a while. I'm assuming this commit is no longer valid, right? It's 18 months old. Any particular way you'd like to help out?  | 
    
| 
           I didn't see any major changes last 18 months so I guess nobody maintain the project. 
 So the project is not alive I guess... :) 
 No. If I were offered to become second admin I would accept it to merge my pull requests without any problems (in my server I use version with promises support so it is second not published PR) but I wouldn't maintain the project.  | 
    
| 
           I am going to look into this at some point soonish. I am aware that I did not invest enough time in here but I will get to that soon again and finally get some stuff moving again.  | 
    
Adding send_command_buf function. The same as send_command but reply will be sent to callbacks as Buffers instead of Strings.