Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Looks like <a href="http://redis.io/topics/data-types#sets" rel="nofollow"><code>SETS</code></a> is an good idea (<strong>if need location uniqueness</strong>):</p> <ul> <li>UserId as key.</li> <li><a href="http://redis.io/commands/sadd" rel="nofollow"><code>SADD</code></a> for <strong>set location</strong> (require O(N) where N is the number of members to be added) </li> <li><a href="http://redis.io/commands/smembers" rel="nofollow"><code>SMEMBERS</code></a> for <strong>get all locations</strong> feature.</li> <li>Hold long, lat as some delimiter separated string or serialized value (json for example).</li> </ul> <p>PHP sample </p> <pre><code>$location = json_encode(array('long' =&gt; '...', 'lat' =&gt; '...')); $redis-&gt;sAdd('locations:' . $userId, $location); ... $redis-&gt;sAdd('locations:' . $userId, $location2); ... $redis-&gt;sAdd('locations:' . $userId, $location2); ... $userLocations = $redis-&gt;sMembers('locations:' . $userId); </code></pre> <p>You did not say this, but <strong>if do not need uniqueness</strong> of locations the <a href="http://redis.io/topics/data-types#lists" rel="nofollow"><code>LISTS</code></a> would be best choise:</p> <ul> <li><a href="http://redis.io/commands/rpush" rel="nofollow"><code>RPUSH</code></a> for <strong>set location</strong> (require O(1)) </li> <li><a href="http://redis.io/commands/lrange" rel="nofollow">LRANGE</a> for <strong>get all locations</strong> feature. </li> <li>Key and value format like in <a href="http://redis.io/topics/data-types#sets" rel="nofollow"><code>SETS</code></a> case.</li> </ul> <p>PHP sample </p> <pre><code>$location = json_encode(array('long' =&gt; '...', 'lat' =&gt; '...')); $redis-&gt;rPush('locations:' . $userId, $location); ... $redis-&gt;rPush('locations:' . $userId, $location2); ... $redis-&gt;rPush('locations:' . $userId, $location2); ... $userLocations = $redis-&gt;lRange('locations:' . $userId, 0, -1); </code></pre> <p>If user has only one location <a href="http://redis.io/commands#hash" rel="nofollow"><code>HASH</code></a> would be best choise:</p> <ul> <li>One key for all users, for example <code>locations</code></li> <li><a href="http://redis.io/commands/hset" rel="nofollow"><code>HSET</code></a> where field is your userId and value is serialized data</li> </ul> <p>PHP sample </p> <pre><code>$location = json_encode(array('long' =&gt; '...', 'lat' =&gt; '...')); $redis-&gt;hSet('locations', $userId, $location); ... $userLocation = json_decode($redis-&gt;hGet('locations', $userId)); </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. 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