You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/06/08 19:27:47 UTC
incubator-ignite git commit: #ignite-961: add putAll,
getAll methods to node js cache.
Repository: incubator-ignite
Updated Branches:
refs/heads/ignite-961 fb197cd35 -> 576126890
#ignite-961: add putAll, getAll methods to node js cache.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/57612689
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/57612689
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/57612689
Branch: refs/heads/ignite-961
Commit: 576126890abbe58a5dca427c03492cb37edc7b14
Parents: fb197cd
Author: ivasilinets <iv...@gridgain.com>
Authored: Mon Jun 8 20:27:37 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Mon Jun 8 20:27:37 2015 +0300
----------------------------------------------------------------------
modules/nodejs/src/main/js/cache.js | 75 ++++++++++++++++++--
.../ignite/internal/NodeJsCacheApiSelfTest.java | 7 ++
modules/nodejs/src/test/js/test-cache-api.js | 34 +++++++++
3 files changed, 111 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/57612689/modules/nodejs/src/main/js/cache.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/cache.js b/modules/nodejs/src/main/js/cache.js
index fe46406..48903fc 100644
--- a/modules/nodejs/src/main/js/cache.js
+++ b/modules/nodejs/src/main/js/cache.js
@@ -71,8 +71,9 @@ Cache.prototype.put = function(key, value, callback) {
/**
* Remove cache key
*
+ * @this {Cache}
* @param {string} key Key
- * @param {noValue} callback Called on finish
+ * @param {Cache~noValue} callback Called on finish
*/
Cache.prototype.remove = function(key, callback) {
this._server.runCommand("rmv", [this._cacheNameParam, Server.pair("key", key)], callback);
@@ -81,17 +82,81 @@ Cache.prototype.remove = function(key, callback) {
/**
* Remove cache keys
*
+ * @this {Cache}
* @param {string[]} keys Keys to remove
- * @param {noValue} callback Called on finish
+ * @param {Cache~noValue} callback Called on finish
*/
Cache.prototype.removeAll = function(keys, callback) {
var params = [this._cacheNameParam];
- for (var i = 0; i < keys.length; ++i) {
- params.push(Server.pair("k" + i, keys[i]));
- }
+ params = params.concat(Cache.concatParams("k", keys));
this._server.runCommand("rmvall", params, callback);
}
+/**
+ * Put keys to cache
+ *
+ * @this {Cache}
+ * @param {string[]} keys Keys
+ * @param {string[]} values Values
+ * @param {Cache~noValue} callback Called on finish
+ */
+Cache.prototype.putAll = function(keys, values, callback) {
+ if (keys.length !== values.length) {
+ callback.call(null, "Number of keys is not equal to number of values." +
+ "keys size=" + keys.length + ", values size=" + values.length + "].");
+
+ return;
+ }
+
+ var params = Cache.concatParams("k", keys);
+ params = params.concat(Cache.concatParams("v", values));
+
+ params.push(this._cacheNameParam);
+
+ this._server.runCommand("putall", params, callback);
+}
+
+/**
+ * Callback for cache get
+ * @callback Cache~onGetAll
+ * @param {string} error Error
+ * @param {string[]} results Result values
+ */
+
+/**
+ * Get keys from the cache
+ *
+ * @this {Cache}
+ * @param {string[]} keys Keys
+ * @param {Cache~onGetAll} callback Called on finish
+ */
+Cache.prototype.getAll = function(keys, callback) {
+ var params = Cache.concatParams("k", keys);
+
+ params.push(this._cacheNameParam);
+
+
+ console.log("PARAM GET ALL "+ params);
+
+ this._server.runCommand("getall", params, callback);
+}
+
+/**
+ * Concatenate all parameters
+ *
+ * @param {string} pref Prefix
+ * @param {string[]} keys Keys
+ * @returns List of parameters.
+ */
+Cache.concatParams = function(pref, keys) {
+ var temp = []
+
+ for (var i = 0; i < keys.length; ++i) {
+ temp.push(Server.pair(pref + i, keys[i]));
+ }
+
+ return temp;
+}
exports.Cache = Cache
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/57612689/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsCacheApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsCacheApiSelfTest.java b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsCacheApiSelfTest.java
index 2f64219..909282f 100644
--- a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsCacheApiSelfTest.java
+++ b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsCacheApiSelfTest.java
@@ -77,4 +77,11 @@ public class NodeJsCacheApiSelfTest extends NodeJsAbstractTest {
public void testRemoveAll() throws Exception {
runJsScript("testRemoveAll");
}
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPutAllGetAll() throws Exception {
+ runJsScript("testPutAllGetAll");
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/57612689/modules/nodejs/src/test/js/test-cache-api.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/js/test-cache-api.js b/modules/nodejs/src/test/js/test-cache-api.js
index c5fe1da..ec4cab5 100644
--- a/modules/nodejs/src/test/js/test-cache-api.js
+++ b/modules/nodejs/src/test/js/test-cache-api.js
@@ -43,6 +43,40 @@ testRemoveAll = function() {
TestUtils.startIgniteNode(onStart.bind(null, onPutRemoveAll, "mycache"));
}
+testPutAllGetAll = function() {
+ TestUtils.startIgniteNode(onStartGetAll.bind(null, "mycache"));
+}
+
+function onStartGetAll(cacheName, error, ignite) {
+ var cache = ignite.cache(cacheName);
+
+ var keys = ["key1", "key2"];
+
+ var values = ["val1", "val2"];
+
+ cache.putAll(keys, values, onPutAll.bind(null, cache, keys, values));
+}
+
+function onPutAll(cache, keys, values, error) {
+ assert(error == null);
+
+ cache.getAll(keys, onGetAll.bind(null, cache, keys, values));
+}
+
+function onGetAll(cache, keys, expected, error, values) {
+ console.log("error get all: " + error)
+ assert(error == null, error);
+
+ console.log("values=" + values);
+
+ for (var i = 0; i < expected.length; ++i) {
+ console.log("valuei=" + values[i]);
+ //assert(value.properties[i].value == expected[i]);
+ }
+
+ TestUtils.testDone();
+}
+
function onStart(onPut1, cacheName, error, ignite) {
var cache = ignite.cache(cacheName);