This article for everyone to share the Redis implementation information has read unread status prompts the key code, hoping to give you some inspiration, the specific contents are as follows
Premise:
If there are now 2 modules to be prompted message: As long as the user has not seen the last time after the information will prompt the user with new information
Ideas are as follows:
Use the hash to store the time that the user last viewed, using SortedSet to store the time each information generated for each module
Code on:
map<string, string> datamap = new hashmap<> ();
Jedis jedis=null;
String uid= "1";//user ID
//category array
string []cagoryarray={"C1", "C2"};
try {
//connection pool get connection jedis=
//Here Gets the user's operation time set
map<string, string> Map = Jedis.hgetall ("u-key-" +uid);
if (map = = null) {
map = new hashmap<> ();
}
for (string value:cagoryarray) {
//Get last operation time under a classification
string s = map.get (value);
if (Stringutils.isblank (s)) {
//If not present, set to have new information
datamap.put (value, "1");
} else {
/ Calculates the new amount of information from the last operation time to the present number
Long Zcount = Jedis.zcount ("c-key-" +value, double.parsedouble (s), System.currenttimemillis ());
if (Zcount = null | | Zcount <= 0) {
//does not exist or is less than or equal to 0 without new information
datamap.put (value, "0");
} else {
Datamap . put (Value, "1");}}}
Finally {
if (jedis!=null) {
//return Connection
}
}
When new information is generated, add time to related modules:
Jedis jedis=null;
The C1 module has a new information
String cid= "C1";
try {
//connection pool get connection jedis=
//Add to SortedSet result weight is time millisecond
long currenttimemillis = System.currenttimemillis ();
Jedis.zadd ("c-key-" +cid, Currenttimemillis, string.valueof (Currenttimemillis));
Finally {
if (jedis!=null) {
//return Connection
}
}
When a user clicks on a module, updates the user's last time to view the module:
Jedis jedis=null;
The C1 module has a new information
String cid= "C1";
User ID
String uid= "1";
try {
//connection pool get connection jedis=
//Add to SortedSet result weight for time millisecond
jedis.hset ("u-key-" +uid, CID, string.valueof ( System.currenttimemillis ());
} Finally {
if (jedis!=null) {
//return Connection
}
}
The above is the entire content of this article, I hope to help you learn.