Ask Your Question
3

How can the score value be obtained from a key name in a sorted set in Redis?

asked 2022-08-01 11:00:00 +0000

pufferfish gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-09-30 15:00:00 +0000

qstack gravatar image

In order to obtain the score value from a key name in a sorted set in Redis, you can use the ZSCORE command followed by the name of the sorted set and the key name.

The syntax for ZSCORE command is:

ZSCORE key member

For example, if you have a sorted set named "myset" with the following values:

redis> ZADD myset 10 "key1"
(integer) 1
redis> ZADD myset 20 "key2"
(integer) 1

You can obtain the score value of "key1" by using the following command:

redis> ZSCORE myset key1
"10"

This command will return the score value of "key1" which is 10.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-08-01 11:00:00 +0000

Seen: 13 times

Last updated: Sep 30 '21