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);
}
}
|
|