Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can sort by hash keys, without the complexity of Lua scripts, but you will have to duplicate the keys in your Json structure to Redis' hash keys.</p> <p>The below example has the following structure:</p> <p><strong>users</strong> is a set with the user id's in query.</p> <p><strong>user:X</strong> is the Redis hash which contains the duplicated <em>name</em> / <em>surname</em> data.</p> <p><strong>userdata:X</strong> is your original users Json hash.</p> <hr> <pre><code>redis&gt; hmset user:1 name First surname User OK redis&gt; set userdata:1 "{occupation: 'Tester'}" OK redis&gt; hmset user:2 name Last surname Violet OK redis&gt; set userdata:2 "{occupation: 'Bookseller'}" OK redis&gt; hmset user:3 name Middle surname Veredict OK redis&gt; set userdata:3 "{occupation: 'Judge'}" OK redis&gt; hmset user:4 name Ultimate surname Veredict OK redis&gt; set userdata:4 "{occupation: 'Ultimate Judge'}" OK redis&gt; sadd users 1 (integer) 1 redis&gt; sadd users 2 (integer) 1 redis&gt; sadd users 3 (integer) 1 redis&gt; sadd users 4 (integer) 1 redis&gt; sort users by user:*-&gt;surname get user:*-&gt;name get user:*-&gt;surname get userdata:* alpha 1) "First" 2) "User" 3) "{occupation: 'Tester'}" 4) "Middle" 5) "Veredict" 6) "{occupation: 'Judge'}" 7) "Ultimate" 8) "Veredict" 9) "{occupation: 'Ultimate Judge'}" 10) "Last" 11) "Violet" 12) "{occupation: 'Bookseller'}" </code></pre> <h2>Edit</h2> <p>I have overlooked that multiple <code>By</code> only consider the last clause. So you can't sort by more than one key in one command.</p> <p>Also the <code>SORT</code> command used for lexicographic ordering now requires <code>alpha</code> modifier.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload