2013-04-30 37 views
1

我想在運行時定義的集合上使用zunionstore命令,它們是動態獲取的,所以我永遠不知道集合是什麼,我必須傳遞給函數。redis zunionstore動態傳遞集合

語法zunionstore的:

ZUNIONSTORE目的地numkeys鍵[鍵...] [WEIGHTS重量[重量...]] [總金額| MIN | MAX]

parsed數組包含集合的名稱。

client.zunionstore 
     (
      'out',     
      parsed.length, 
      parsed, 
      function (err, res) 
      { 
       console.log(err); 
       if(!err) 
       { 
        client.zrevrange('out', 0, -1, 'withscores', function (err, res) 
        { 
         console.log(res); 
         if(!err) 
         { 
          //do stuff 
         } 
        });       
       } 
      } 
     ); 

,你可以看到我試圖傳遞包含名稱數組但這並不工作..

錯誤我得到:

[Error: ERR syntax error] 

如何解決任何想法這個?

回答

2

你的意思是你有問題傳遞一個數組到一個函數?把所有的參數到一個數組中,並調用apply的功能:Passing an array as a function parameter in JavaScript

所以,你有你的parsed陣列,只是給它添加其他的東西像你'out'parsed.length等,並調用client.zunionstore.apply(this, array)

+0

感謝它的工作,我只需要改變上下文到客戶端而不是這:) – 2013-05-02 06:42:23