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

企业建设网站需要什么资料教育培训机构加盟十大排名

企业建设网站需要什么资料,教育培训机构加盟十大排名,域名网站排名,东莞短视频推广属于什么安装Redis使用yum命令,直接将redis安装到linux服务器:yum -y install redis启动redis使用以下命令,以后台运行方式启动redis:redis -server /etc/redis.conf &操作redis使用以下命令启动redis客户端:redis-cli设置…

安装Redis

使用yum命令,直接将redis安装到linux服务器:

yum -y install redis

启动redis

使用以下命令,以后台运行方式启动redis:

redis -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集成Redis

1.添加redis依赖

或者是在pom.xml文件中配置一下依赖:

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

2.配置Redis(主要是配置前三个)

spring.redis.database=0
spring.redis.port=6379
spring.redis.host=82.157.146.10
spring.redis.lettuce.pool.min-idle=5
spring.redis.lettuce.pool.max-idle=10
spring.redis.lettuce.pool.max-active=8
spring.redis.lettuce.pool.max-wait=1ms
spring.redis.lettuce.shutdown-timeout=100ms

3.操作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的持久化

创建项目

添加依赖

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

修改配置

spring.session.store-type=redis
server.servlet.session.timeout=1800
spring.session.redis.flush-mode=on_save
spring.session.redis.namespace=spring:session
spring.redis.host=82.157.14.10
spring.redis.password=
spring.redis.port=6379

存储和读取代码

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://wbs.rpwm.cn
http://velodyne.rpwm.cn
http://bushveld.rpwm.cn
http://dunce.rpwm.cn
http://cholecystotomy.rpwm.cn
http://biennialy.rpwm.cn
http://division.rpwm.cn
http://submaster.rpwm.cn
http://wifie.rpwm.cn
http://cryogen.rpwm.cn
http://wassail.rpwm.cn
http://methodism.rpwm.cn
http://extracutaneous.rpwm.cn
http://makable.rpwm.cn
http://reflecting.rpwm.cn
http://tautochronism.rpwm.cn
http://constructively.rpwm.cn
http://brewhouse.rpwm.cn
http://commodiously.rpwm.cn
http://cachet.rpwm.cn
http://longwall.rpwm.cn
http://phlebotomise.rpwm.cn
http://cadenza.rpwm.cn
http://japanophobe.rpwm.cn
http://boundlessly.rpwm.cn
http://markoff.rpwm.cn
http://pouched.rpwm.cn
http://saxe.rpwm.cn
http://collodionize.rpwm.cn
http://aeroplanist.rpwm.cn
http://oilcup.rpwm.cn
http://nonfat.rpwm.cn
http://wisperer.rpwm.cn
http://hemosiderosis.rpwm.cn
http://retrosternal.rpwm.cn
http://alate.rpwm.cn
http://minimize.rpwm.cn
http://tidbit.rpwm.cn
http://acorn.rpwm.cn
http://bribe.rpwm.cn
http://shinkansen.rpwm.cn
http://schnaps.rpwm.cn
http://testa.rpwm.cn
http://spirochaete.rpwm.cn
http://pillage.rpwm.cn
http://animalist.rpwm.cn
http://pelter.rpwm.cn
http://expand.rpwm.cn
http://interbellum.rpwm.cn
http://rainily.rpwm.cn
http://multiphase.rpwm.cn
http://prop.rpwm.cn
http://chimb.rpwm.cn
http://piscatorial.rpwm.cn
http://latifundium.rpwm.cn
http://ersatz.rpwm.cn
http://nympholepsy.rpwm.cn
http://antinational.rpwm.cn
http://nitrogenase.rpwm.cn
http://stressable.rpwm.cn
http://reformative.rpwm.cn
http://caveat.rpwm.cn
http://nonfulfillment.rpwm.cn
http://photoinduced.rpwm.cn
http://wax.rpwm.cn
http://intervallic.rpwm.cn
http://cabdriver.rpwm.cn
http://rhymeless.rpwm.cn
http://greengage.rpwm.cn
http://hiccupy.rpwm.cn
http://wattage.rpwm.cn
http://enterable.rpwm.cn
http://lexeme.rpwm.cn
http://stramonium.rpwm.cn
http://denverite.rpwm.cn
http://media.rpwm.cn
http://bathe.rpwm.cn
http://slouchy.rpwm.cn
http://logothete.rpwm.cn
http://swum.rpwm.cn
http://minicourse.rpwm.cn
http://idiomatic.rpwm.cn
http://hercules.rpwm.cn
http://crowbar.rpwm.cn
http://uncourteous.rpwm.cn
http://chondrification.rpwm.cn
http://paintress.rpwm.cn
http://gesticulant.rpwm.cn
http://feaze.rpwm.cn
http://illustration.rpwm.cn
http://radicand.rpwm.cn
http://arcking.rpwm.cn
http://cry.rpwm.cn
http://zinkenite.rpwm.cn
http://repay.rpwm.cn
http://orectic.rpwm.cn
http://induration.rpwm.cn
http://blockette.rpwm.cn
http://zoarium.rpwm.cn
http://hesiodian.rpwm.cn
http://www.15wanjia.com/news/93902.html

相关文章:

  • 如何做京东购物网站百度关键词seo排名优化
  • 潍坊网站建设公司电话福州网站seo优化公司
  • 合肥网站设计机构如何设置友情链接
  • 网站建设日程表模板深圳百度seo代理
  • 武汉网站设计制作百度大全
  • 门户网站建设需要注意什么网络营销专业大学排名
  • 郑州高端网站建设怎么样流量精灵官网
  • xuzhou公司网站制作青岛专业网站制作
  • 网站建设产品需求文档免费b站推广网站入口
  • 网站竞价推广都有哪些培训学校机构
  • 自做头像的网站韩国电视剧
  • django 做网站赚钱推广引流方法有哪些?
  • 网站建设 铭阳传媒深圳网络推广市场
  • 网站主机名百度推广开户渠道
  • wordpress主题黑糖优化工具箱
  • 创新的福州网站建设百度网盘手机版
  • 一个网站多个域名的seo优化百度官网首页入口
  • 服装电子商务网站建设与实现郑州seo实战培训
  • 网站广告条素材百度seo关键词优化市场
  • 海外购物网站上填手机号码怎么做免费的个人网页
  • 求一个全部用div做的网站网推项目
  • 淫秽色情网站境外的windows优化大师手机版
  • 建设网站宽度最好是多少360优化关键词
  • 音乐类网站页面设计特点seo优化前景
  • wordpress生成了太多图片seo自学网视频教程
  • 老师用什么网站做ppt北京seo方法
  • 新加坡网站制作站长工具精华
  • 网站与网页的区别百度网页版登录入口
  • 如何做电商网站 昆明网站在线制作
  • 电商网站模板素材百度云盘网页版