Redis Integrated Ssm_redis Integrated SSM

Source: Internet
Author: User
Tags aop auth

One: Pom file:

		<dependency>
		    <groupId>redis.clients</groupId>
		    <artifactid>jedis</artifactid >
		    <version>2.9.0</version>
		</dependency>

Two: Configuration file: Spring-jedis.xml

<?xml version= "1.0" encoding= "UTF-8"?> <beans "xmlns=" xmlns: context= "Http://www.springframework.org/schema/context" xmlns:p= "http://www.springframework.org/schema/p" xmlns: aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:tx= "Http://www.springframework.org/schema/tx" xmlns:xsi= " Http://www.w3.org/2001/XMLSchema-instance "xsi:schemalocation=" Http://www.springframework.org/schema/beans http ://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http ://www.springframework.org/schema/context/spring-context-4.2.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http ://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http:// Www.springframework.org/schema/tx/spring-tx-4.2.xsd http://www.springframework.org/schema/util http:// Www.springframework.org/schema/util/spring-util-4.2.xsd "> <!--Connection pool configuration--> <bean id=" JedispooLconfig "class=" Redis.clients.jedis.JedisPoolConfig > <!--maximum number of connections--> <property name= "maxtotal" value= "30"  /> <!--maximum idle connections--> <property name= "Maxidle" value= "ten"/> <!--maximum number of connections per release--> <property Name= "Numtestsperevictionrun" value= "1024"/> <!--release the connection's scanning interval (milliseconds)--> <property name= "Timebetweenevictionr Unsmillis "value=" 30000/> <!--connection Minimum idle time--> <property name= "Minevictableidletimemillis" value= "1800000"  /> <!--The connection is free for how long, release--> <property name= "Softminevictableidletimemillis" when idle time > The value and idle connection > maximum number of idle connections Value= "10000"/> <!--the maximum number of wait milliseconds to get a connection, less than 0: block indeterminate time, Default-1--> <property name= "Maxwaitmillis" value= "1500"/&G
		T <!--check validity when getting connections, default false--> <property name= "Testonborrow" value= "true"/> <!--check for validity at idle, default false- -> <property name= "Testwhileidle" value= "true"/> <!--the connection is depleted, false is reported as abnormal, Ture is blocked until timeout, default true--> ;p Roperty Name= "blocKwhenexhausted "value=" false "/> </bean> <!--Jedis Client stand-alone version--> <bean id=" redisclient "class=".
		Clients.jedis.JedisPool "> <constructor-arg name=" host "value=" 192.168.91.143 "></constructor-arg> <constructor-arg name= "Port" value= "6379" ></constructor-arg> <constructor-arg name= "Poolconfig" ref= "Jedispoolconfig" ></constructor-arg> </bean> <!--<bean id= "Jedisclient class=" cn.sys.auth.re Discach.jedisclientsingleservice "/>--> <!--jedis cluster configuration--> <!--<bean id=" redisclient "class=" Redis . clients.jedis.JedisCluster "> <constructor-arg name=" Nodes "> <set> <bean class=" REDIS.CLIENTS.J Edis. Hostandport "> <constructor-arg name=" host "value=" 192.168.91.143 "></constructor-arg> <construc Tor-arg name= "Port" value= "7001" ></constructor-arg> </bean> <bean class= "Redis.clients.jedis.Hos" Tandport "> <construcTor-arg name= "host" value= "192.168.91.143" ></constructor-arg> <constructor-arg name= "Port" value= "7002" ></constructor-arg> </bean> <bean class= "Redis.clients.jedis.HostAndPort" > <construct Or-arg name= "host" value= "192.168.91.143" ></constructor-arg> <constructor-arg name= "Port" value= "7003" & gt;</constructor-arg> </bean> <bean class= "Redis.clients.jedis.HostAndPort" > <constructo R-arg name= "host" value= "192.168.91.143" ></constructor-arg> <constructor-arg name= "Port" value= "7004" & gt;</constructor-arg> </bean> <bean class= "Redis.clients.jedis.HostAndPort" > <constructo R-arg name= "host" value= "192.168.91.143" ></constructor-arg> <constructor-arg name= "Port" value= "7005" & gt;</constructor-arg> </bean> <bean class= "Redis.clients.jedis.HostAndPort" > <constructo R-arg name= "host" value= "192.168.91.143 "></constructor-arg> <constructor-arg name=" Port "value=" 7006 "></constructor-arg> </ bean> </set> </constructor-arg> <constructor-arg name= "Poolconfig" ref= "Jedispoolconfig" &GT;&L t;/constructor-arg> </bean> <bean id= "Jedisclientcluster" class= " Cn.sys.auth.redisCach.JedisClientSingleService "></bean>--> </beans>
Three: Web.xml

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value> Classpath*:config/spring-mybatis.xml,classpath*:config/spring-jedis.xml</param-value>
  </ Context-param>
IV: Interface and Implementation class class (Java code)
Package Cn.sys.auth.redisCach;

Public interface Jedisclient {
	string (string key);
	String set (String key, String value);
	String Hget (String hkey, string key);
	Long Hset (String hkey, String key, String value);
	Long incr (String key);
	Long expire (String key, int second);
	Long TTL (String key);
	Long del (String key);
	Long Hdel (String hkey, string key);

Cluster
Package Cn.sys.auth.redisCach;

Import org.springframework.beans.factory.annotation.Autowired;
Import Redis.clients.jedis.JedisCluster;
 /** * * Class name: Jedisclientclusterservcie. 
	* Class Description: Cluster implementation * Creator: Lyj * creation time: November 21, 2016 PM 7:15:22/public class Jedisclientclusterservcie implements jedisclient{
	
	@Autowired private Jediscluster Jediscluster;
	@Override public string "(string key) {return jediscluster.get (key);
	@Override public string Set (string key, String value) {return Jediscluster.set (key, value);
	@Override public string Hget (string hkey, string key) {return Jediscluster.hget (hkey, key);
	@Override Public Long Hset (string hkey, String key, String value) {return Jediscluster.hset (hkey, key, value);
	@Override Public long incr (String key) {return jediscluster.incr (key);
	@Override Public long expire (String key, int second) {return Jediscluster.expire (key, second); @Override public long TTL (String key) {return JedisclusTer.ttl (key);
	@Override Public long del (String key) {return Jediscluster.del (key);
	@Override Public Long Hdel (string hkey, string key) {return Jediscluster.hdel (hkey, key);
 }
}
Single
Package Cn.sys.auth.redisCach;
Import org.springframework.beans.factory.annotation.Autowired;

Import Org.springframework.stereotype.Service;
Import Redis.clients.jedis.Jedis;
Import Redis.clients.jedis.JedisPool;
 /** * * Class name: Jedisclientsingleservice. * Class Description: Standalone Implementation class * Creator: Lyj * Create time: November 21, 2016 PM 7:16:06/@Service public class Jedisclientsingleservice implements J 
		
		edisclient {@Autowired private jedispool jedispool;
			@Override public string (string key) {Jedis Jedis = Jedispool.getresource ();
			String string = Jedis.get (key);
			Jedis.close ();
		return string;
			@Override public string Set (string key, String value) {Jedis Jedis = Jedispool.getresource ();
			String string = Jedis.set (key, value);
			Jedis.close ();
		return string;
			@Override public string Hget (string hkey, String key) {Jedis Jedis = Jedispool.getresource ();
			String string = Jedis.hget (hkey, key);
			Jedis.close ();
		return string; @Override Public Long Hset (String hkey, String key, String value) {Jedis Jedis = Jedispool.getresource ();
			Long result = Jedis.hset (hkey, key, value);
			Jedis.close ();
		return result;
			@Override Public long incr (String key) {Jedis Jedis = Jedispool.getresource ();
			Long result = JEDIS.INCR (key);
			Jedis.close ();
		return result;
			@Override Public long expire (String key, int second) {Jedis Jedis = Jedispool.getresource ();
			Long result = Jedis.expire (key, second);
			Jedis.close ();
		return result;
			@Override public long TTL (String key) {Jedis Jedis = Jedispool.getresource ();
			Long result = Jedis.ttl (key);
			Jedis.close ();
		return result;
			@Override Public long del (String key) {Jedis Jedis = Jedispool.getresource ();
			Long result = Jedis.del (key);
			Jedis.close ();
		return result;
			@Override Public Long Hdel (string hkey, String key) {Jedis Jedis = Jedispool.getresource ();
			Long result = Jedis.hdel (hkey, key); Jedis.close ();
		return result;
 }
	}

In this regard, the development and construction completed
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: info-contact@alibabacloud.com 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.