Commit a35cbcda authored by 李丛阳's avatar 李丛阳

redis

parent 13c4bfb2
......@@ -91,6 +91,13 @@
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!--spring boot redis starter-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!--spring boot mybatis starter-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
......
package org.rcisoft.config;
import lombok.extern.slf4j.Slf4j;
import org.rcisoft.core.bean.RcRedisConfigBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import static sun.jvm.hotspot.oops.CellTypeState.addr;
/**
* Created by lcy on 18/1/8.
*/
@Configuration
@Slf4j
public class RedisConfig {
@Autowired
private RcRedisConfigBean redisConfigBean;
@Bean
public JedisPool getJedisPool(){
JedisPoolConfig config = new JedisPoolConfig();
//连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true
config.setBlockWhenExhausted(true);
//设置的逐出策略类名, 默认DefaultEvictionPolicy(当连接超过最大空闲时间,或连接数超过最大空闲连接数)
config.setEvictionPolicyClassName("org.apache.commons.pool2.impl.DefaultEvictionPolicy");
//是否启用pool的jmx管理功能, 默认true
config.setJmxEnabled(true);
//MBean ObjectName = new ObjectName("org.apache.commons.pool2:type=GenericObjectPool,name=" + "pool" + i); 默认为"pool", JMX不熟,具体不知道是干啥的...默认就好.
config.setJmxNamePrefix("pool");
//是否启用后进先出, 默认true
config.setLifo(false);
//最大空闲连接数, 默认8个
config.setMaxIdle(redisConfigBean.getMaxIdle());
//最大连接数, 默认8个
config.setMaxTotal(redisConfigBean.getMaxActive());
//获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1
config.setMaxWaitMillis(redisConfigBean.getMaxWait());
//逐出连接的最小空闲时间 默认1800000毫秒(30分钟)
config.setMinEvictableIdleTimeMillis(1800000);
//最小空闲连接数, 默认0
config.setMinIdle(0);
//每次逐出检查时 逐出的最大数目 如果为负数就是 : 1/abs(n), 默认3
config.setNumTestsPerEvictionRun(3);
//对象空闲多久后逐出, 当空闲时间>该值 且 空闲连接>最大空闲数 时直接逐出,不再根据MinEvictableIdleTimeMillis判断 (默认逐出策略)
config.setSoftMinEvictableIdleTimeMillis(1800000);
//在获取连接的时候检查有效性, 默认false
config.setTestOnBorrow(false);
//在空闲时检查有效性, 默认false
config.setTestWhileIdle(false);
//逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认-1
config.setTimeBetweenEvictionRunsMillis(-1);
JedisPool pool = new JedisPool(config,redisConfigBean.getHost(),redisConfigBean.getPort(),
redisConfigBean.getTimeout(),null,redisConfigBean.getDatabase());
log.info("init JedisPool ...");
return pool;
}
}
......@@ -24,6 +24,15 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic
@EnableGlobalMethodSecurity(prePostEnabled = true) //开启prePostEnabled注解支持
public class SecurityConfig extends WebSecurityConfigurerAdapter {
/**
* 前置过滤器
* @return
*/
@Autowired
JwtAuthenTokenFilter jwtAuthenTokenFilter;
@Autowired
private UserDetailsService jwtUserDetailServiceImpl;
......@@ -51,14 +60,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
return new JwtBean();
}
/**
* 前置过滤器
* @return
*/
@Bean
JwtAuthenTokenFilter authenticationTokenFilterBean(){
return new JwtAuthenTokenFilter();
}
@Override
......@@ -94,9 +96,10 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.authenticationEntryPoint(new RestAuthenticationEntryPoint())
;
http //添加前置过滤器
.addFilterBefore(authenticationTokenFilterBean(), UsernamePasswordAuthenticationFilter.class);
.addFilterAfter(jwtAuthenTokenFilter, UsernamePasswordAuthenticationFilter.class);
http //禁用header缓存
.headers().cacheControl();
}
}
package org.rcisoft.core.bean;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* Created by lcy on 18/1/8.
*/
@Component
@ConfigurationProperties(prefix = "spring.redis")
@Data
public class RcRedisConfigBean {
private String host;
private int port;
private String password;
private int timeout;
private int database;
@Value("${spring.redis.pool.max-idle:100}")
private int maxIdle;
@Value("${spring.redis.pool.max-active:100}")
private int maxActive;
@Value("${spring.redis.pool.min-idle:1}")
private int minIdle;
@Value("${spring.redis.pool.max-wait:-1}")
private int maxWait;
}
......@@ -9,6 +9,7 @@ import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain;
......@@ -21,6 +22,7 @@ import java.io.IOException;
* Created by lcy on 17/11/21.
*/
@Slf4j
@Component
public class JwtAuthenTokenFilter extends OncePerRequestFilter {
@Value("${jwt.header}")
......
package org.rcisoft.core.service;
import redis.clients.jedis.Jedis;
/**
* Created by lcy on 18/1/8.
*/
public interface RcRedisService {
public Jedis getResource();
public void returnResource(Jedis jedis);
public void set(String key, String value);
public String get(String key);
}
package org.rcisoft.core.service.impl;
import lombok.extern.slf4j.Slf4j;
import org.rcisoft.core.service.RcRedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
/**
* Created by lcy on 18/1/8.
*/
@Service
@Slf4j
public class RcRedisServiceImpl implements RcRedisService {
@Autowired
private JedisPool jedisPool;
@Override
public Jedis getResource() {
return jedisPool.getResource();
}
@SuppressWarnings("deprecation")
@Override
public void returnResource(Jedis jedis) {
if(jedis != null){
jedisPool.returnResourceObject(jedis);
}
}
@Override
public void set(String key, String value) {
Jedis jedis=null;
try{
jedis = getResource();
jedis.set(key, value);
log.info("Redis set success - " + key + ", value:" + value);
} catch (Exception e) {
e.printStackTrace();
log.error("Redis set error: "+ e.getMessage() +" - " + key + ", value:" + value);
}finally{
returnResource(jedis);
}
}
@Override
public String get(String key) {
String result = null;
Jedis jedis=null;
try{
jedis = getResource();
result = jedis.get(key);
log.info("Redis get success - " + key + ", value:" + result);
} catch (Exception e) {
e.printStackTrace();
log.error("Redis set error: "+ e.getMessage() +" - " + key + ", value:" + result);
}finally{
returnResource(jedis);
}
return result;
}
}
server:
port: 8081
context-path: /edu #ContextPath must start with '/' and not end with '/'
#context-path: /edu #ContextPath must start with '/' and not end with '/'
tomcat:
max-threads: 300
#uri-encoding: UTF-8
......@@ -11,9 +11,9 @@ server:
# org.springframework.web: DEBUG
druid:
url: jdbc:mysql://127.0.0.1:3306/edu_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
url: jdbc:mysql://127.0.0.1:3306/edu_db?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false
username: root
password: root
password: cy
initial-size: 1
min-idle: 1
max-active: 20
......@@ -53,6 +53,17 @@ spring:
throw-exception-if-no-handler-found: true
resources:
add-mappings: false
redis:
host: 106.2.3.134
port: 7481
pool:
max-idle: 50
max-active: 1000
min-idle: 5
max-wait: -1
database: 0
password: ''
springfox:
......@@ -102,7 +113,7 @@ global:
min_password: 6
max_password: 16
path:
base_upload_server_location: E:\\eduFiles
base_upload_server_location: /working/resource/eduServer/
course_location: course
lesson_location: lesson
sl_location: sl
......
......@@ -53,6 +53,16 @@ spring:
throw-exception-if-no-handler-found: true
resources:
add-mappings: false
redis:
host: 106.2.3.134
port: 7481
pool:
max-idle: 50
max-active: 1000
min-idle: 5
max-wait: -1
database: 0
password: ''
springfox:
......
......@@ -45,6 +45,46 @@
|images|(轮播图)
|default|
# 容器
## 容器编排
### html 工程
> 无node grunt 环境
镜像 httpd:2.4
1. apache容器
2. 端口分配 [12000-22000]
### java 工程
> 包括maven 环境
镜像 maven:3.5-ibmjava-8
mysql
1. jdk8的环境
2. maven环境映射
## 容器存储
|eduLxc|
|userId|
|docker-compose.yml|
## redis
存储方案
~~~~
{
lessonLxc:{
userid:{
"containerId":"",
"expiredMin":23,
"startDate":"2017-02-11 12:23:11",
"shutdownDate":"2017-02-11 12:53:11",
"sl":"",
"code":"1001"
}
}
}
~~~~
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment