org.springframework.data.redis.core.ValueOperations Java Examples

The following examples show how to use org.springframework.data.redis.core.ValueOperations. 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: SmsController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 更改手机验证码
 */
@RequestMapping(value = "/change/code", method = RequestMethod.POST)
public MessageResult resetPhoneCode(@SessionAttribute(SESSION_MEMBER) AuthMember user) throws Exception {
    Member member = memberService.findOne(user.getId());
    Assert.hasText(member.getMobilePhone(), localeMessageSourceService.getMessage("NOT_BIND_PHONE"));
    MessageResult result;
    String randomCode = String.valueOf(GeneratorUtil.getRandomNumber(100000, 999999));
    if ("86".equals(member.getCountry().getAreaCode())) {
        result = smsProvider.sendVerifyMessage(member.getMobilePhone(), randomCode);
    } else {
        result = smsProvider.sendInternationalMessage(randomCode, member.getCountry().getAreaCode() + member.getMobilePhone());
    }
    if (result.getCode() == 0) {
        ValueOperations valueOperations = redisTemplate.opsForValue();
        String key = SysConstant.PHONE_CHANGE_CODE_PREFIX + member.getMobilePhone();
        valueOperations.getOperations().delete(key);
        // 缓存验证码
        valueOperations.set(key, randomCode, 10, TimeUnit.MINUTES);
        return success(localeMessageSourceService.getMessage("SEND_SMS_SUCCESS"));
    } else {
        return error(localeMessageSourceService.getMessage("SEND_SMS_FAILED"));
    }
}
 
Example #2
Source File: ApproveController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 重置资金密码
 *
 * @param newPassword
 * @param code
 * @param user
 * @return
 * @throws Exception
 */
@RequestMapping("/reset/transaction/password")
@Transactional(rollbackFor = Exception.class)
public MessageResult resetTransaction(String newPassword, String code, @SessionAttribute(SESSION_MEMBER) AuthMember user) throws Exception {
    hasText(newPassword, msService.getMessage("MISSING_NEW_JY_PASSWORD"));
    isTrue(newPassword.length() >= 6 && newPassword.length() <= 20, msService.getMessage("JY_PASSWORD_LENGTH_ILLEGAL"));
    ValueOperations valueOperations = redisTemplate.opsForValue();
    Object cache = valueOperations.get(SysConstant.PHONE_RESET_TRANS_CODE_PREFIX + user.getMobilePhone());
    notNull(cache, msService.getMessage("NO_GET_VERIFICATION_CODE"));
    hasText(code, msService.getMessage("MISSING_VERIFICATION_CODE"));
    if (!code.equals(cache.toString())) {
        return MessageResult.error(msService.getMessage("VERIFICATION_CODE_INCORRECT"));
    } else {
        valueOperations.getOperations().delete(SysConstant.PHONE_RESET_TRANS_CODE_PREFIX + user.getMobilePhone());
    }
    Member member = memberService.findOne(user.getId());
    member.setJyPassword(Md5.md5Digest(newPassword + member.getSalt()).toLowerCase());
    return MessageResult.success(msService.getMessage("SETTING_JY_PASSWORD"));
}
 
Example #3
Source File: SystemTask.java    From mysiteforme with Apache License 2.0 6 votes vote down vote up
/**
 * 同步文章点击量
 * @param params
 */
public void  synchronizationArticleView(String params){
    ValueOperations<String, Object> operations=redisTemplate.opsForValue();
    EntityWrapper<BlogArticle> wrapper = new EntityWrapper<>();
    wrapper.eq("del_flag",false);
    List<BlogArticle> list = blogArticleService.selectList(wrapper);
    for (BlogArticle article : list){
        String key = "article_click_id_"+article.getId();
        if(redisTemplate.hasKey(key)){
            Integer count = (Integer)operations.get(key);
            if(count > 0){
                article.setClick(blogArticleService.getArticleClick(article.getId()));
                if(StringUtils.isNotBlank(params)){
                    article.setUpdateId(Long.valueOf(params));
                }
                blogArticleService.updateById(article);
            }
        }
    }
}
 
Example #4
Source File: ExchangeInitPlateController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 删除信息
 * @param id
 * @return
 * @throws Exception
 */
@RequiresPermissions("exchange:init-plate:delete")
@GetMapping("delete/{id}")
public MessageResult deleteExchangeInitPlate(@PathVariable("id")long id)throws Exception{
    MessageResult mr = new MessageResult();
    try {
        InitPlate initPlate = initPlateService.findByInitPlateId(id);
        if(initPlate==null){
            mr.setCode(500);
            mr.setMessage("不存在该记录");
            return mr;
        }
        initPlateService.delete(id);
        ValueOperations valueOperations = redisTemplate.opsForValue();
        String key = SysConstant.EXCHANGE_INIT_PLATE_SYMBOL_KEY+initPlate.getSymbol();
        valueOperations.getOperations().delete(key);
        mr.setCode(0);
        mr.setMessage("success");
    }catch (Exception e){
        log.info(">>>>deleteExchangeInitPlate Error={}",e);
        e.printStackTrace();
        throw new Exception(e);
    }

    return  mr ;
}
 
Example #5
Source File: ApproveController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 绑定邮箱
 *
 * @param request
 * @param password
 * @param code
 * @param email
 * @param user
 * @return
 */
@RequestMapping("/bind/email")
@Transactional(rollbackFor = Exception.class)
public MessageResult bindEmail(HttpServletRequest request, String password, String code, String email, @SessionAttribute(SESSION_MEMBER) AuthMember user) throws Exception {
    hasText(password, msService.getMessage("MISSING_LOGIN_PASSWORD"));
    hasText(code, msService.getMessage("MISSING_VERIFICATION_CODE"));
    hasText(email, msService.getMessage("MISSING_EMAIL"));
    isTrue(ValidateUtil.isEmail(email), msService.getMessage("EMAIL_FORMAT_ERROR"));
    ValueOperations valueOperations = redisTemplate.opsForValue();
    Object cache = valueOperations.get(SysConstant.EMAIL_BIND_CODE_PREFIX + email);
    notNull(cache, msService.getMessage("NO_GET_VERIFICATION_CODE"));
    isTrue(code.equals(cache.toString()), msService.getMessage("VERIFICATION_CODE_INCORRECT"));
    Member member = memberService.findOne(user.getId());
    isTrue(member.getEmail() == null, msService.getMessage("REPEAT_EMAIL_REQUEST"));
    if (!Md5.md5Digest(password + member.getSalt()).toLowerCase().equals(member.getPassword())) {
        request.removeAttribute(SysConstant.SESSION_MEMBER);
        return MessageResult.error(msService.getMessage("PASSWORD_ERROR"));
    } else {
        member.setEmail(email);
        return MessageResult.success(msService.getMessage("SETTING_SUCCESS"));
    }
}
 
Example #6
Source File: AideController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 获取该分类(二级页面)
 * @param pageNo
 * @param pageSize
 * @param cate
 * @return
 */
@RequestMapping(value = "more/help/page",method = RequestMethod.POST)
public MessageResult sysHelpCate(@RequestParam(value = "pageNo",defaultValue = "1")int pageNo,
                                @RequestParam(value = "pageSize",defaultValue = "10")int pageSize,
                                @RequestParam(value = "cate")SysHelpClassification cate){
    ValueOperations valueOperations = redisTemplate.opsForValue();
    JSONObject result = (JSONObject) valueOperations.get(SysConstant.SYS_HELP_CATE+cate);
    if (result != null){
        return success(result);
    }else {
        JSONObject jsonObject = new JSONObject();
        Page<SysHelp> sysHelpPage = sysHelpService.findByCondition(pageNo,pageSize,cate);
        jsonObject.put("content",sysHelpPage.getContent());
        jsonObject.put("totalPage",sysHelpPage.getTotalPages());
        jsonObject.put("totalElements",sysHelpPage.getTotalElements());
        valueOperations.set(SysConstant.SYS_HELP_CATE+cate,jsonObject,SysConstant.SYS_HELP_CATE_EXPIRE_TIME, TimeUnit.SECONDS);
        return success(jsonObject);

    }

}
 
Example #7
Source File: AnnouncementController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 根据ID获取当前公告及上一条和下一条
 * @param id
 * @return
 */
@RequestMapping(value = "more",method = RequestMethod.POST)
public MessageResult moreDetail(@RequestParam("id")Long id ){
    ValueOperations redisOperations = redisTemplate.opsForValue();
    JSONObject result  = (JSONObject) redisOperations.get(SysConstant.NOTICE_DETAIL+id);
    if ( result != null){
        return success(result);
    }else {
        JSONObject resultObj = new JSONObject();
        Announcement announcement = announcementService.findById(id);
        Assert.notNull(announcement, "validate id!");
        resultObj.put("info",announcement);
        resultObj.put("back",announcementService.getBack(id));
        resultObj.put("next",announcementService.getNext(id));
        redisOperations.set(SysConstant.NOTICE_DETAIL+id,resultObj,SysConstant.NOTICE_DETAIL_EXPIRE_TIME, TimeUnit.SECONDS);
        return success(resultObj);
    }
}
 
Example #8
Source File: RegisterController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 发送绑定邮箱验证码
 *
 * @param email
 * @param user
 * @return
 */
@RequestMapping("/bind/email/code")
@ResponseBody
@Transactional(rollbackFor = Exception.class)
public MessageResult sendBindEmail(String email, @SessionAttribute(SESSION_MEMBER) AuthMember user) {
    Assert.isTrue(ValidateUtil.isEmail(email), localeMessageSourceService.getMessage("WRONG_EMAIL"));
    Member member = memberService.findOne(user.getId());
    Assert.isNull(member.getEmail(), localeMessageSourceService.getMessage("BIND_EMAIL_REPEAT"));
    Assert.isTrue(!memberService.emailIsExist(email), localeMessageSourceService.getMessage("EMAIL_ALREADY_BOUND"));
    String code = String.valueOf(GeneratorUtil.getRandomNumber(100000, 999999));
    ValueOperations valueOperations = redisTemplate.opsForValue();
    if (valueOperations.get(EMAIL_BIND_CODE_PREFIX + email) != null) {
        return error(localeMessageSourceService.getMessage("EMAIL_ALREADY_SEND"));
    }
    try {
        sentEmailCode(valueOperations, email, code);
    } catch (Exception e) {
        e.printStackTrace();
        return error(localeMessageSourceService.getMessage("SEND_FAILED"));
    }
    return success(localeMessageSourceService.getMessage("SENT_SUCCESS_TEN"));
}
 
Example #9
Source File: RegisterController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 忘记密码后重置密码
 *
 * @param mode     0为手机验证,1为邮箱验证
 * @param account  手机或邮箱
 * @param code     验证码
 * @param password 新密码
 * @return
 */
@RequestMapping(value = "/reset/login/password", method = RequestMethod.POST)
@ResponseBody
@Transactional(rollbackFor = Exception.class)
public MessageResult forgetPassword(int mode, String account, String code, String password) throws Exception {
    Member member = null;
    ValueOperations valueOperations = redisTemplate.opsForValue();
    Object redisCode = valueOperations.get(SysConstant.RESET_PASSWORD_CODE_PREFIX + account);
    notNull(redisCode, localeMessageSourceService.getMessage("VERIFICATION_CODE_NOT_EXISTS"));
    if (mode == 0) {
        member = memberService.findByPhone(account);
    } else if (mode == 1) {
        member = memberService.findByEmail(account);
    }
    isTrue(password.length() >= 6 && password.length() <= 20, localeMessageSourceService.getMessage("PASSWORD_LENGTH_ILLEGAL"));
    notNull(member, localeMessageSourceService.getMessage("MEMBER_NOT_EXISTS"));
    if (!code.equals(redisCode.toString())) {
        return error(localeMessageSourceService.getMessage("VERIFICATION_CODE_INCORRECT"));
    } else {
        valueOperations.getOperations().delete(SysConstant.RESET_PASSWORD_CODE_PREFIX + account);
    }
    //生成密码
    String newPassword = Md5.md5Digest(password + member.getSalt()).toLowerCase();
    member.setPassword(newPassword);
    return success();
}
 
Example #10
Source File: SmsController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 重置交易密码验证码
 *
 * @param user
 * @return
 */
@RequestMapping(value = "/transaction/code", method = RequestMethod.POST)
public MessageResult sendResetTransactionCode(@SessionAttribute(SESSION_MEMBER) AuthMember user) throws Exception {
    Member member = memberService.findOne(user.getId());
    Assert.hasText(member.getMobilePhone(), localeMessageSourceService.getMessage("NOT_BIND_PHONE"));
    String randomCode = String.valueOf(GeneratorUtil.getRandomNumber(100000, 999999));
    MessageResult result;
    if ("86".equals(member.getCountry().getAreaCode())) {
        result = smsProvider.sendVerifyMessage(member.getMobilePhone(), randomCode);
    } else {
        result = smsProvider.sendInternationalMessage(randomCode, member.getCountry().getAreaCode() + member.getMobilePhone());
    }
    if (result.getCode() == 0) {
        ValueOperations valueOperations = redisTemplate.opsForValue();
        String key = SysConstant.PHONE_RESET_TRANS_CODE_PREFIX + member.getMobilePhone();
        valueOperations.getOperations().delete(key);
        // 缓存验证码
        valueOperations.set(key, randomCode, 10, TimeUnit.MINUTES);
        return success(localeMessageSourceService.getMessage("SEND_SMS_SUCCESS"));
    } else {
        return error(localeMessageSourceService.getMessage("SEND_SMS_FAILED"));
    }
}
 
Example #11
Source File: Pub_RedisUtils.java    From SuperBoot with MIT License 6 votes vote down vote up
/**
 * 根据来源平台与版本获取TOKEN
 *
 * @param pkUser   用户主键
 * @param platform 来源平台
 * @param version  来源版本
 * @return
 */
public String getTokenAllow(long pkUser, String platform, String version) {
    ValueOperations<String, HashMap> operations = redisTemplate.opsForValue();
    boolean exists = redisTemplate.hasKey(BaseConstants.USER_TOKEN + "-" + pkUser);
    if (exists) {
        HashMap<String, Object> tokenMap = operations.get(BaseConstants.USER_TOKEN + "-" + pkUser);
        //循环处理TOKEN白名单里失效的TOKEN
        for (String key : tokenMap.keySet()) {
            //判断对象是TOKEN
            if (key.startsWith("Bearer")) {
                //如果TOKEN已经不存在了
                if (!redisTemplate.hasKey(key)) {
                    //清理失效TOKEN信息
                    cleanTokenAllow(pkUser, key);
                }
            }
        }
        if (tokenMap.containsKey(platform + "-" + version)) {
            return "" + tokenMap.get(platform + "-" + version);
        }
    }
    return null;
}
 
Example #12
Source File: SmsProviderController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
private MessageResult sendCode(String phone, String prefix) {
    Assert.notNull(phone, msService.getMessage("NO_CELL_PHONE_NUMBER"));
    MessageResult result;
    String randomCode = String.valueOf(GeneratorUtil.getRandomNumber(100000, 999999));
    try {
        ValueOperations valueOperations = redisTemplate.opsForValue();
        String key = prefix + phone;
        long expire = valueOperations.getOperations().getExpire(key, TimeUnit.SECONDS);
        if (expire < 600 && expire > 540) {
            return error(msService.getMessage("SEND_CODE_FAILURE_ONE"));
        }
             result = smsProvider.sendVerifyMessage(phone, randomCode);
        if (result.getCode() == 0) {
            logger.info("短信验证码:{}", randomCode);
            valueOperations.set(key, randomCode, 10, TimeUnit.MINUTES);
            return success(msService.getMessage("SEND_CODE_SUCCESS") + phone);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return error(msService.getMessage("REQUEST_FAILED"));
}
 
Example #13
Source File: RegisterController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 增加提币地址验证码
 *
 * @param user
 * @return
 */
@RequestMapping("/add/address/code")
@ResponseBody
@Transactional(rollbackFor = Exception.class)
public MessageResult sendAddAddress(@SessionAttribute(SESSION_MEMBER) AuthMember user) {
    String code = String.valueOf(GeneratorUtil.getRandomNumber(100000, 999999));
    ValueOperations valueOperations = redisTemplate.opsForValue();
    Member member = memberService.findOne(user.getId());
    String email = member.getEmail();
    if (email == null) {
        return error(localeMessageSourceService.getMessage("NOT_BIND_EMAIL"));
    }
    if (valueOperations.get(ADD_ADDRESS_CODE_PREFIX + email) != null) {
        return error(localeMessageSourceService.getMessage("EMAIL_ALREADY_SEND"));
    }
    try {
        sentEmailAddCode(valueOperations, email, code);
    } catch (Exception e) {
        e.printStackTrace();
        return error(localeMessageSourceService.getMessage("SEND_FAILED"));
    }
    return success(localeMessageSourceService.getMessage("SENT_SUCCESS_TEN"));
}
 
Example #14
Source File: Pub_RedisUtils.java    From SuperBoot with MIT License 6 votes vote down vote up
/**
 * 获取用户菜单
 *
 * @param userId 用户ID
 * @return
 */
public List getUserMenu(long userId) {
    ValueOperations<String, String> operations = redisTemplate.opsForValue();
    boolean exists = redisTemplate.hasKey(USER_MENU + userId);
    if (exists) {

        Object list = operations.get(USER_MENU + userId);
        if (list instanceof List) {
            return (List<UserMenuDTO>) list;
        }

        Object o = JSON.parse(operations.get(USER_MENU + userId));

        List<UserMenuDTO> rList = new ArrayList<>();

        List data = JSON.toJavaObject((JSON) o, List.class);

        for (int i = 0; i < data.size(); i++) {
            UserMenuDTO item = ((JSONObject) data.get(i)).toJavaObject(UserMenuDTO.class);
            rList.add(item);

        }
        return rList;
    }
    return null;
}
 
Example #15
Source File: RegisterController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 忘记密码后重置密码
 *
 * @param mode     0为手机验证,1为邮箱验证
 * @param account  手机或邮箱
 * @param code     验证码
 * @param password 新密码
 * @return
 */
@RequestMapping(value = "/reset/login/password", method = RequestMethod.POST)
@ResponseBody
@Transactional(rollbackFor = Exception.class)
public MessageResult forgetPassword(int mode, String account, String code, String password) throws Exception {
    Member member = null;
    ValueOperations valueOperations = redisTemplate.opsForValue();
    Object redisCode = valueOperations.get(SysConstant.RESET_PASSWORD_CODE_PREFIX + account);
    notNull(redisCode, localeMessageSourceService.getMessage("VERIFICATION_CODE_NOT_EXISTS"));
    if (mode == 0) {
        member = memberService.findByPhone(account);
    } else if (mode == 1) {
        member = memberService.findByEmail(account);
    }
    isTrue(password.length() >= 6 && password.length() <= 20, localeMessageSourceService.getMessage("PASSWORD_LENGTH_ILLEGAL"));
    notNull(member, localeMessageSourceService.getMessage("MEMBER_NOT_EXISTS"));
    if (!code.equals(redisCode.toString())) {
        return error(localeMessageSourceService.getMessage("VERIFICATION_CODE_INCORRECT"));
    } else {
        valueOperations.getOperations().delete(SysConstant.RESET_PASSWORD_CODE_PREFIX + account);
    }
    //生成密码
    String newPassword = Md5.md5Digest(password + member.getSalt()).toLowerCase();
    member.setPassword(newPassword);
    return success();
}
 
Example #16
Source File: SmsController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 忘记密码验证码
 */
@RequestMapping(value = "/reset/code", method = RequestMethod.POST)
public MessageResult resetPasswordCode(String account) throws Exception {
    Member member = memberService.findByPhone(account);
    Assert.notNull(member, localeMessageSourceService.getMessage("MEMBER_NOT_EXISTS"));
    MessageResult result;
    String randomCode = String.valueOf(GeneratorUtil.getRandomNumber(100000, 999999));
    if ("86".equals(member.getCountry().getAreaCode())) {
        result = smsProvider.sendVerifyMessage(member.getMobilePhone(), randomCode);
    } else {
        result = smsProvider.sendInternationalMessage(randomCode, member.getCountry().getAreaCode() + member.getMobilePhone());
    }
    if (result.getCode() == 0) {
        ValueOperations valueOperations = redisTemplate.opsForValue();
        String key = SysConstant.RESET_PASSWORD_CODE_PREFIX + member.getMobilePhone();
        valueOperations.getOperations().delete(key);
        // 缓存验证码
        valueOperations.set(key, randomCode, 10, TimeUnit.MINUTES);
        return success(localeMessageSourceService.getMessage("SEND_SMS_SUCCESS"));
    } else {
        return error(localeMessageSourceService.getMessage("SEND_SMS_FAILED"));
    }
}
 
Example #17
Source File: SmsController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
@RequestMapping(value = "/add/address/code", method = RequestMethod.POST)
public MessageResult addAddressCode(@SessionAttribute(SESSION_MEMBER) AuthMember user) throws Exception {
    Member member = memberService.findOne(user.getId());
    Assert.hasText(member.getMobilePhone(), localeMessageSourceService.getMessage("NOT_BIND_PHONE"));
    MessageResult result;
    String randomCode = String.valueOf(GeneratorUtil.getRandomNumber(100000, 999999));
    if ("86".equals(member.getCountry().getAreaCode())) {
        result = smsProvider.sendVerifyMessage(member.getMobilePhone(), randomCode);
    } else {
        result = smsProvider.sendInternationalMessage(randomCode, member.getCountry().getAreaCode() + member.getMobilePhone());
    }
    if (result.getCode() == 0) {
        ValueOperations valueOperations = redisTemplate.opsForValue();
        String key = SysConstant.PHONE_ADD_ADDRESS_PREFIX + member.getMobilePhone();
        valueOperations.getOperations().delete(key);
        // 缓存验证码
        valueOperations.set(key, randomCode, 10, TimeUnit.MINUTES);
        return success(localeMessageSourceService.getMessage("SEND_SMS_SUCCESS"));
    } else {
        return error(localeMessageSourceService.getMessage("SEND_SMS_FAILED"));
    }
}
 
Example #18
Source File: SmsController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
@RequestMapping(value = "/withdraw/code", method = RequestMethod.POST)
public MessageResult withdrawCode(@SessionAttribute(SESSION_MEMBER) AuthMember user) throws Exception {
    Member member = memberService.findOne(user.getId());
    Assert.hasText(member.getMobilePhone(), localeMessageSourceService.getMessage("NOT_BIND_PHONE"));
    MessageResult result;
    log.info("===提币验证码发送===mobile:"+member.getMobilePhone());
    String randomCode = String.valueOf(GeneratorUtil.getRandomNumber(100000, 999999));
    if ("86".equals(member.getCountry().getAreaCode())) {
        result = smsProvider.sendVerifyMessage(member.getMobilePhone(), randomCode);
    } else {
        result = smsProvider.sendInternationalMessage(randomCode, member.getCountry().getAreaCode() + member.getMobilePhone());
    }
    if (result.getCode() == 0) {
        ValueOperations valueOperations = redisTemplate.opsForValue();
        String key = SysConstant.PHONE_WITHDRAW_MONEY_CODE_PREFIX + member.getMobilePhone();
        valueOperations.getOperations().delete(key);
        // 缓存验证码
        valueOperations.set(key, randomCode, 10, TimeUnit.MINUTES);
        return success(localeMessageSourceService.getMessage("SEND_SMS_SUCCESS"));
    } else {
        return error(localeMessageSourceService.getMessage("SEND_SMS_FAILED"));
    }
}
 
Example #19
Source File: BaseAdminController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 判断手机验证码正确否
 * @param code 验证码
 * @param key redis中的key 前缀+手机号
 * @return
 */
protected MessageResult checkCode(String code, String key){
    ValueOperations valueOperations = redisTemplate.opsForValue();
    Object value = valueOperations.get(key);
    if(value==null) {
        return error(msService.getMessage("CODE_NOT_EXIST_RESEND"));
    }
    if(!value.toString().equals(code)) {
        return  error(msService.getMessage("CODE_ERROR"));
    }
    valueOperations.getOperations().delete(key);
    /**
     * 十分钟之内无需再次验证
     */
    valueOperations.set(key+"_PASS",true,10, TimeUnit.MINUTES);
    return success(msService.getMessage("CODE_CORRECT"));
}
 
Example #20
Source File: RedisCache.java    From poseidon with Apache License 2.0 5 votes vote down vote up
/**
 * Get cached query result from redis
 * @param key
 * @return
 */
@Override
public Object getObject(Object key) {
	try {
		RedisTemplate redisTemplate = getRedisTemplate();
		ValueOperations opsForValue = redisTemplate.opsForValue();
		logger.debug("Get cached query result from redis");
		return opsForValue.get(key);
	}
	catch (Throwable t) {
		logger.error("Redis get failed, fail over to db", t);
		return null;
	}
}
 
Example #21
Source File: CityHandler.java    From springboot-learning-example with Apache License 2.0 5 votes vote down vote up
public Mono<City> findCityById(Long id) {

        // 从缓存中获取城市信息
        String key = "city_" + id;
        ValueOperations<String, City> operations = redisTemplate.opsForValue();

        // 缓存存在
        boolean hasKey = redisTemplate.hasKey(key);
        if (hasKey) {
            City city = operations.get(key);

            LOGGER.info("CityHandler.findCityById() : 从缓存中获取了城市 >> " + city.toString());
            return Mono.create(cityMonoSink -> cityMonoSink.success(city));
        }

        // 从 MongoDB 中获取城市信息
        Mono<City> cityMono = cityRepository.findById(id);

        if (cityMono == null)
            return cityMono;

        // 插入缓存
        cityMono.subscribe(cityObj -> {
            operations.set(key, cityObj);
            LOGGER.info("CityHandler.findCityById() : 城市插入缓存 >> " + cityObj.toString());
        });

        return cityMono;
    }
 
Example #22
Source File: BizCommentServiceImpl.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 点赞
 *
 * @param id
 */
@Override
@RedisCache(flush = true)
public void doSupport(Long id) {
    String key = IpUtil.getRealIp(RequestHolder.getRequest()) + "_doSupport_" + id;
    ValueOperations<String, Object> operations = redisTemplate.opsForValue();
    if (redisTemplate.hasKey(key)) {
        throw new ZhydCommentException("一个小时只能点一次赞哈~");
    }
    bizCommentMapper.doSupport(id);
    operations.set(key, id, 1, TimeUnit.HOURS);
}
 
Example #23
Source File: RedisUtil.java    From MI-S with MIT License 5 votes vote down vote up
/**
 * 写入缓存
 *
 * @param key
 * @param value
 * @return
 */
public static boolean set(final String key, Object value, Long expireTime) {
    boolean result = false;
    try {
        ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue();
        operations.set(key, value);
        redisTemplate.expire(key, expireTime, TimeUnit.SECONDS);

        result = true;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}
 
Example #24
Source File: RedisUtilsTest.java    From fw-spring-cloud with Apache License 2.0 5 votes vote down vote up
private  void  setinfo(String key){
    SerializerThreadlocal.set(key);
    ValueOperations<String, String> operations = (ValueOperations<String, String>) redisTemplate
            .opsForValue();
    operations.set("lisi", "999");
    String lisi = operations.get("lisi");
    log.info(lisi);
}
 
Example #25
Source File: TestController.java    From spring_boot with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/redisSelectTwo")
public String redisSelectTwo(){
    RedisTemplate template = RedisUtil.getSelect_1();
    ValueOperations ops = template.opsForValue();
    ops.set("test","1");
    return "success";
}
 
Example #26
Source File: RedisCache.java    From poseidon with Apache License 2.0 5 votes vote down vote up
/**
 * Put query result to redis
 * @param key
 * @param value
 */
@Override
@SuppressWarnings("unchecked")
public void putObject(Object key, Object value) {
	try {
		RedisTemplate redisTemplate = getRedisTemplate();
		ValueOperations opsForValue = redisTemplate.opsForValue();
		opsForValue.set(key, value, EXPIRE_TIME_IN_MINUTES, TimeUnit.MINUTES);
		logger.debug("Put query result to redis");
	}
	catch (Throwable t) {
		logger.error("Redis put failed", t);
	}
}
 
Example #27
Source File: TestRedis2.java    From spring-boot-demo with MIT License 5 votes vote down vote up
@Test
public void test() {
    ValueOperations<String, String> ops = this.template.opsForValue();
    String key = "DemoRedisApplication";
    if (!this.template.hasKey(key)) {
        ops.set(key, "easy-web");
    }
    log.info("找到key=" + key + ", 值=" + ops.get(key));
}
 
Example #28
Source File: TxManagerServiceImpl.java    From tx-lcn with Apache License 2.0 5 votes vote down vote up
@Override
public TxGroup createTransactionGroup() {
    String groupId = KidUtils.generateShortUuid();
    TxGroup txGroup = new TxGroup();
    txGroup.setStartTime(System.currentTimeMillis());
    txGroup.setGroupId(groupId);
    String key = key_prefix + groupId;
    ValueOperations<String, String> value = redisTemplate.opsForValue();
    value.set(key, txGroup.toJsonString(), redis_save_max_time, TimeUnit.SECONDS);
    return txGroup;
}
 
Example #29
Source File: RedisUtils.java    From springboot-learn with MIT License 5 votes vote down vote up
/**
 * 写入缓存
 *
 * @param key
 * @param value
 * @return
 */
@SuppressWarnings("unchecked")
public boolean set(final String key, Object value) {
    boolean result = false;
    try {
        ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue();
        operations.set(key, value);
        result = true;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}
 
Example #30
Source File: AideController.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
/**
 * 查询帮助中心首页数据
 * @param total
 * @return
 */
@RequestMapping(value = "more/help",method = RequestMethod.POST)
public MessageResult sysAllHelp(@RequestParam(value = "total",defaultValue = "6")int total){

    ValueOperations valueOperations = redisTemplate.opsForValue();
    List<JSONObject> result = (List<JSONObject>) valueOperations.get(SysConstant.SYS_HELP);
    if (result != null){
        return success(result);
    } else {
        //HELP("新手指南"),
        List<JSONObject> jsonResult = new ArrayList<>();
        Page<SysHelp> sysHelpPage = sysHelpService.findByCondition(1,total,SysHelpClassification.HELP);
        JSONObject jsonSysHelp = new JSONObject();
        jsonSysHelp.put("content",sysHelpPage.getContent());
        jsonSysHelp.put("title","新手指南");
        jsonSysHelp.put("cate","0");
        jsonResult.add(jsonSysHelp);

        //FAQ("常见问题"),
        Page<SysHelp> sysFaqPage = sysHelpService.findByCondition(1,total,SysHelpClassification.FAQ);
        JSONObject jsonSysFaq = new JSONObject();
        jsonSysFaq.put("content",sysFaqPage.getContent());
        jsonSysFaq.put("title","常见问题");
        jsonSysFaq.put("cate","1");
        jsonResult.add(jsonSysFaq);
        valueOperations.set(SysConstant.SYS_HELP,jsonResult,SysConstant.SYS_HELP_EXPIRE_TIME, TimeUnit.SECONDS);
        return success(jsonResult);
    }


    //RECHARGE("充值指南"),
    //Page<SysHelp> sysRechangePage = sysHelpService.findByCondition(1,total,SysHelpClassification.HELP);

    //TRANSACTION("交易指南"),
    //Page<SysHelp> sysTransactonPage = sysHelpService.findByCondition(1,total,SysHelpClassification.HELP);




}