0%

以下涉及到的源码均为redis5.0-rc3版本的代码【点击查看官方源码

整数集合

整数集合(intset),故名思意,是存放整数的集合数据结构,从而可知其是集合(Set)的底层实现之一。而从源码中可知,整数集合中的元素又是从小到大来排序的。

数据结构

整数集合的定义在源码头文件intset.h中,如下所示:

1
2
3
4
5
typedef struct intset {
uint32_t encoding;
uint32_t length;
int8_t contents[];
} intset;
  • encoding:当前结构内所有元素的类型,如int8_t,int16_t,int32_t,int64_t;
  • length:contents数组中元素的个数,也即一个整数集合中存储的元素的个数;
  • contents[]:存放元素的数组;
Read more »

以下涉及到的源码均为redis5.0-rc3版本的代码【点击查看官方源码

Redis字典

字典是一个key-value形式的数据结构,使用过java中map结构的都应该了解,因为其也是字典;而了解哈希表的也应该不会陌生,因为字典的底层就是哈希表。而redis本身就是一个key-value形式的nosql数据库,足以见得字典结构在redis中的地位。

数据结构

字典的定义是在redis源码中的dict.h头文件中,其底层是由哈希表构成。

Read more »

以下涉及到的源码均为redis5.0-rc3版本的代码【点击查看官方源码

SDS简介

简单动态字符串(simple dynamic string),是redis底层为字符串而设计的一种数据结构,是针对C字符串的一个改良版。凡是涉及到需要修改的字符串均采用sds来存储,而非C字符串。

Read more »

maven构建的项目中默认的java版本是1.5,并且我们在项目属性里面更改了之后,

在maven-update project后又会变成默认的1.5版本,甚为烦恼。

下面提供解决方法:

Read more »

找到我们自己设置的maven的本地仓库的settings.xml文件,在镜像标签中更改默认下载依赖的路径,如用阿里云的镜像仓库地址,当然也可以选用其他的地址。

1
2
3
4
5
6
<mirror>  
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>

maven打jar包时,很容易漏掉依赖,因此需要将所有的依赖集中起来,在pom文件中做如下配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.test.main.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compile.plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

maven项目管理中,分环境(开发、测试、生产)打包是在所难免的事情,只需要在pom文件中做一些配置。

首先是配置profiles(此处设置develop为默认环境):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!-- project environment -->
<profiles>
<profile>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<id>develop</id>
<properties>
<package.environment>develop</package.environment>
</properties>
</profile>
<profile>
<id>product</id>
<properties>
<package.environment>product</package.environment>
</properties>
</profile>
</profiles>
Read more »

ufw

ufw(Uncomplicated Firewall)是ubuntu默认的防火墙配置工具,其屏蔽了iptables的复杂操作方式,提供了非常友好的方式去配置规则。 一般情况下都会是默认安装的,若没有安装则可以输入如下命令进行安装:

1
apt install ufw
Read more »