0

participants I use REDIS database and use PHP client http://rediska.geometria-lab.net/documentation/ Here i found type Sorted sets and try create users list for current user. My code is:

$sortedSet = new Rediska_Key_SortedSet('userslist'); // use collaction userslist
        $sortedSet[1] = array('name' => 'Max');
        $sortedSet[1] = array('name' => 'Vasile');

As I understand userslist indicates the name of the collection, and the number 1 in $ sortedSet [1] key. Then, in the console through the client redis-cli write:

127.0.0.1:6379> SMEMBERS 1: userslist 
(empty list or set) 
and get a empty blank ... prompt, what am I doing wrong? May be my concept is wrong?

2 Answers 2

2

The sorted set commands is prefixed with Z.

http://redis.io/commands#sorted_set

Try:

ZRANGE userslist 0 -1
Sign up to request clarification or add additional context in comments.

Comments

0

SMEMBERS is set not SORTED SETS for sorted sets USE ZSETS

 ZADD myzset 3 "two"
 ZRANGE myzset 0 -1 WITHSCORES

ZADD expects 3 parameters key, score and member, You are not providing it in your code

ZADD myzset 1 "one"
ZADD myzset 1 "uno"

You will have to use ZRANGE to get the range from sorted sets

ZRANGE myzset 0 -1   // This will give all values in SETS

I do not know how the PHP library works but it seems you have overwriting the members

$sortedSet[1] = array('name' => 'Max');
$sortedSet[1] = array('name' => 'Vasile');

Use Monitor command on redis-cli it will help you to analyze which command redis is processing. So start redis-cli and type monitor and then run your script and check in redis-cli which command it is firing

redis-cli monitor

TIP: Try not to write any code until you understand how things works. E.g. In this case try to understand the difference between SETS and ZSETS

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.