配色: 字号:
redis
2013-09-03 | 阅:  转:  |  分享 
  
xml配置
























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



















packagecom.zhuqing.redis;



@SuppressWarnings(value="unchecked")

@Component("stringRedis")

publicclassStringRedis{



@Resource

privateRedisTemplatestringRedisTemplate;



publicStringRedis(){

}



/

将map直接装入redis中



@paramredisKey

Hash的键

@paramhashValue

所要装入的map对象

@paramexpire

hash的有效期

/

publicvoidputHashAll(StringredisKey,MaphashValue){

BoundHashOperationsbho=this.stringRedisTemplate.boundHashOps(redisKey);

bho.putAll(hashValue);

}



/

设置redis的有效期(毫秒)



@paramredisKey

@paramtimeout

/

publicvoidexpire(StringredisKey,longtimeout){

this.stringRedisTemplate.expire(redisKey,timeout,TimeUnit.MILLISECONDS);

}



/

将键-值装入redis中的hash中



@paramredisKey

Hash的键

@paramkey



@paramvalue



/

publicvoidputHash(StringredisKey,Objectkey,Objectvalue){

BoundHashOperationsbho=this.stringRedisTemplate.boundHashOps(redisKey);

bho.put(key,value);

}



/

将字符装入redis中



@paramredisKey

@paramvalue

/

publicvoidputString(StringredisKey,Stringvalue){

BoundValueOperationsbvo=this.stringRedisTemplate.boundValueOps(redisKey);

bvo.set(value);

}



/

删除



@paramredisKey

redis的键

/

publicvoidremove(StringredisKey){

this.stringRedisTemplate.delete(redisKey);

}



/

批量删除



@paramredisKeys

/

publicvoidremove(CollectionredisKeys){

this.stringRedisTemplate.delete(redisKeys);

}



}

献花(0)
+1
(本文系中工402首藏)