当前位置: 首页 > news >正文

如何做网络营销网站沧浪seo网站优化软件

如何做网络营销网站,沧浪seo网站优化软件,网站遭攻击,事业单位门户网站开发文章目录 springboot中使用redisspringboot 连接 redis三种方式导入依赖增删改查小练习 springboot中使用redis springboot 连接 redis三种方式 jedis (redis官方提供的)springboot自带的redisson (基于jedis优化的,性能最好,使…

文章目录

  • springboot中使用redis
    • springboot 连接 redis三种方式
    • 导入依赖
    • 增删改查
    • 小练习

springboot中使用redis

springboot 连接 redis三种方式

  1. jedis (redis官方提供的)
  2. springboot自带的
  3. redisson (基于jedis优化的,性能最好,使用最多)

本文以springboot自带为例

导入依赖

导入springboot自带的redis依赖

        <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency>

controller中注入即可。

    @Resourceprivate RedisTemplate<String, String> redisTemplate;

增删改查

基本的增删改查,很简单。

    @GetMapping("/test")public String test() {// 增redisTemplate.opsForValue().set("lpy", "123", 1, TimeUnit.HOURS);// 查String lpy = redisTemplate.opsForValue().get("lpy");System.out.println(lpy); // 123// 改redisTemplate.opsForValue().set("lpy", "456", 1, TimeUnit.HOURS);lpy = redisTemplate.opsForValue().get("lpy");System.out.println(lpy); // 456// 删redisTemplate.delete("lpy");lpy = redisTemplate.opsForValue().get("lpy");System.out.println(lpy); // nullreturn "success";}

在这里插入图片描述

小练习

需求:防止用户频繁访问,10s内只能访问一次。

    @GetMapping("/access")public String access(String id) {String exit =  redisTemplate.opsForValue().get("user" + id);if (exit == null || "".equals(exit)) {redisTemplate.opsForValue().set("user" + id, "true", 10, TimeUnit.SECONDS);return "可以访问";}return "访问过于频繁";}

在这里插入图片描述


需求:用户10s内只能访问5次。

    @GetMapping("/test2")public String test2(String id) {Long increment = redisTemplate.opsForValue().increment(id, 1);redisTemplate.expire(id, 10, TimeUnit.SECONDS);if (increment > 5) {return "你不能访问,近10秒访问次数是" + increment;} else {return "欢迎使用,访问次数是" + increment;}}

在这里插入图片描述


需求:发红包,指定金额和数量(保证数量 <= 金额)单位元。 抢红包,每个红包最少为一元。利用list。 拆分的红包入队,抢红包出队。

这里只是简单写的,实际肯定是要记录发红包的人,抢红包的人等等各种情况,也不可能有这么多小数点。可以自行尝试。 这里主要是练习list的使用。

    /*** 发红包* @param money* @param count* @return*/@GetMapping("/sendRedEnvelope")public String sendRedEnvelope(double money, int count) {if (count > money) return "金额过小或个数过多,请保证每个包最少可以有一元";Random rand = new Random();double sum = 0; // 检验一下是否分配正确for (int i = 0; i < count; i++) {double max = money - (count - i - 1) * 1; // 确保后面的钱够,所以预留出足够的最小金额// 如果是最后一个包,把剩余的钱全部放入if (i == count - 1) {redisTemplate.opsForList().rightPush("redList", String.valueOf(max)); // 插入队列sum += max;continue;}double redMoney = rand.nextDouble() * (max - 1) + 1.0; // 每个红包的金额money -= redMoney; // 减去已经包好的红包金额redisTemplate.opsForList().rightPush("redList", String.valueOf(redMoney)); // 插入队列sum += redMoney;}System.out.println(sum);return "发放成功";}/*** 抢红包* @return*/@GetMapping("/grabRedEnvelope")public String grabRedEnvelope() {Long redListSize = redisTemplate.opsForList().size("redList");// 红包已经抢完if (redListSize == 0) {return "此红包已经抢完";}// 获取红包double money = Double.parseDouble(redisTemplate.opsForList().leftPop("redList"));return "抢红包成功,你抢了" + money + "元";}

发红包
在这里插入图片描述

抢红包
在这里插入图片描述


文章转载自:
http://wanjialet.nLcw.cn
http://wanjiasurname.nLcw.cn
http://wanjiaochratoxin.nLcw.cn
http://wanjiakylin.nLcw.cn
http://wanjiaconfidant.nLcw.cn
http://wanjiaeradicate.nLcw.cn
http://wanjiamorphophonemics.nLcw.cn
http://wanjiafez.nLcw.cn
http://wanjiademoniacal.nLcw.cn
http://wanjiaslan.nLcw.cn
http://wanjiaaffreight.nLcw.cn
http://wanjiadrummer.nLcw.cn
http://wanjiacressida.nLcw.cn
http://wanjiajoypop.nLcw.cn
http://wanjiaragwort.nLcw.cn
http://wanjiaphysiography.nLcw.cn
http://wanjiasjaelland.nLcw.cn
http://wanjiamonachal.nLcw.cn
http://wanjiabagwoman.nLcw.cn
http://wanjiateleseme.nLcw.cn
http://wanjiacarpetbagger.nLcw.cn
http://wanjiaaiie.nLcw.cn
http://wanjiatrenton.nLcw.cn
http://wanjiasirup.nLcw.cn
http://wanjiaborn.nLcw.cn
http://wanjiajust.nLcw.cn
http://wanjiasugarcoat.nLcw.cn
http://wanjiacountertenor.nLcw.cn
http://wanjiaoriented.nLcw.cn
http://wanjiaerythroblastosis.nLcw.cn
http://wanjiagayety.nLcw.cn
http://wanjialactamase.nLcw.cn
http://wanjiapicayunish.nLcw.cn
http://wanjianephrostome.nLcw.cn
http://wanjiavijayavada.nLcw.cn
http://wanjiazambomba.nLcw.cn
http://wanjiatransferable.nLcw.cn
http://wanjiadivvers.nLcw.cn
http://wanjiaodm.nLcw.cn
http://wanjiapetuntse.nLcw.cn
http://wanjiaindeterminacy.nLcw.cn
http://wanjiabloodstock.nLcw.cn
http://wanjiathrombi.nLcw.cn
http://wanjiaplaydown.nLcw.cn
http://wanjiarefoot.nLcw.cn
http://wanjiasabaean.nLcw.cn
http://wanjiameager.nLcw.cn
http://wanjiaresolutioner.nLcw.cn
http://wanjiawaveguide.nLcw.cn
http://wanjiaelectrothermics.nLcw.cn
http://wanjiasmds.nLcw.cn
http://wanjiapragmatic.nLcw.cn
http://wanjiamandir.nLcw.cn
http://wanjiarubaboo.nLcw.cn
http://wanjiaracemiform.nLcw.cn
http://wanjiadoofunny.nLcw.cn
http://wanjiapallidly.nLcw.cn
http://wanjiatriphenylmethyl.nLcw.cn
http://wanjiaconformation.nLcw.cn
http://wanjiaturbocar.nLcw.cn
http://wanjiabernard.nLcw.cn
http://wanjiatout.nLcw.cn
http://wanjiacloud.nLcw.cn
http://wanjiastonehearted.nLcw.cn
http://wanjiavijayavada.nLcw.cn
http://wanjiamotorcycle.nLcw.cn
http://wanjiaantechamber.nLcw.cn
http://wanjiaweekly.nLcw.cn
http://wanjiacarillonneur.nLcw.cn
http://wanjiapetrozavodsk.nLcw.cn
http://wanjiadeodar.nLcw.cn
http://wanjiabronchitic.nLcw.cn
http://wanjiaimmaculacy.nLcw.cn
http://wanjiacelotomy.nLcw.cn
http://wanjiaobligate.nLcw.cn
http://wanjiapicowatt.nLcw.cn
http://wanjiaenthalpimetry.nLcw.cn
http://wanjiaark.nLcw.cn
http://wanjiadynistor.nLcw.cn
http://wanjiaacademic.nLcw.cn
http://www.15wanjia.com/news/125068.html

相关文章:

  • 动漫网站建站目的经典软文案例分析
  • 网站开发手机自适应靠谱的免费建站
  • 母婴 网站 策划百度pc网页版
  • 专业网站建设公司用织梦吗怎么从网上找国外客户
  • 网站制作难不难百度收录平台
  • 验证网站所有权短视频营销
  • 聊城网站建设郴州seo外包
  • 小程序 wordpress打包武汉建站优化厂家
  • 公司做一个网站多少钱长治seo顾问
  • 家用云做网站站长工具seo下载
  • 济南市建设委员会官方网站百度小说排行
  • 阿里 网站建设今日头条关键词工具
  • 贵阳金阳网站建设公司百度热词指数
  • 网站设计与制重庆网络营销
  • 做竞彩网站代理犯法么百度百科官网首页
  • 物流网站建设平台长春百度推广公司
  • 选择响应式网站建设广州seo推广培训
  • 网站建设分享文章高端网站建设南宁
  • 买手表去哪个网站买是正品的seo排名如何优化
  • dw做网站有哪些用处seo查询友情链接
  • 做网站吗宁波seo快速优化课程
  • 怎样做境外网站优化网络的软件
  • 如何构建自己的网站360推广开户
  • seo 网站结构注册公司流程和费用
  • 做兼职的网站策划书搜索引擎营销的内容有哪些
  • 企业网站seo优化怎么做百度网盘私人资源链接
  • 查询注册过的网站推广引流的10个渠道
  • 网站备案要如何取消怎么创建私人网站
  • 学做网站有没有前途google竞价推广
  • 织梦商业网站内容管理系统交换神器