<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
I was wondering if anyone had any suggestions of trying to implement a binary search tree using memcache? I know it wouldn't be a good&nbsp;candidate&nbsp;if we had multiple memcache servers, but I was thinking it might be doable if we partition the tree on 1 memcache node.&nbsp;<br><br><div>Our biggest concern at the moment is race conditions of the tree updating. I thought a binary tree might solve the problem were having and that is the following scenario:</div><div><br class="webkit-block-placeholder"></div><div>1) We have hundreds of memcache objects being created (imagine rows in a database of users visiting a site)</div><div>2) We need to have a running list of last 10 users for the hour, without duplication of a users record. So we implemented the idea of a counter:</div><div><br class="webkit-block-placeholder"></div><div>&nbsp;&nbsp;if(!memcache-&gt;get("userid:$hourofday")</div><div>&nbsp;&nbsp;{</div><div>&nbsp;&nbsp; &nbsp;$counter = memcache-&gt;set("counter",1);</div><div>&nbsp;&nbsp; &nbsp;memcache-&gt;set("counter:$counter", payload);</div><div>&nbsp;&nbsp; &nbsp;memcache-&gt;set("userid:$hourofday",1);</div><div>&nbsp;&nbsp;}<br><div contenteditable="false"><br class="webkit-block-placeholder"></div><div contenteditable="false"> <span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; ">This would create only 1 record per hour of day, increment the counter, so we could build the key list in our application to pull last 10 items for the hour. The issue we run into is what happens when the following scenario happens:</span></div><div contenteditable="false"><br class="webkit-block-placeholder"></div><div contenteditable="false"><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; ">&nbsp;&nbsp;Hour 1 - &gt; User A - Counter 1</span></div><div contenteditable="false"><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; ">&nbsp;&nbsp;Hour 2 - &gt; User A - Counter 2</span></div><div contenteditable="false">&nbsp;&nbsp;Hour 3 - &gt; User A&nbsp;- Counter 3</div><div contenteditable="false"><div contenteditable="false">&nbsp;&nbsp;Hour 4 - &gt; User A&nbsp;- Counter 4</div><div contenteditable="false">&nbsp;&nbsp;Hour 5 - &gt; User A&nbsp;- Counter 5</div><div contenteditable="false"><br class="webkit-block-placeholder"></div></div><div contenteditable="false"><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; ">In this case we would only just want to show User A one time especially since its a list of user activity. We can't store a hash and just push/pop because of race conditions (our first thought). If anyone has any ideas, I'd really appreciate it!</span></div><div contenteditable="false"><br></div><div contenteditable="false"><br class="webkit-block-placeholder"></div><div contenteditable="false"><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div>-Chris</div><br class="Apple-interchange-newline"></span> </div><br></div></body></html>