Skip to content

Commit

Permalink
cache function finished
Browse files Browse the repository at this point in the history
  • Loading branch information
dufyun committed Jul 17, 2018
1 parent c1b34ce commit 39a0d7d
Show file tree
Hide file tree
Showing 16 changed files with 913 additions and 26 deletions.
80 changes: 79 additions & 1 deletion learn-sitech-project/cache-to-file-db/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<artifactId>druid</artifactId>
</dependency>

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>

<dependency>
<groupId>org.mybatis</groupId>
Expand Down Expand Up @@ -71,10 +75,84 @@
<artifactId>hutool-all</artifactId>
</dependency>

<!--spring redis jar-->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
</dependency>

<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.4.2</version>
<scope>compile</scope>
</dependency>
<!--spring redis jar-->

<!--jackson-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-base</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
</dependency>

</dependencies>

<build>

<finalName>cache-to-file-db</finalName>
<plugins>

<plugin>
<!-- MAVEN 编译使用的JDK版本 -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version><!-- 可解决一个类报错打不了包的问题 -->
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>

</plugins>
<!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->
<resources>
<resource>
Expand Down
27 changes: 20 additions & 7 deletions learn-sitech-project/cache-to-file-db/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,27 @@ User{id=3, userName='dufy', password='123456', age=25}
User{id=4, userName='github', password='123456', age=10}
````

3. 缓存相关的配置


4. 日志入库文件的扫描和转移


5. 读取文件数据并进行入库操作
- (1)添加对应的jar ,jedis 、spring-data-redis等
- (2)添加cache对应的配置文件,既spring-cache.xml
- (3)添加`RedisClientTemplate` redis操作工具类
- (4)进行测试,`org.dufy.cache.RedisClientTemplateTest`
4. 设计缓存的入库缓存保存的key
两种方式:
- (1)使用String
> key=user:id
> value=json(user).toString
- (2)使用Hash
> key=user:id
> key "name" "dufy"
> key "age" 25
注: 需要redis配置集群,可参考[Redis创建高可用集群教程【Windows环境】](https://blog.csdn.net/u010648555/article/details/79427608)

5. 日志入库文件的扫描和转移


6. 读取文件数据并进行入库操作



Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.dufy.cache;

/**
* 缓存的常量
*
* @author:dufyun
* @version:1.0.0
* @date 2018/7/16
* @update:[日期YYYY-MM-DD] [更改人姓名][变更描述]
*/
public interface CacheConstants {

public static final int expire_day = 24 * 60 * 60;
/**
* 缓存key user:id
*/
public static final String USER_KEY = "user:";


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.dufy.cache;

import org.dufy.model.User;

/**
* 用户缓存接口类
*
* @author:dufyun
* @version:1.0.0
* @date 2018/7/16
* @update:[日期YYYY-MM-DD] [更改人姓名][变更描述]
*/
public interface IUserCache {

/**
* string set user
* @param user
*/
public void setUser(User user);

/**
* string get user
* @param id
* @return
*/
public User getUser(String id);

/**
* hset user
* @param user
*/
public void hsetUser(User user);

/**
* hget user
* @param id
* @return
*/
public User hgetUser(String id);

}
Loading

0 comments on commit 39a0d7d

Please sign in to comment.