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));