Ioredis: range with "withscores"

Created on 10 Sep 2015  路  7Comments  路  Source: luin/ioredis

Just wanted to know how we specify extra clauses to commands in ioredis. For example, I want to call zrange/zrevrange with "withscores" (see http://redis.io/commands/zrange).

How would I go about doing that? Please let me know.

Thanks.

question

Most helpful comment

redis.zrange('foo', 0, 100, 'WITHSCORES');

All 7 comments

redis.zrange('foo', 0, 100, 'WITHSCORES');

Thanks.

Is there an easy way to dynamically add a random (unknown) number of members to sorted set in a single command? I have members in an array but only want to use a single command.

http://redis.io/commands/zadd

redis.zadd('key', score1, member1, score2, member2)
or
redis.zadd('key', [score1, member1, score2, member2])

Thanks luin

How do I use the above with same score? Something like

redis.zadd('key', score, [member1, member2, member3])

This syntax isn't support by redis natively. However, you can just use redis.zadd('key', _.flatten([member1, member2, member3].map(member => [score, member])))

Thanks. That works.

Was this page helpful?
0 / 5 - 0 ratings