1. Official download installation file redis-4.0.2 version, unzip, compile (GCC, TCL), make Test no problem, compile successfully
2. Switch to Redis directory, execute src/redis-server redis.conf &
redis.conf Content Note 2 point a) note bind 127.0.0.1 B) Turn off protected mode and allow other IP remote connections
3. Execution Src/redis-cli-h 192.168.xx.xx-p 6379
If set key value succeeds, then it is possible to connect remotely ( pay special attention to whether the firewall on the server is down ).
4 Recommended local Redis Visualizer: Redis Desktop Manager
5.springboot Connection Integration operation
@Configuration @enablecaching Public classRedisconfigextendsCachingconfigurersupport {@Bean Publickeygenerator Keygenerator () {return NewKeygenerator () {@Override Publicobject Generate (Object target, Method method, Object ... params) {StringBuilder sb=NewStringBuilder (); Sb.append (Target.getclass (). GetName ()); Sb.append (Method.getname ()); for(Object obj:params) {sb.append (obj.tostring ()); } returnsb.tostring (); } }; } @SuppressWarnings ("Rawtypes") @Bean PublicCacheManager CacheManager (redistemplate redistemplate) {Rediscachemanager RCM=NewRediscachemanager (redistemplate); returnRCM; } PublicRedistemplate<string, string>redistemplate (redisconnectionfactory redisconnectionfactory) {stringredistemplate template=Newstringredistemplate (redisconnectionfactory); Jackson2jsonredisserializer Jackson2jsonredisserializer=NewJackson2jsonredisserializer (Object.class); Objectmapper om=NewObjectmapper (); Om.setvisibility (Propertyaccessor.all, JsonAutoDetect.Visibility.ANY); Om.enabledefaulttyping (ObjectMapper.DefaultTyping.NON_FINAL); Jackson2jsonredisserializer.setobjectmapper (OM); Template.setvalueserializer (Jackson2jsonredisserializer); Template.afterpropertiesset (); returntemplate; }}
Properties File Configuration
#redis配置 # Redis Database index (default 0) spring.redis.database=0 # Redis server address Spring.redis.host= 192.168.198.xxx# Redis Server connection Port spring.redis.port=6379 # Redis Server connection password (default is empty) Spring.redis.password =# Connection pool Maximum number of connections (using negative values to indicate no limit) Spring.redis.pool.max-active=8 # Connection pool Maximum blocking wait time (with negative values for No limit) Spring.redis.pool.max-wait=-1 # maximum idle connections in the connection pool Spring.redis.pool.max-idle =8 # Minimum idle connection in connection pool spring.redis.pool.min-idle=0 # Connection time-out (ms) Spring.redis.timeout=0
Test class
@RunWith (Springjunit4classrunner.class) @SpringBootTest (Classes= Demodruidtestapplication.class) @WebAppConfiguration Public classTestredis {@AutowiredPrivatestringredistemplate stringredistemplate; @AutowiredPrivateredistemplate redistemplate; @Test Public voidTest () {Stringredistemplate.opsforvalue (). Set ("Test1", "111"); Assert.assertequals ("111", Stringredistemplate.opsforvalue (). Get ("Test1")); }}
Redis and Springboot Connection integration under CENTOS7 environment