Permalink
Browse files

optimized APPEND

  • Loading branch information...
1 parent 4f5e37e commit 57712ffea89365dc2c32c01be13ab9c7a73a4708 @tj committed Apr 15, 2011
Showing with 4 additions and 4 deletions.
  1. +4 −4 lib/commands/string.js
View
@@ -177,12 +177,11 @@ exports.strlen = function(client, key){
(exports.append = function(client, key, str){
var key = string(key)
- , obj = this.lookup(key)
- || { type: 'string', val: new Buffer(0) };
+ , obj = this.lookup(key);
if (obj && 'string' != obj.type) return client.typeError();
- if (Buffer.isBuffer(obj.val)) {
+ if (obj) {
var offset = obj.val.length
, len = offset + str.length
, buf = new Buffer(len);
@@ -192,7 +191,8 @@ exports.strlen = function(client, key){
this.db.data[key] = obj;
client.int(len);
} else {
- client.typeError();
+ this.db.data[key] = { type: 'string', val: str };
+ client.int(str.length);
}
}).mutates = true;

0 comments on commit 57712ff

Please sign in to comment.