Liking function programming

Source: Internet
Author: User

LS is not recommended to use hash to store points like data. Because there is no way to sort (if you need to.)

We are dealing with this at the moment.

You can use the Zset ordered collection for storage. Theoretically, in a zset, the amount within 10W does not have any pear. In other words, the number of people who like Weibo is less than 10W (which is impossible).

$redis->zadd("T: $tid: Liked", Time (),$uid);//$tid for your Weibo ID, $uid for your liking the UID of the person//Remove the likes of the people (support by the likes of the time to sort the OH:)): According to LSD, the value of the hash taken out of no order.$uids=$redis->zrevrange("T: $tid: Liked",$offset,$max,TRUE);//Reverse value$uids=$redis->zrange("T: $tid: Liked",$offset,$max,TRUE);//Sequential values//$offset and $max so to calculate$pagesize= -;$offset= ($page>1) ? ($page-1) *$pagesize:0;$max= ($page*$pagesize) -1;//Take out all of this at once.$total=$redis->zcard("T: $tid: Liked");$uids=$redis->zrevange("T: $tid: Liked",0,$total-1,TRUE);//Get the $uids is an array oh .//Determine if a user likes this one.$redis->zscore("T: $tid: Liked",$uid);//Cancel likes to do so$redis->zrem("T: $tid: Liked",$uid);//Bulk cancel a short period of time like this operation$redis->zremrangebyscore("T: $tid: Liked",$start _timestamp,$end _timestamp);//Such operations are much stronger than hash.

Well, PS again!!!

If you need a database such as NoSQL to store data like Weibo, you can store it like this:).

$pipe=$redis->multi(Redis::P ipeline);$pipe->set("T: $tid", Json_encode ($data))//json This format is a bit of a waste of storage. If you can think of a better format, don't use JSON, because JSON is too big: like Msgpack, it's a lot better than JSON .     ->zadd("T:scores", Time (),$tid);$pipe->exec();//pipe This kind of operation likes to explode. If your Redis supports transactions, PIPE is not an atomic operation.// take out the data if it is good to take out!!$tid=$reids->zrevrange("T:scores",0, -);$pipe=$redis->multi(Redis::P ipeline);foreach($tid  as $key=$value){$pipe->get("T: $value");}$list=$pipe->exec();//$list is your data.

PS again, Weibo reviews are similar storage methods. Just need to agree on the name of the $redis keys. Like what:
c:< reviews How id> can be associated with Weibo data:

T: $tid: Comments:scores (zset timestmap Comment ID);

It is much easier to use pipeline when you take the data.

Finally, a NoSQL database KEY must be set.

Liking function programming

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.