Redis----Computing Friends concern relationships

Source: Internet
Author: User
Tags redis
Class friend{Public $flag = "";		#存储当前对象的标志信息 Public $redis = "";
			#redis对象成员 function __construct ($name) {$this->flag = $name;
				function Getrd () {#实例化redis对象//Instantiate Redis object and connect Redis service $this->redis = new Redis ();
				$this->redis-> Connect (' 192.168.9.38 ', 6379);
				$this->redis-> Select (9);
			return $this->redis;
				function Follow ($user) {#实现关注效果//redis object->sadd (myself, $user);
				$this->getrd ()->sadd (i key, $user);
			$this->getrd ()->sadd ("user:{$this->flag}:follow", $user); Function following () {#获得关注全部人员的信息//Get all object information of current author's concern//redis object->smember (i) return $this->GETRD (
			)->smembers ("user:{$this->flag}:follow"); function Isfollow ($user) {#判断是否关注该用户 return $this->getrd ()->sismember ("user:{$this->flag}:follow", $user)
			; function Follow_common ($user) {#获得共同关注好友信息//the current user and the specified user focus on the buddy information return $this->GETRD ()->sinter ("user:{$thi S->flag}: Follow "," user:{$user}:follow ");
			} $user 1 = new Friend (1);
			$user 1-> follow (3);
			$user 1-> follow (4);
			$user 1-> Follow (5);
			$user 1-> Follow (7);

			$user 1-> Follow (9);
			$user 2 = new Friend (2);
			$user 2-> Follow (3);
			$user 2-> follow (4);
			$user 2-> Follow (5);
			$user 2-> Follow (11);
			$user 2-> follow (100);
			
			$user 2-> Follow (130);
			echo "user1:following:";
			Print_r ($user 1->following ());
			Print_r ($user 1->isfollow (3));
			Var_dump ($user 1->isfollow (13));
 Print_r ($user 1->follow_common (2));

Related Article

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.