Skip to content

Commit

Permalink
Implement all commands
Browse files Browse the repository at this point in the history
  • Loading branch information
evanhuang8 committed Mar 29, 2017
1 parent 30f5b49 commit beab2dc
Show file tree
Hide file tree
Showing 2 changed files with 373 additions and 1 deletion.
64 changes: 64 additions & 0 deletions lib/rejson.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ Rejson.prototype.objkeys = function(key, path) {
return cmd.call(this.client, key, path);
};

Rejson.prototype.objlen = function(key, path) {
var cmd = this.cmds['JSON.OBJLEN'];
return cmd.call(this.client, key, path);
};

Rejson.prototype.type = function(key, path) {
var cmd = this.cmds['JSON.TYPE'];
return cmd.call(this.client, key, path);
Expand All @@ -195,6 +200,65 @@ Rejson.prototype.numincrby = function(key, path, number) {
});
};

Rejson.prototype.nummultby = function(key, path, number) {
var cmd = this.cmds['JSON.NUMMULTBY'];
return cmd.call(this.client, key, path, number).then(function(result) {
return parseFloat(result);
});
};

Rejson.prototype.strappend = function(key, path, string) {
var cmd = this.cmds['JSON.STRAPPEND'];
return cmd.call(this.client, key, path, JSON.stringify(string));
};

Rejson.prototype.strlen = function(key, path) {
var cmd = this.cmds['JSON.STRLEN'];
return cmd.call(this.client, key, path);
};

Rejson.prototype.arrappend = function() {
var cmd = this.cmds['JSON.ARRAPPEND'];
var _arguments = Array.prototype.slice.call(arguments);
var fixed = _arguments.slice(0, 2);
var items = _.map(_arguments.slice(2), function(item) {
return JSON.stringify(item);
});
return cmd.apply(this.client, fixed.concat(items));
};

Rejson.prototype.arrindex = function(key, path, scalar) {
var cmd = this.cmds['JSON.ARRINDEX'];
return cmd.call(this.client, key, path, JSON.stringify(scalar));
};

Rejson.prototype.arrinsert = function() {
var cmd = this.cmds['JSON.ARRINSERT'];
var _arguments = Array.prototype.slice.call(arguments);
var fixed = _arguments.slice(0, 3);
var items = _.map(_arguments.slice(3), function(item) {
return JSON.stringify(item);
});
return cmd.apply(this.client, fixed.concat(items));
};

Rejson.prototype.arrlen = function(key, path) {
var cmd = this.cmds['JSON.ARRLEN'];
return cmd.call(this.client, key, path);
};

Rejson.prototype.arrpop = function(key, path, index) {
var cmd = this.cmds['JSON.ARRPOP'];
return cmd.call(this.client, key, path, index).then(function(result) {
return JSON.parse(result);
});
};

Rejson.prototype.arrtrim = function(key, path, start, end) {
var cmd = this.cmds['JSON.ARRTRIM'];
return cmd.call(this.client, key, path, start, end);
};

Rejson.prototype.execQuery = execQuery;

module.exports = Rejson;
Loading

0 comments on commit beab2dc

Please sign in to comment.