html网站设计实验报告,阿里云网站建设教程视频,网站被k 多久恢复,软件开发专科学校概述
在我们日常的Java Web开发中#xff0c;无不都是使用数据库来进行数据的存储#xff0c;由于一般的系统任务中通常不会存在高并发的情况#xff0c;所以这样看起来并没有什么问题#xff0c;可是一旦涉及大数据量的需求#xff0c;比如一些商品抢购的情景#xff0…概述
在我们日常的Java Web开发中无不都是使用数据库来进行数据的存储由于一般的系统任务中通常不会存在高并发的情况所以这样看起来并没有什么问题可是一旦涉及大数据量的需求比如一些商品抢购的情景或者是主页访问量瞬间较大的时候单一使用数据库来保存数据的系统会因为面向磁盘磁盘读/写速度比较慢的问题而存在严重的性能弊端一瞬间成千上万的请求到来需要系统在极短的时间内完成成千上万次的读/写操作这个时候往往不是数据库能够承受的极其容易造成数据库系统瘫痪最终导致服务宕机的严重生产问题
安装redis
redis是key-value属性的数据库; NOSQL数据库非关系型的;
关系型数据库 msql oracle db2 sqlServer 非关系型数据库 redis mongo db memcached
主要的特点
基于内存存储读写性能高适合存储热点数据热点商品、资讯、新闻 //秒杀系统大量的用户访问该数据企业应用广泛
Redis安装 Redis安装包分为windows版和Linux版
Windows版下载地址https://github.com/microsoftarchive/redis/releasesLinux版下载地址 https://download.redis.io/releases/ redis.windows.conf 配置文件 redis-cli.exe Redis 客户端 redis-server.exe Redis服务端
易错点 启动服务端是需要设置指定的配置文件不然就是默认的配置文件
需要先启动redis的服务端然后再启动客户端服务。
默认的端口号是6379;
通过redis-cli.exe命令默认连接的是本地的redis服务并且使用默认6379端口。也可以通过指定如下参数连接
-h ip地址-p 端口号-a 密码如果需要
简化redis操作使用客户端界面 图形界面操作redis
Redis中的数据类型
五种最常用的数据类型 字符串 string 哈希 hash 列表 list 集合 set 有序集合 sorted set
字符串(string)普通字符串Redis中最简单的数据类型哈希(hash)也叫散列类似于Java中的HashMap结构列表(list)按照插入顺序排序可以有重复元素类似于Java中的LinkedList集合(set)无序集合没有重复元素类似于Java中的HashSet计算交集并集和差集有序集合(sorted set/zset)集合中每个元素关联一个分数(score)根据分数升序排序没有重复元素视频播放排行榜等
Redis中的命令
字符串常用的操作
set key value 设置指定key的值
get key 获取指定key
setex key seconds value //短信验证码使用redis设置多长时间过期 设置指定key的值并将 key 的过期时间设为 seconds 秒
SETNX key value 只有在 key 不存在时设置 key 的值
哈希表的操作
Redis hash 是一个string类型的 field 和 value 的映射表hash特别适合用于存储对象常用命令
HSET key field value 将哈希表 key 中的字段 field 的值设为 valueHGET key field 获取存储在哈希表中指定字段的值HDEL key field 删除存储在哈希表中的指定字段HKEYS key 获取哈希表中所有字段HVALS key 获取哈希表中所有值 在操作前面多了一个H代表哈希表key是表面 field是字段名 value是对应的值
列表操作
Redis 列表是简单的字符串列表按照插入顺序排序常用命令
LPUSH key value1 [value2] 将一个或多个值插入到列表头部LRANGE key start stop 获取列表指定范围内的元素RPOP key 移除并获取列表最后一个元素LLEN key 获取列表长度BRPOP key1 [key2 ] timeout 移出并获取列表的最后一个元素 如果列表没有元素会阻塞列表直到等待超 时或发现可弹出元素为止
集合操作
Redis set 是string类型的无序集合。集合成员是唯一的这就意味着集合中不能出现重复的数据常用命令
SADD key member1 [member2] 向集合添加一个或多个成员SMEMBERS key 返回集合中的所有成员SCARD key 获取集合的成员数SINTER key1 [key2] 返回给定所有集合的交集SUNION key1 [key2] 返回所有给定集合的并集SREM key member1 [member2] 移除集合中一个或多个成员
有序集合操作 视频播放排行榜
Redis有序集合是string类型元素的集合且不允许有重复成员。每个元素都会关联一个double类型的分数。常用命令
常用命令
ZADD key score1 member1 [score2 member2] 向有序集合添加一个或多个成员ZRANGE key start stop [WITHSCORES] 通过索引区间返回有序集合中指定区间内的成员ZINCRBY key increment member 有序集合中对指定成员的分数加上增量 incrementZREM key member [member …] 移除有序集合中的一个或多个成员
通用命令 Redis的通用命令是不分数据类型的都可以使用的命令
KEYS pattern 查找所有符合给定模式( pattern)的 key//可以使用正则表达式EXISTS key 检查给定 key 是否存在TYPE key 返回 key 所储存的值的类型DEL key 该命令用于在 key 存在是删除 key
java中操作redis
Spring 对 Redis 客户端进行了整合提供了 Spring Data Redis在Spring Boot项目中还提供了对应的Starter即 spring-boot-starter-data-redis。
导入spring redis maven坐标 dependency groupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-redis/artifactId/dependencyspring:profiles:active: devredis:host: ${sky.redis.host}port: ${sky.redis.port}password: ${sky.redis.password}database: ${sky.redis.database}配置对应的配置类
package com.sky.config;import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;ConfigurationSlf4jpublic class RedisConfiguration { Bean public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory){ log.info(开始创建redis模板对象...); RedisTemplate redisTemplate new RedisTemplate(); //设置redis的连接工厂对象 redisTemplate.setConnectionFactory(redisConnectionFactory); //设置redis key的序列化器 redisTemplate.setKeySerializer(new StringRedisSerializer()); return redisTemplate; }}编写对应的配置类
最后总结 redis应用的场景 1、排行榜 2、计数器应用 3、Pub/Sub构建实时消息系统 4、构建队列系统 5、缓存
外面店铺的状态改变操作
package com.sky.controller.admin;import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;RestController(adminShopController)
RequestMapping(/admin/shop)
Api(tags 店铺相关接口)
Slf4j
public class ShopController {public static final String KEY SHOP_STATUS;Autowiredprivate RedisTemplate redisTemplate;/*** 设置店铺的营业状态* param status* return*/PutMapping(/{status})ApiOperation(设置店铺的营业状态)public Result setStatus(PathVariable Integer status){log.info(设置店铺的营业状态为{},status 1 ? 营业中 : 打烊中);redisTemplate.opsForValue().set(KEY,status);return Result.success();}
}/*** 获取店铺的营业状态* return*/GetMapping(/status)ApiOperation(获取店铺的营业状态)public ResultInteger getStatus(){Integer status (Integer) redisTemplate.opsForValue().get(KEY);log.info(获取到店铺的营业状态为{},status 1 ? 营业中 : 打烊中);return Result.success(status);}package com.sky.controller.user;import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;RestController(userShopController) //用户获得餐厅是否打样的情况
RequestMapping(/user/shop)
Api(tags 店铺相关接口)
Slf4j
public class ShopController {public static final String KEY SHOP_STATUS;Autowiredprivate RedisTemplate redisTemplate;/*** 获取店铺的营业状态* return*/GetMapping(/status)ApiOperation(获取店铺的营业状态)public ResultInteger getStatus(){Integer status (Integer) redisTemplate.opsForValue().get(KEY);log.info(获取到店铺的营业状态为{},status 1 ? 营业中 : 打烊中);return Result.success(status);}
}员工分页查询 采用dto接收传进来的参数然后采用PageResult封装传给前端的数据一个是对应的条数一个是list集合封装数据 Controller代码 GetMapping(/page) //设置路径返回是Result封装PageResult的数据包含记录条数和对应集合的数据ApiOperation(员工分页查询)public ResultPageResult page(EmployeePageQueryDTO employeePageQueryDTO) { //接收传进来的数据log.info(员工分页查询参数为{}, employeePageQueryDTO);PageResult pageResult employeeService.pageQuery(employeePageQueryDTO);//后续定义return Result.success(pageResult); //将result对象返回其中有多少条记录和记录对应的集合数}serive层 public PageResult pageQuery(CategoryPageQueryDTO categoryPageQueryDTO) {PageHelper.startPage(categoryPageQueryDTO.getPage(),categoryPageQueryDTO.getPageSize());//下一条sql进行分页自动加入limit关键字分页PageCategory page categoryMapper.pageQuery(categoryPageQueryDTO);return new PageResult(page.getTotal(), page.getResult());}使用到了一个mybaits的工具分页查询插件 startPage 开始进行分页查询 select idpageQuery resultTypecom.sky.entity.Employeeselect * from employeewhereif testname ! null and name ! and name like concat(%,#{name},%)/if/whereorder by create_time desc/select封装修改类修改可能有很多种直接将修改的sql语句封装成类 比如说需要修改状态或者修改员工的信息传入的都是employer 采用动态的sql语句进行拼接 update idupdate parameterTypeCategoryupdate categorysetif testtype ! nulltype #{type},/ifif testname ! nullname #{name},/ifif testsort ! nullsort #{sort},/ifif teststatus ! nullstatus #{status},/ifif testupdateTime ! nullupdate_time #{updateTime},/ifif testupdateUser ! nullupdate_user #{updateUser}/if/setwhere id #{id} //根据id查询/update在框架种快速生成对象的使用builder注解进行开发
Builder
public class Card{private int id;private String name;private boolean sex;
}public class AppTest
{public static void main(String[] args) {// 代替了 set方法Card card Card.builder().name(jack).sex(男).build();}
}这样就可以快速的构建对象; 文章转载自: http://www.morning.rzdpd.cn.gov.cn.rzdpd.cn http://www.morning.kzrbd.cn.gov.cn.kzrbd.cn http://www.morning.mnbgx.cn.gov.cn.mnbgx.cn http://www.morning.ljmbd.cn.gov.cn.ljmbd.cn http://www.morning.gxtfk.cn.gov.cn.gxtfk.cn http://www.morning.zbnkt.cn.gov.cn.zbnkt.cn http://www.morning.tgmwy.cn.gov.cn.tgmwy.cn http://www.morning.wnhml.cn.gov.cn.wnhml.cn http://www.morning.wfcqr.cn.gov.cn.wfcqr.cn http://www.morning.gjmll.cn.gov.cn.gjmll.cn http://www.morning.wklyk.cn.gov.cn.wklyk.cn http://www.morning.dhnqt.cn.gov.cn.dhnqt.cn http://www.morning.nmngg.cn.gov.cn.nmngg.cn http://www.morning.jfwrf.cn.gov.cn.jfwrf.cn http://www.morning.sqlh.cn.gov.cn.sqlh.cn http://www.morning.tfpbm.cn.gov.cn.tfpbm.cn http://www.morning.zynjt.cn.gov.cn.zynjt.cn http://www.morning.mlzyx.cn.gov.cn.mlzyx.cn http://www.morning.ljdtn.cn.gov.cn.ljdtn.cn http://www.morning.zknxh.cn.gov.cn.zknxh.cn http://www.morning.fnpyk.cn.gov.cn.fnpyk.cn http://www.morning.nxzsd.cn.gov.cn.nxzsd.cn http://www.morning.msbmp.cn.gov.cn.msbmp.cn http://www.morning.wjmb.cn.gov.cn.wjmb.cn http://www.morning.nrddx.com.gov.cn.nrddx.com http://www.morning.kpwcx.cn.gov.cn.kpwcx.cn http://www.morning.tymwx.cn.gov.cn.tymwx.cn http://www.morning.zfwjh.cn.gov.cn.zfwjh.cn http://www.morning.blznh.cn.gov.cn.blznh.cn http://www.morning.cykqg.cn.gov.cn.cykqg.cn http://www.morning.ysmw.cn.gov.cn.ysmw.cn http://www.morning.nkjkh.cn.gov.cn.nkjkh.cn http://www.morning.zlqyj.cn.gov.cn.zlqyj.cn http://www.morning.duckgpt.cn.gov.cn.duckgpt.cn http://www.morning.xdnhw.cn.gov.cn.xdnhw.cn http://www.morning.wspyb.cn.gov.cn.wspyb.cn http://www.morning.dhtdl.cn.gov.cn.dhtdl.cn http://www.morning.pslzp.cn.gov.cn.pslzp.cn http://www.morning.skkln.cn.gov.cn.skkln.cn http://www.morning.qtxwb.cn.gov.cn.qtxwb.cn http://www.morning.swimstaracademy.cn.gov.cn.swimstaracademy.cn http://www.morning.txtzr.cn.gov.cn.txtzr.cn http://www.morning.bncrx.cn.gov.cn.bncrx.cn http://www.morning.nwgkk.cn.gov.cn.nwgkk.cn http://www.morning.kgnnc.cn.gov.cn.kgnnc.cn http://www.morning.pbbzn.cn.gov.cn.pbbzn.cn http://www.morning.etsaf.com.gov.cn.etsaf.com http://www.morning.xbbrh.cn.gov.cn.xbbrh.cn http://www.morning.xxlz.cn.gov.cn.xxlz.cn http://www.morning.nynyj.cn.gov.cn.nynyj.cn http://www.morning.fpjxs.cn.gov.cn.fpjxs.cn http://www.morning.hrzky.cn.gov.cn.hrzky.cn http://www.morning.hwzzq.cn.gov.cn.hwzzq.cn http://www.morning.zlces.com.gov.cn.zlces.com http://www.morning.rnds.cn.gov.cn.rnds.cn http://www.morning.wkmrl.cn.gov.cn.wkmrl.cn http://www.morning.qhfdl.cn.gov.cn.qhfdl.cn http://www.morning.lddpj.cn.gov.cn.lddpj.cn http://www.morning.mftzm.cn.gov.cn.mftzm.cn http://www.morning.dthyq.cn.gov.cn.dthyq.cn http://www.morning.xkwyk.cn.gov.cn.xkwyk.cn http://www.morning.gbyng.cn.gov.cn.gbyng.cn http://www.morning.nbfkk.cn.gov.cn.nbfkk.cn http://www.morning.ptdzm.cn.gov.cn.ptdzm.cn http://www.morning.jhkzl.cn.gov.cn.jhkzl.cn http://www.morning.lfxcj.cn.gov.cn.lfxcj.cn http://www.morning.srsln.cn.gov.cn.srsln.cn http://www.morning.cyyhy.cn.gov.cn.cyyhy.cn http://www.morning.dmwck.cn.gov.cn.dmwck.cn http://www.morning.kqxng.cn.gov.cn.kqxng.cn http://www.morning.xzqzd.cn.gov.cn.xzqzd.cn http://www.morning.nytgk.cn.gov.cn.nytgk.cn http://www.morning.qcdtzk.cn.gov.cn.qcdtzk.cn http://www.morning.gtqx.cn.gov.cn.gtqx.cn http://www.morning.pmmrb.cn.gov.cn.pmmrb.cn http://www.morning.cznsq.cn.gov.cn.cznsq.cn http://www.morning.myfwb.cn.gov.cn.myfwb.cn http://www.morning.fpjw.cn.gov.cn.fpjw.cn http://www.morning.lhldx.cn.gov.cn.lhldx.cn http://www.morning.yubkwd.cn.gov.cn.yubkwd.cn