Micro-blogging function Analysis
Uniqueset class
API |
function |
Implementation Principle |
Uniqueset (client, key) |
Sets the client and key for a unique collection. |
|
Is_include (Element) |
Checks whether an element exists in a unique collection. |
Sismember |
Add (Element) |
Adds an element to a unique collection. |
Sadd |
User Class
API |
function |
Implementation Principle |
User (client) |
Sets the client to use when performing the operation. |
|
Create (name, email, password) |
Creates a new user based on the given name, mailbox, and password, returning the user's ID. |
Use Hmset to store user information and use Hset to correlate email and ID. |
Try_login (email, password) |
Try to log in with the given mailbox and password, and if successful, return information such as the ID, username, and so on. Find the user ID associated with it based on email and then take out the user data based on the ID for a password comparison. |
|
User Relations
Attention and attention relationship class
API |
function |
Implementation Principle |
Relationship (client) |
Sets the client used by the relationship class. |
|
Follow (fans, target) |
Let fans focus on target. |
Add fans to Target's fan collection and add target to the fans ' collection of followers. |
Is_following (A, B) |
Check whether a is watching B. |
Check whether A's focus collection contains B. |
Is_following_each_other (A, B) |
Check whether A and B are concerned about each other. |
Check whether A's focus collection contains B, and whether the set of concerns for B contains a. |
Get_all_following (user) |
Returns everyone who is interested in the user. |
Returns the user's entire collection of concerns. |
Get_all_fans (user) |
Returns all fans of the user. |
Returns the entire fan collection for the user. |
Common_following (A, B) |
Return A and B people of common concern. |
Calculates the set of concerns for A and B. |
Hair Micro Blog
Store Weibo and broadcast it to various timelines the implementation of the Message class
API |
function |
Implementation Principle |
Message (client) |
Set up the client. |
|
Create (author, content) |
Save a microblog and return the Weibo ID. |
Use Hmset to store information about Weibo in a hash. |
GET_BY_ID (message_id) |
Search for Weibo by ID. |
Use Hgetall to get the micro-blog information stored in the hash. |
Time Line
Store Weibo in chronological order of publication time
The program stores two timelines for each user: a custom timeline that includes tweets from the user and the people they're following, with the key named Weibo::user::id::custom_timeline. Personal timeline, containing only the user's own tweets, the key name is Weibo::user::id::p ersonal_timeline. Timeline class
API |
role |
Implementation principle |
Timeline (client) |
sets the clients. |
|
custom_push (user_id, msg_id, time) |
pushes Weibo into the user's custom timeline. The |
uses Zadd to add the microblog ID to the ordered collection that represents the custom timeline. |
personal_push (user_id, msg_id,time) |
pushes Weibo into the user's personal timeline. The |
uses Zadd to add the microblog ID to the ordered collection that represents the personal timeline. |
Broadcast (msg_id, Time, *fans_ids) |
pushes Weibo into the custom timeline for all given users. The |
iterates through all the user IDs that are passed in, performing a custom_push for each ID. |
custom_paging (user_id, N, Count) |
is calculated on a per-page count of pages, to obtain a user-customized timeline on page N of Weibo. The |
uses Zrevrange to remove the microblog ID stored in the ordered collection from new to old. |
personal_paging (user_id, N, Count) |
gets the Weibo on page N of the user's personal timeline, calculated per page Count bar. The |
uses Zrevrange to remove the microblog ID stored in the ordered collection from new to old. |
Like the Weibo blog.
Support your favorite microblogging Likemessage class implementation
API |
function |
Implementation Principle |
Likemessage (client, msg_id) |
Set up the client and the microblog to be operated on. |
|
Like (user_id) |
The user likes the microblogging site. |
Add the user ID to the collection. |
Is_liking (USER_ID) |
Check to see if the user likes the Weibo. |
Use Sismember to check if the user ID exists in the collection. |
Undo (USER_ID) |
Cancel the user's likes. |
Use Srem to remove the user ID from the collection. |
Count () |
Get the number of likes for this Weibo. |
Executes a scard on the collection. |
Get_all_liking_user () |
Back to all users who liked the microblog. |
Executes a smembers on the collection. |
Review Weibo
Discuss the content of Weibo Comment class
API |
function |
Implementation Principle |
Comment (client) |
Set up the client. |
|
Create (author, content) |
Create a comment. |
Use Hmset to store comments in a hash column. |
GET_BY_ID (comment_id) |
Gets the specified comment. |
Use Hgetall to get the hash stored comment information. |
Commentlist class
API |
function |
Implementation Principle |
Commentlist (client, message_id) |
Set up the client and the blog that was commented on. |
|
Push (COMMENT_ID) |
Add comments to your Weibo blog. |
Use the Lpush command to push the comment ID into the list. |
Count () |
Get the current number of reviews for Weibo. |
Llen |
Paging (number, count) |
Calculate the Count bar per page comment to get the comments on the Weibo number page. |
Lrange |
forward micro-blog
Quote another tweet on a Weibo blog
Change the interface of the previous tweet, instead: Create (author, content, Origin_message_id=none)