Blacklist validator solution

“This is the 17th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

1. Blacklist filter service scenario analysis

In some of the electricity system, such as the evaluation function of taobao, not anyone can evaluate, can only be purchased goods, and has a good evaluation record to evaluate approval, is a profession is bad review division, bad review division is alleged extortion businesses, this kind of bad review division was set up a blacklist in taobao, even buy the goods, and evaluation.

Second, the redIS technical scheme of blacklist validator

Blacklist filters can be used in many scenarios, such as device blacklist, IP blacklist, and user blacklist

In e-commerce system, in the case of high concurrency, filtering through query database obviously does not meet the requirements, and the general approach is to achieve the set structure of Redis.

  • Step 1: Synchronize data. First, synchronize the database data to the SET set of Redis.
  • Step 2: Query the filter and verify whether it is in the blacklist during evaluation by running the sismember command of redis.

SpringBoot+Redis blacklist validator

Step 1: Initialize data to redis cache

/** * Initializes data into redis cache */
@PostConstruct
public void init(a){
    List<Integer> blacklist=this.blacklist();
    blacklist.forEach(t->this.redisTemplate.opsForSet().add(Constants.BLACKLIST_KEY,t));
}

/** * simulate 500 blacklist */
public List<Integer> blacklist(a) {
    List<Integer> list=new ArrayList<>();
    for (int i = 0; i < 500; i++) {
        list.add(i);
    }
    return list;
}
Copy the code

Step 2: Write the blacklist validator interface

/** * Blacklist validator interface * true= blacklist * false= Not blacklist */
@GetMapping(value = "/isBlacklist")
public boolean isBlacklist(Integer userId) {
    boolean bo=false;
    try {
        // Check whether the set is blacklist.
        bo = this.redisTemplate.opsForSet().isMember(Constants.BLACKLIST_KEY,userId);
        log.info("Query result: {}", bo);
    } catch (Exception ex) {
        // The redis network timeout is not enabled
        log.error("exception:", ex);
        //TODO go to DB query
    }
    return bo;
}
Copy the code

Redis distributed cache family

  • Redis Distributed Cache (1) – Redis Installation (Linux and Docker)
  • Redis Distributed cache (ii) – RDB and AOF
  • SpringBoot integrates Mybatis-Plus,Redis and Swagger
  • Redis distributed cache (4) – SpringCache integrates redis
  • Redis Distributed Cache (5) — Common command (String)
  • Redis Distributed Cache (6) — Article read volume PV Solution (String)
  • Redis Distributed Cache (7) — Distributed Global ID Solution (String)
  • Redis Distributed Cache (8) — Highly Concurrent atomic Operations (Redis+Lua)
  • Redis Distributed Cache (9) — Hacker Anti-brush Attack Solution (String)
  • Redis Distributed Cache (10) common Commands (Hash)
  • Redis Distributed Cache (11) store Java Bean object Hash
  • Redis Distributed Cache (12) – Short Link Solution (Hash)
  • Redis Distributed Cache (13) — JD Shopping cart solution
  • Redis distributed cache (14) – distributed session inconsistency solution
  • Redis Distributed Cache (15) – a highly available user registration solution
  • Redis distributed Cache (16) – user microblogging solution
  • Redis Distributed cache (17)
  • The article continues to be updated…