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

最专业的企业营销型网站建设价格石家庄免费做网站

最专业的企业营销型网站建设价格,石家庄免费做网站,高密网站开发,网站做半透明度的优势安装Redis使用yum命令#xff0c;直接将redis安装到linux服务器#xff1a;yum -y install redis启动redis使用以下命令#xff0c;以后台运行方式启动redis#xff1a;redis -server /etc/redis.conf 操作redis使用以下命令启动redis客户端#xff1a;redis-cli设置…安装Redis使用yum命令直接将redis安装到linux服务器yum -y install redis启动redis使用以下命令以后台运行方式启动redisredis -server /etc/redis.conf 操作redis使用以下命令启动redis客户端redis-cli设置远程连接1. 将 redis 配置文件下载到本地redis 配置文件是 linux 下的 /etc/redis.conf 2. 将 redis.conf 中的 “bind 127.0.0.1”注释掉3. 将 redis.conf 中的“protected-mode yes” 改为“protected-mode no”4. 将修改后的 redis.conf 上传至 liunx 下的 /etc 目录5. 使用命令“redis-cli shutdown”先关闭 redis 服务再使用“redis-server /etc/redis.conf ”启动 redis 服务注意在连接redis终端的之前一定要开放安全组SpringBoot集成Redis1.添加redis依赖或者是在pom.xml文件中配置一下依赖dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-redis/artifactId /dependency2.配置Redis(主要是配置前三个)spring.redis.database0 spring.redis.port6379 spring.redis.host82.157.146.10 spring.redis.lettuce.pool.min-idle5 spring.redis.lettuce.pool.max-idle10 spring.redis.lettuce.pool.max-active8 spring.redis.lettuce.pool.max-wait1ms spring.redis.lettuce.shutdown-timeout100ms3.操作Redis操作字段package com.example.demo.controller;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Controller; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;RestController public class RedisController {Autowiredprivate StringRedisTemplate stringRedisTemplate;/*** 将字符串存贮到redis* param key* param value* return*/RequestMapping(/setredis)public String setRedis(String key,String value){if(StringUtils.hasLength(key) StringUtils.hasLength(value)){//在redis中存储数据stringRedisTemplate.opsForValue().set(key,value);return 设置成功;}else{return 请检查输入的值是否正确;}}/*** 从redis中获取对象* param key* return*/RequestMapping(/getredis)public String getRedis(String key){if(StringUtils.hasLength(key)){//获取redis中的valueString s stringRedisTemplate.opsForValue().get(key);return s;}else{return 获取失败;}} } 结果操作对象package com.example.demo.model;import lombok.Data;Data public class User {private int id;private String name;private String password; }package com.example.demo.controller;import com.example.demo.model.User; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Controller; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;RestController public class RedisController {private User user;private final String object_redis_key user_1;Autowiredprivate ObjectMapper objectMapper;Autowiredprivate StringRedisTemplate stringRedisTemplate;/*** 使用双重效验锁来构建一个单例 user 对象*/public User getUser(){if(user null){synchronized (this){if(user null){user new User();user.setId(1);user.setName(韩梅梅);user.setPassword(123);}}}return user;}/*** 讲对象存储到redis中* return*/RequestMapping(/setobj)public String setObj() throws JsonProcessingException {User user getUser();String userStr objectMapper.writeValueAsString(user);stringRedisTemplate.opsForValue().set(object_redis_key,userStr);return 操作成功!;}RequestMapping(/getobj)public User getObj() throws JsonProcessingException {String userStr stringRedisTemplate.opsForValue().get(object_redis_key);User user objectMapper.readValue(userStr, User.class);return user;} } 结果使用字典的方式来存储redis的优点可以获取单个值节省带宽。缺点是存取写起来程序都比较麻烦。Session的持久化创建项目添加依赖 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-redis/artifactId/dependencydependencygroupIdorg.springframework.session/groupIdartifactIdspring-session-data-redis/artifactId/dependency修改配置spring.session.store-typeredis server.servlet.session.timeout1800 spring.session.redis.flush-modeon_save spring.session.redis.namespacespring:session spring.redis.host82.157.14.10 spring.redis.password spring.redis.port6379存储和读取代码package com.example.demo.model;import lombok.Data;import java.io.Serializable;Data public class User implements Serializable {private int id;private String username;private String password; } package com.example.demo.controller;import com.example.demo.model.User; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession;RestController public class UserController {private final String user_session_key session_1;RequestMapping(/login)public boolean login(HttpSession session){// ... 省去验证过程User user new User();user.setId(1);user.setUsername(王五);user.setPassword(123);session.setAttribute(user_session_key,user);return true;}RequestMapping(/getsess)public User getSess(HttpServletRequest request){HttpSession session request.getSession(false);if(session ! null){return (User) session.getAttribute(user_session_key);}return null;} } 上面的操作表示已经将session存储到redis中了这是即使重启程序输入相应的路由也能读取redis中的数据这时如果将redis中的session信息删除掉再去获得session就获取不到了
http://www.hkea.cn/news/14350316/

相关文章:

  • 2017两学一做网站网店设计作用有哪些
  • 网站开发内容怎么写南京制作网站
  • 网站建设很简单百度浏览器app
  • 微网站页面菜单栏如何自己做解析网站
  • 做的好的有哪些网站云畅网站建设后台
  • 博物建设公司网站如今做那个网站致富
  • 动漫网站logo企业网站怎么做排名
  • wordpress国内网站网络营销网站 功能
  • 做不做生意都要知道的网站新注册的公司怎么做网站
  • 深圳建站工作室wordpress中如何添加面包屑
  • 电影网站开发现状推广普通话宣传内容
  • 上海网站建设不好苏州微信网站建设
  • 帮做钓鱼网站会怎样wordpress博客百度收录
  • 自己编写网站wordpress 调用文章摘要
  • 山东专业网站建设公司哪家好鞍山玉佛苑玉佛图片
  • 唐山市做网站几种语言的网站如何做
  • 做网站 学什么重要新闻头条
  • 2016做网站百度号码认证平台个人号码申诉
  • 深圳网站建设ejaket更改wordpress链接数据库
  • 网站制作与网站设计郑州做优化的公司有哪些
  • 工艺品网站怎么做自己建网站买玩具
  • 唐山住房和城乡建设网站今天重大新闻摘抄
  • 网站流量转换做网页和网站一样吗
  • 网店的网站设计方案广州网站建设服务
  • 安卓做网站教程做网站推广的公司
  • 旅游手机网站开发网站开发模板教务管理
  • 网站式小程序幸福人寿保险公司官方网站
  • 弹出网站代码网站运营托管咨询
  • 网站栏目建设需求的通知青岛建网站需要花多少钱
  • 大佬做的魔法少女网站渭南网站建设服务