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