lib/command/string.js
function setrange(key, offset, value, req) {
  var val = this.getKey(key, req)
    , str = typeof val === 'string'
    , len
    , buf;
  if(val && !(val instanceof Buffer)) val = new Buffer(val);
  if(typeof val === 'number') val = new Buffer('' + val);
  if(typeof value === 'string') {
    value = new Buffer(value);
  }
  offset = parseInt(offset);
  if(!val) {
    val = new Buffer('');
  }

  // zero pad where necessary
  while(val.length < offset) {
    val = Buffer.concat([val, new Buffer([0])], val.length + 1);
  }

  // slice the buffer to offset
  if(offset < val.length) {
    val = val.slice(0, offset);
  }

  val = Buffer.concat([val, value], val.length + value.length);

  // was a string, put back as a string
  if(str) {
    val = '' + val;
    len = Buffer.byteLength(val);
  // was a buffer
  }else{
    len = val.length;
  }
  this.setKey(key, val, undefined, undefined, undefined, req);
  return len;
}
function setrange(key, offset, value, req) {
  var val = this.getKey(key, req)
    , str = typeof val === 'string'
    , len
    , buf;
  if(val && !(val instanceof Buffer)) val = new Buffer(val);
  if(typeof val === 'number') val = new Buffer('' + val);
  if(typeof value === 'string') {
    value = new Buffer(value);
  }
  offset = parseInt(offset);
  if(!val) {
    val = new Buffer('');
  }

  // zero pad where necessary
  while(val.length < offset) {
    val = Buffer.concat([val, new Buffer([0])], val.length + 1);
  }

  // slice the buffer to offset
  if(offset < val.length) {
    val = val.slice(0, offset);
  }

  val = Buffer.concat([val, value], val.length + value.length);

  // was a string, put back as a string
  if(str) {
    val = '' + val;
    len = Buffer.byteLength(val);
  // was a buffer
  }else{
    len = val.length;
  }
  this.setKey(key, val, undefined, undefined, undefined, req);
  return len;
}
function setrange ( key , offset , value , req ) { var val = this . getKey ( key , req ) , str = typeof val === 'string' , len , buf ; if ( val && ! ( val instanceof Buffer ) ) val = new Buffer ( val ) ; if ( typeof val === 'number' ) val = new Buffer ( '' + val ) ; if ( typeof value === 'string' ) { value = new Buffer ( value ) ; } offset = parseInt ( offset ) ; if ( ! val ) { val = new Buffer ( '' ) ; } // zero pad where necessary while ( val . length < offset ) { val = Buffer . concat ( [ val , new Buffer ( [ 0 ] ) ] , val . length + 1 ) ; } // slice the buffer to offset if ( offset < val . length ) { val = val . slice ( 0 , offset ) ; } val = Buffer . concat ( [ val , value ] , val . length + value . length ) ; // was a string, put back as a string if ( str ) { val = '' + val ; len = Buffer . byteLength ( val ) ; // was a buffer } else { len = val . length ; } this . setKey ( key , val , undefined , undefined , undefined , req ) ; return len ; }
Set a substring of the string stored at a key.
Set a substring of the string stored at a key .