Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, there are a few things you must clear up about the solution:</p> <h3>1) The kind of data structure you will use</h3> <p>Before dealing with <code>SORT</code>, you must store the data in some Redis structure. You have plenty of options for this case. Redis native data structures are: hashes, lists, sets, sorted sets and simple key/value.</p> <p>You could use lists for this, like:</p> <pre><code>lpush mylist "User Name" username2 username1 UserName username4 username3 </code></pre> <p>Notice that you have to enclose spaces in values with double quotes.</p> <p>You could also use sets, <strong>the main difference between sets and lists is that sets only store distinct values</strong> (see the example below, in which a duplicated value is stored once):</p> <pre><code>127.0.0.1:6379&gt; sadd sample_set avalue avalue (integer) 1 127.0.0.1:6379&gt; smembers sample_set 1) "avalue" </code></pre> <p>So with sets, you would go like:</p> <pre><code>sadd myset "User Name" username2 username1 UserName username4 username3 </code></pre> <h3>2) SORT lexicographically</h3> <p>You will use <code>SORT</code>, now when you want to sort lexicographically you must use the <code>ALPHA</code> modifier:</p> <pre><code>127.0.0.1:6379&gt; sort mylist alpha 1) "User Name" 2) "UserName" 3) "username1" 4) "username2" 5) "username3" 6) "username4" </code></pre> <p>The sorted order for <code>myset</code> elements is identical.</p> <pre><code>127.0.0.1:6379&gt; sort myset alpha 1) "User Name" 2) "UserName" 3) "username1" 4) "username2" 5) "username3" 6) "username4" </code></pre> <p>So you may have noticed that the order you stated you wanted is not quite equal to the common lexicographic order: <strong>space</strong>, <strong>numbers</strong>, <strong>uppercase letters</strong>, <strong>lowercase letters</strong> which follows the <a href="http://www.asciitable.com" rel="nofollow">www.asciitable.com</a> order.</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. This table or related slice is empty.
    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