tporadowski / redis

Native port of Redis for Windows. Redis is an in-memory database that persists on disk. The data model is key-value, but many different kind of values are supported: Strings, Lists, Sets, Sorted Sets, Hashes, Streams, HyperLogLogs. This repository contains unofficial port of Redis to Windows.
http://redis.io
Other
8.88k stars 1.09k forks source link

ZRange is not giving scores using withscores option #129

Closed bhavnesh2211 closed 2 years ago

bhavnesh2211 commented 2 years ago

I'm trying to get range of user with there scores, but it's returning only array of user_ids.

const getLeaderboard = async (tournamentUid) => (client.ZRANGE( tournamentUid, 0, 100, 'withscores', ));

This is my snippet.

tporadowski commented 2 years ago

Could you please provide some steps to reproduce? Ideally a set of steps to be directly run via redis-cli.

bhavnesh2211 commented 2 years ago

When I try this commands it's working fine in redis-cli, but when I'm trying to get in node app. It's returning only user_id that I added using ZADD.

tporadowski commented 2 years ago

How do you access the result? ZRANGE with "WITHSCORES" returns an array as follows:

The following example using WITHSCORES shows how the command returns always an array, but this time, populated with element_1, score_1, element_2, score_2, ..., element_N, score_N.

tporadowski commented 2 years ago

@bhavnesh2211 it's a matter of your Node.js client, which I assume is redis. Please use zRangeWithScores(key, min, max) or ZRANGE_WITHSCORES(key, min, max) to get back result with scores:

obraz

bhavnesh2211 commented 2 years ago

Hey, @tporadowski Thanks for the help. Where I can find these functions means it's not given in Redis's official document or in any tutorial I have seen.

tporadowski commented 2 years ago

@bhavnesh2211 I used Visual Studio Code with some Node.js extensions - and it provided those to me in "intellisense" code completion list like this: obraz