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. Based on this, Redis supports sorting in a variety of different ways. As with memcached, data is cached in memory to ensure efficiency. The difference is that Redis periodically writes the updated data to disk or writes the modified operation to the appended record file, and Master-slave (Master-Slave) synchronization is implemented on this basis.
1. Cached objects must implement the serialization interface
2. When using Redis to store data, sometimes for convenience of viewing, usually there is a hierarchy or a directory, when we are set, we need to use the key value ":" Symbol to distinguish the hierarchical relationship, such as: @Cacheable (value = "Users", Key = "' User: ' + #user. UserId"), then in Redis it is the user directory
The key value is UserID.
3. Configure the Cache Manager:
@Configuration @enablecaching Public classRediscacheconfigextendsCachingconfigurersupport {@Bean Publicjedisconnectionfactory redisconnectionfactory () {jedisconnectionfactory redisconnectionfactory=Newjedisconnectionfactory (); //DefaultsRedisconnectionfactory.sethostname ("127.0.0.1"); Redisconnectionfactory.setport (6379); returnredisconnectionfactory; }
@Bean PublicRedistemplate<string, string>redistemplate (Redisconnectionfactory CF) {redistemplate<string, string> redistemplate =NewRedistemplate<string, string>(); Redistemplate.setconnectionfactory (CF); returnredistemplate; }
@Bean PublicCacheManager CacheManager (redistemplate redistemplate) {Rediscachemanager CacheManager=NewRediscachemanager (redistemplate); //set default cache expiration time by default to unlimited units: secondsCachemanager.setdefaultexpiration (60*60); returnCacheManager; }
4. Continuous update ...
Spring+redis integration problem Sets and considerations