Advertisement
Guest User

Untitled

a guest
May 25th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1.  $list = array();
  2. // hash looks like c:order(contains the data) and l:replyID(has the c:order for each reply so I can remove replies)
  3. foreach($redis->hGetAll("reply_post:".$id) as $l => $r){
  4.     if(substr($l,0,1) === "l"){continue;} // $l looks like l:203 | c:1  . And if $l has l in the first character then ignore
  5.     $list[intval(substr($l,2))] = $r; // $l is now c:x and I want x to get the right order and c:x contains reply that which is $r
  6. }
  7. ksort($list,SORT_NUMERIC); // sort the array by numeric so the replies are in right order
  8. foreach($list as $r){
  9.     $c[$c_id]["post_replies"][] = $r;
  10. }
  11.  
  12. ------------------------------------------------------------------------
  13. Or if I would use 2 redis hashes then it would look like this
  14. foreach($redis->hGetAll("reply_post_list:".$id) as $l => $r){
  15.     if($redis->hexists("reply_post".$id,"c:".$r)){
  16.         $c[$c_id]["post_replies"][] = $redis->hget("reply_post".$id,"c:".$r);
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement