Skizit
Skizit

Reputation: 44852

Array to function parameters

I'm using the node.js Redis library and I'm attempting to bulk-subscribe to many keys. I've got an array which is dynamic i.e

var keys {'key1','key2',...,'keyN'}

and I want to feed each index in as parameters to subscribe in the Redis library which takes one or more string(s). I've tried the apply function in JS using..

redisClient.subscribe.apply(this,keys);

but it doesn't cause a subscription. Any suggestions on how I can get over this issue?

Upvotes: 0

Views: 229

Answers (1)

loganfsmyth
loganfsmyth

Reputation: 161467

Your example data is totally invalid JS, but I'm assuming you have it correct in your code. You need to set the proper function context:

redisClient.subscribe.apply(redisClient, keys);

Upvotes: 2

Related Questions