Anche se @gimenete opere risposta, il modo migliore per fare quello che vuoi è quello di trasmettere gli elementi della lista come argomenti a rpush in questo modo:
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);
}));
Pro: - una singola istruzione sarà transmited Redis
Contro: - un angolo e minuscole: .apply
lancerà una RangeError: Maximum call stack size exceeded
se la lunghezza della lista argomenti passati al rpush è troppo grande (un po 'ove r 100 000 articoli per v8).
Da 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.
Si desidera scorrere gli elementi dell'array e inserirli singolarmente. Puoi scrivere un semplice ciclo 'for' o usare' Array.prototype.forEach'. – fardjad