Redis storage object, Entity class new Add field null pointer problem handling

Source: Internet
Author: User

Redis is a key-value storage system. Similar to memcached, it supports storing more value types, including string (string), list (linked list), set (set), Zset (sorted set-ordered collection), and hash (hash type). These data types support Push/pop, Add/remove, and intersection-set and difference sets, and richer operations, and these operations are atomic.

Generally with the cache object, through the serialization of storage, when the entity class new Add field, the object is deserialized into the new field will be empty, the problem is easy to ignore, if you do not do a good job, the line will have a lot of NULL pointer exception, in order to solve this problem, we have done some of the Redis key to do the processing.

eg. we've added a cache to an activity configuration.

Class activity{

String name;//Name

Boolean limit1;//Participation Activity limit 1

Boolean limit2;//Participation Activity limit 1

...

}

if (limit1) {

Meet the criteria:

}

Redis key; Activity_key expire Time:1hour

If we have been doing well in the formal environment for a while now, we have added a limit limit3;

Gets the limit3 of the activity in the cache to be null,

if (limit3) {//throw nullpointexecption

Meet the criteria:

}

The project may be similar to the place will be more my approach is key+version (Activity.class);

private static int version (Class clazz) {
Return Clazz.getdeclaredfields (). length;
}

By tagging the number of all field in class to add the cache, updating the attributes in the entity class will automatically replace the Redis key to avoid null pointers.

Redis storage object, Entity class new Add field null pointer problem handling

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.