spring整合redis

阅读更多
1.需要引入的包
jedis-2.7.0.jar
apache.commons.pool2-2.2.jar
springframework.data.redis-1.5.0.jar

2.spring整合redis配置

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
      http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">


 
 






class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">














3.代码示例

//spring 整合redis
public class RedisIntegrateDemo {
    public static void main(String[] args) {
         ApplicationContext ctx = new ClassPathXmlApplicationContext("/my/config/spring-bean-services-redis.xml");
         StringRedisTemplate template = ctx.getBean(StringRedisTemplate.class);
         //增
         template.opsForHash().put("omg", "wq", "sm");
         template.opsForHash().put("omg", "key1", "v1");
        
         //删
         template.opsForHash().delete("omg", "wq");
        
         //改
         template.opsForHash().put("omg", "key1", "v1-1");
         //查
         System.out.println(template.opsForHash().get("omg", "key1"));
       
    }
}

你可能感兴趣的:(spring整合redis)