1

We have created 3 hash in redis using the REPL redis-cli in this way:

hmset redishop:items:Articulo1 artist "Martin Wessely" price 12.99 name "Handcrafted Trees Mug" 
hmset redishop:items:Articulo2 artist "Martin Wessely" price 13.99 name "Handcrafted Trees Mug"
hmset redishop:items:Articulo3 artist "Martin Wessely" price 14.99 name "Handcrafted Trees Mug"

I check the structures are created OK in redis and these are there:

hgetall redishop:items:Articulo3

Now we add the hash in a set in this way:

sadd redishop:list-all redishop:items:Articulo3
sadd redishop:list-all redishop:items:Articulo2
sadd redishop:list-all redishop:items:Articulo1

Now we are playing with the command SORT:

SORT redishop:list-all BY redishop:items:*->price
SORT redishop:list-all BY redishop:items:*->price GET redishop:items:*->price
SORT redishop:list-all BY redishop:items:*->price GET # GET redishop:items:*->price

We never get results, the hash in the set are with value null and I dont understand why?

by other hand if we create the hash and set in this other way:

multi
hmset redishop:items:Articulo1 artist "Martin Wessely" price 12.99 name "Handcrafted Trees Mug" 
sadd redishop:list-all Articulo1
hmset redishop:items3:Articulo2 artist "Martin Wessely" price 13.99 name "Handcrafted Trees Mug"
sadd redishop:list-all Articulo2
hmset redishop:items3:Articulo3 artist "Martin Wessely" price 14.99 name "Handcrafted Trees Mug"
sadd redishop:list-all Articulo3
exec

In this way the command SORT works perfectly and the hash are inserted in the set, But I dont understand why in base of redis documentation:

  1. The command multi only Marks the start of a transaction block. Subsequent commands will be queued for atomic execution using EXEC.

  2. When I create the hash with the key key:key:key is indifferent if I use : or , or - and the most important in redis we are not creating a tree of structures according the documentation: https://redis.io/topics/data-types-intro

They tell you is better or a good way include : or dots, but They don tell you he is creating a structures tree. And then I dont understadn why when you add the hash in the set if type Articulo1 instead of redishop:items:Articulo1 is Ok but in the oher case is wrong???? in fact when you type hgetall Articulo1 you receive a null but When you type hgetall redishop:items:Articulo1 you get all the fels an values.. it is so much strange.

  1. exec only executes all the sentences, for these reason should be the same make it with multi or without multi.

Please Any help or explanation on the subject would be of great help. Thanks in advance.

charles
  • 361
  • 1
  • 5
  • 15

1 Answers1

2

Now we are playing with the command SORT

Beware of SORT's time complexity and memory requirements, I usually recommend against using it.

We never get results, the hash in the set are with value null and I dont understand why?

The problem lies with how you call SORT and specify the GET and BY clauses. Since your Set's members are the complete (Hash) key names, here's how you should do it with your example data:

127.0.0.1:6379> SORT redishop:list-all BY *->price
1) "redishop:items:Articulo1"
2) "redishop:items:Articulo2"
3) "redishop:items:Articulo3"
127.0.0.1:6379> SORT redishop:list-all BY *->price GET *->price
1) "12.99"
2) "13.99"
3) "14.99"

In this way the command SORT works perfectly

In this case you're populating the Set with only the "id" part of the key names, so the GET and BY clauses map to actual data. To clarify, this has nothing to do with the use (or lack) of MULTI blocks.

Itamar Haber
  • 47,336
  • 7
  • 91
  • 117
  • I continue without understand, sorry. – charles Nov 05 '17 at 15:22
  • furthemore and most important, Why If I insert in the set the hash between block multi I can refer it with the last id of my key and the SORT work as I want but if I make the same out of multi I can not do the same? I am sorry but I dont understand look like a bug in the tool. – charles Nov 05 '17 at 15:30
  • What happen if the same set I have a hash with key redishop:item:cars and other with redishop:itemsBig:truck and I want the price of trucks. Dont can I do it? Maybe in the documentation any reference I dont think so...... Because the most strange is that if I do the same but between multi block and making reference to the last id of my key, later I can use SORT as I want. – charles Nov 05 '17 at 15:34
  • But if I try to do the same out of multi, i.e. hmset car:1 name "X" price 3000 and later make sadd mylist 1, I am adding in the set other thing different to car:1 but if I make the same thing but into blocks of multi I can do it, I dont understand why, maybe this a bug in the tool redis-cli? – charles Nov 05 '17 at 15:37
  • I'm sorry, I can't understand the question in the last comment. Perhaps try a new question that is focused on that issue and that issue only. – Itamar Haber Nov 07 '17 at 14:43