1 A: Introduction to Redis:2 Redis is an open source (BSD-licensed) memory data structure store that serves as a database, cache, and message broker. 3 simply put, it is a database that stores data in the form of (Key,value).4Official website: https://redis.io/download to download the corresponding version5 Second: The use of the process:61. Decompression: redis-2.4.5-win32-Win64.zip7Run the Redis-server.exe and redis-in the corresponding system version (32bit/64bit)Cli.exe file to start the service and enter the appropriate action.82. Graphical interface Jedis download URL: https://Github.com/xetorthio/jedis. 93.Spring Data Redis Introduction website: http://projects.spring.io/spring-data-redis/Ten3. 1 Introducing the associated jar package file One<dependency> A<groupId>redis.clients</groupId> -<artifactId>jedis</artifactId> -<version>2.6.2</version> the</dependency> -<dependency> -<groupId>org.apache.commons</groupId> -<artifactId>commons-pool2</artifactId> +<version>2.4.1</version> -</dependency> +<dependency> A<groupId>org.springframework.data</groupId> at<artifactId>spring-data-redis</artifactId> -<version>1.5.1.RELEASE</version> -</dependency> -3. 2 Configuring Redistemplate in Applicationcontext.xml -<!--scan Redis service class- -<context:component-scan base- Package= "Cn.itcast.redis.service"/> in<!--Spring manages Redis cache manager- -<bean id= "Rediscachemanager" to class= "Org.springframework.data.redis.cache.RedisCacheManager" > +<constructor-arg index= "0" ref= "redistemplate"/> -</bean> the<cache:annotation-driven cache-manager= "Rediscachemanager"/> *<!--Jedis Connection pool-- $<bean id= "Poolconfig"class= "Redis.clients.jedis.JedisPoolConfig" >Panax Notoginseng<property name= "Maxidle" value= "/>" -<property name= "Maxwaitmillis" value= "/>" the<property name= "Testonborrow" value= "true"/> +</bean> A<!--Jedis Connection factory-- the<bean id= "ConnectionFactory" + class= "Org.springframework.data.redis.connection.jedis.JedisConnectionFactory" -P:host-name= "localhost" p:port= "6379" p:pool-config-ref= "Poolconfig" $p:database= "0"/> $<!--Spring-data-redis offers templates-- -<bean id= "Redistemplate"class= "Org.springframework.data.redis.core.StringRedisTemplate" > -<property name= "ConnectionFactory" ref= "ConnectionFactory"/> the<property name= "Keyserializer" > -<beanclass= "Org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/>Wuyi</property> the<property name= "ValueSerializer" > -<beanclass= "Org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" > Wu</bean> -</property> About</bean> $3. 3 Send mail Save activation code 24H to Redis - //inject redistemplate<string,string> into the action class - @Autowired - PrivateRedistemplate<string,string>redistemplate; A //Generate Activation Code +String Activecode = Randomstringutils.randomnumeric (32); the //Save the Activation code to Redis and set the 24-hour expiration -Redistemplate.opsforvalue (). Set (Model.gettelephone (), Activecode, 24, $ timeunit.hours); the3. 4 Determine if the activation code is valid the //Property-Driven the PrivateString Activecode; the - Public voidSetactivecode (String activecode) { in This. Activecode =Activecode; the } the@Action ("Customer_activemail") About PublicString Activemail ()throwsIOException { the servletactioncontext.getresponse (). setContentType ( the"Text/html;charset=utf-8"); the //determine if the activation code is valid +String Activecoderedis =Redistemplate.opsforvalue (). Get ( - Model.gettelephone ()); the if(Activecoderedis = =NULL|| !activecoderedis.equals (Activecoderedis)) {Bayi //Invalid Activation Code the servletactioncontext.getresponse (). Getwriter () the. println ("Invalid activation code, please login to the system, re-bind the mailbox!") "); -}Else { - //Activation Code Valid the //Prevent Duplicate binding the //Call CRM WebService to inquire about customer information and determine if it has been bound theCustomer customer =WebClient the. Create ("Http://localhost:9002/crm_management/services" -+ "/customerservice/customer/telephone/" the+Model.gettelephone ()) the. Accept (Mediatype.application_json). Get (Customer.class); the if(Customer.gettype () = =NULL|| Customer.gettype ()! = 1) {94 //do not bind, bind the Webclient.create ( the"Http://localhost:9002/crm_management/services" the+ "/customerservice/customer/updatetype/"98+Model.gettelephone ()). get (); About servletactioncontext.getresponse (). Getwriter () -. println ("Mailbox Binding succeeded! ");101}Else {102 //has been bound.103 servletactioncontext.getresponse (). Getwriter ()104. println ("The mailbox is already bound, no need to repeat the binding! "); the }106 107 //Remove the Redis activation code108 Redistemplate.delete (Model.gettelephone ());109 } the returnNONE;111 } the3. 5 Write the server class implementation of the corresponding method (combined with WebService technology to achieve data query and operation)113Writing entity classes (@XmlRootElement)--Interfaces for service classes the(@Path & @Get/@Post/@Push/@Delete/) implement class--Dao the@Produces ({"Application/xml", "Application/json"})/ the@Consumes ({"Application/xml", "Application/json"})/117
Redis Integration Spring Summary