यहां तक कि अगर @gimenete जवाब काम करता है, तुम क्या चाहते करने के लिए सबसे अच्छा तरीका सूची तत्वों को अग्रेषित करने के रूप में तर्क तो जैसे rpush के लिए है:
var redis = require('redis'),
client = redis.createClient();
var arr = [1,2,3];
client.rpush.apply(client, ['testlist'].concat(arr));
// ... or with a callback
client.rpush.apply(client, ['testlist'].concat(arr).concat(function(err, ok){
console.log(err, ok);
}));
पेशेवरों: - एक एकल अनुदेश हो जाएगा .apply
एक RangeError: Maximum call stack size exceeded
फेंक देंगे अगर तर्क सूची rpush के लिए पारित लंबाई बहुत बड़ा है (एक छोटे से ove: - एक कोने-केस : Redis को
विपक्ष transmited v8 के लिए आर 100 000 आइटम)।
MDC से:
The consequences of applying a function with too many arguments (think more than tens of thousands of arguments) vary across engines (JavaScriptCore has hard-coded argument limit of 65536), because the limit (indeed even the nature of any excessively-large-stack behavior) is unspecified. Some engines will throw an exception. More perniciously, others will arbitrarily limit the number of arguments actually passed to the applied function.
आप सरणी तत्वों के माध्यम से पुनरावृति और उन्हें व्यक्तिगत रूप सम्मिलित करना चाहते हैं। आप लूप के लिए एक सरल 'लिख सकते हैं या' Array.prototype.forEach' का उपयोग कर सकते हैं। – fardjad