Redis相关

Redis相关

Redis

使用场景

  1. 数据库缓存,减轻服务器压力,提高系统响应。当系统访问量太大,数据库压力增大,使用redis将访问过的内容或者数据存储起来,再次访问的时候先找缓存,缓存命中返回数据,不命中再找数据库,并回填数据。
  2. session分离。集群或者分布式环境不同web容器管理自己的session,自带的session共享通过网络和IO进行同步,极大地影响性能。
  3. 实现分布式锁。sexNX
  4. 实现乐观锁。watch+incr
阅读更多
MyBatis分析

MyBatis分析

MyBatis

mybatis相比较传统jdbc

  1. 传统数据库配置信息存在硬编码,包括sql语句,设置参数,获取结果集需要手动封装结果集,较为繁琐。

  2. 需要频繁创建数据库连接。

阅读更多
io模型

io模型

I/O网络

阻塞与非阻塞

阻塞:访问IO的线程是否会阻塞(等待)。

同步和异步

数据的请求方式。

  • 同步会等待资源返回的结果。

  • 异步通过回调的方式获取返回的结果

BIO

同步阻塞。传统的socket编程,实现模式为一个连接一个线程,客户端有连接请求时服务器就启动一个线程处理,如果这个连接不做任何事情就会造成不必要的线程开销,可以通过线程池改善(实现多个客户端连接服务器)。

BIO
阅读更多
Filter

Filter

传统 JavaWeb

新建过滤器

引入 tomcat-jarservlet-api.jar,新建过滤器如下

阅读更多

SpringCache

Configuration

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  @Bean
public CacheManager cacheManager(RedisConnectionFactory factory) {
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
.serializeKeysWith(
RedisSerializationContext.SerializationPair.fromSerializer(RedisSerializer.string()))
.serializeValuesWith(
RedisSerializationContext.SerializationPair.fromSerializer(serializer()))
.disableCachingNullValues()
//replace double colons to single colons
// .computePrefixWith(cacheName -> cacheName+":")
.entryTtl(getDuration());

return RedisCacheManager
.builder(factory)
.cacheDefaults(config)
.build();
}
阅读更多

Stream

转集合

1
List<String> strList=list.stream.map(T::get).collect(Collectors.toList);

根据分类分组

1
2
3
4
5
6
7
List<AppModel> list=new ArrayList<>();
Map<String, List<AppModel>> groupByCategoryList = appModelList
.stream()
.collect(
Collectors
.groupingBy(AppModel::getModelCategory)
);
阅读更多

Jackson正反序列化

  • 范例1:List<T>
  • 范例1:List<Map<String, T>>
  • 范例2:Map<String, List<T>>
1
2
3
4
5
6
//先构造Map<String,Person>得到innerType,第一个参数为外层对象HashMap,第二个参数为String,第三个参数为Person
JavaType innerType = mapper.getTypeFactory().constructParametricType(HashMap.class, String.class, Person.class);
//再构造List<innerType>
JavaType resultType = mapper.getTypeFactory().constructParametricType(ArrayList.class, innerType);
//反序列化
List<Map<String, Person>> result2 = mapper.readValue(s, resultType);

ELK记录

Filebeat

1
./filebeat -e -c filebeat.yml -d "publish"

https://www.elastic.co/guide/en/beats/filebeat/7.8/filebeat-starting.html

Logstash

1
./logstash -f ../config/logstash-sample.conf  --config.reload.automatic

https://www.elastic.co/guide/en/logstash/current/advanced-pipeline.html

格式

1
2
3
2020-07-21 09:15:38,001 INFO [quartzScheduler_Worker-3] c.g.j.modules.quartz.jobs.SampleJob [SampleJob.java : 20] 定时任务! 时间:2020-07-21 09:15:38

%{TIMESTAMP_ISO8601} %{LOGLEVEL:loglevel} \[%{DATA:thread}\] %{JAVACLASS:class} \[%{JAVAFILE:file} (?:: %{BASE10NUM:line})?\] %{GREEDYDATA:msg}

elasticsearch

查看索引信息

curl -XGET 'http://localhost:9200/_cluster/health?pretty=true'

查看所有索引状态

curl 'localhost:9200/_cat/indices?v'

删除索引

curl -XDELETE http://localhost:9200/index_namee

https://www.cnblogs.com/zhangb8042/articles/11346085.html

nohup ./kibana >/dev/null 2>&1 &

nohup ./elasticsearch >/dev/null 2>&1 &

nohup ./logstash -f ../config/logstash-sample.conf --config.reload.automatic >/dev/null 2>&1 &

Tomcat-APR

Tomcat-APR

SpringBoot 内置 Tomcat 启用 APR(Linux)

准备文件

  • apr-1.7.0.tar.gz

  • apr-util-1.6.1.tar.gz

  • apr-iconv-1.2.2.tar.gz

    Apache 官网下载 开启 APR 所需文件

阅读更多
MySQL记录

MySQL记录

建库授权

1
2
3
4
CREATE DATABASE IF NOT EXISTS gunslite DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'gunslite'@'%' IDENTIFIED BY 'gunslite123';
GRANT ALL privileges ON gunslite.* TO 'gunslite'@'%';
flush privileges;

字符集相关

  • 查看表字段字符集

    1
    SHOW FULL COLUMNS FROM process_model;
阅读更多
Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×