Redis Integration Spring Summary

Source: Internet
Author: User

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: 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: 93.Spring Data Redis Introduction website: 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></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= "" > +<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= "" -P:host-name= "localhost" p:port= "6379" p:pool-config-ref= "Poolconfig" $p:database= "0"/> $<!--Spring-data-redis offers templates-- -<bean id= "Redistemplate"class= "" > -<property name= "ConnectionFactory" ref= "ConnectionFactory"/> the<property name= "Keyserializer" > -<beanclass= ""/>Wuyi</property> the<property name= "ValueSerializer" > -<beanclass= "" > 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

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: 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.