Java Code Examples for org.redisson.api.RBucket#expire()
The following examples show how to use
org.redisson.api.RBucket#expire() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KaptchaServiceImpl.java From gpmall with Apache License 2.0 | 6 votes |
@Override public KaptchaCodeResponse getKaptchaCode(KaptchaCodeRequest request) { KaptchaCodeResponse response=new KaptchaCodeResponse(); try { ImageResult capText = VerifyCodeUtils.VerifyCode(140, 43, 4); response.setImageCode(capText.getImg()); String uuid= UUID.randomUUID().toString(); RBucket rBucket=redissonClient.getBucket(KAPTCHA_UUID+uuid); rBucket.set(capText.getCode()); rBucket.expire(60, TimeUnit.SECONDS); response.setImageCode(capText.getImg()); response.setUuid(uuid); response.setCode(SysRetCodeConstants.SUCCESS.getCode()); response.setMsg(SysRetCodeConstants.SUCCESS.getMessage()); }catch (Exception e){ log.error("KaptchaServiceImpl.getKaptchaCode occur Exception :"+e); ExceptionProcessorUtils.wrapperHandlerException(response,e); } return response; }
Example 2
Source File: UserRepository.java From j360-dubbo-app-all with Apache License 2.0 | 6 votes |
/** * redission 作为二级缓存DAO层的案例 * @param itemId * @return */ public UserDO getGoodsCacheable(long itemId) { try{ RBucket<UserDO> rBucket = redissonClient.getBucket(String.format(UserKeys.USER_DO_ID, itemId, JsonJacksonCodec.INSTANCE)); if (rBucket.isExists()) { rBucket.expire(AppConfig.COMMON_CACHE_DAYS, TimeUnit.MINUTES); return rBucket.get(); } UserDO topicDO = getGoods(itemId); if (Objects.nonNull(topicDO)) { redissonClient.getBucket(String.format(UserKeys.USER_DO_ID, itemId),JsonJacksonCodec.INSTANCE) .setAsync(topicDO, AppConfig.COMMON_CACHE_DAYS, TimeUnit.MINUTES); } return topicDO; }catch(Throwable th){ throw new RepositoryException(ErrorCode.DB_ERROR.getErrorCode(),ErrorCode.DB_ERROR.getErrorMsg(),th); } }
Example 3
Source File: UserRepository.java From j360-dubbo-app-all with Apache License 2.0 | 6 votes |
/** * redission 作为二级缓存DAO层的案例 * @param id * @return */ public String getUserCacheable(long id) { try{ RBucket<String> rBucket = redissonClient.getBucket(String.format(UserKeys.USER_DO_ID, id, JsonJacksonCodec.INSTANCE)); if (rBucket.isExists()) { rBucket.expire(AppConfig.COMMON_CACHE_DAYS, TimeUnit.MINUTES); return rBucket.get(); } String name = jdbcTemplate.queryForObject("select username from user where id = ?", String.class, new Object[]{id}); if (Objects.nonNull(name)) { redissonClient.getBucket(String.format(UserKeys.USER_DO_ID, id),JsonJacksonCodec.INSTANCE) .setAsync(name, AppConfig.COMMON_CACHE_DAYS, TimeUnit.MINUTES); } return name; }catch(Throwable th){ throw new RepositoryException(ErrorCode.DB_ERROR.getErrorCode(),ErrorCode.DB_ERROR.getErrorMsg(),th); } }
Example 4
Source File: CacheManager.java From gpmall with Apache License 2.0 | 4 votes |
public void setCache(String key,String val,int expire){ RBucket rBucket = redissonClient.getBucket(key); rBucket.set(val); rBucket.expire(expire, TimeUnit.DAYS); }
Example 5
Source File: RedisLock.java From j360-dubbo-app-all with Apache License 2.0 | 4 votes |
private void expire(final String key, long time, TimeUnit timeUnit) { RBucket<String> keyBucket = redissonClient.getBucket(key); keyBucket.expire(time, timeUnit); }