-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
09718d7
commit df7d2d4
Showing
12 changed files
with
535 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# SpringBoot Starter | ||
|
||
|
||
## Usage | ||
|
||
Add dependency | ||
```xml | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.github.dengliming.redismodule</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
<version>2.0.4-SNAPSHOT</version> | ||
</dependency> | ||
</dependencies> | ||
``` | ||
|
||
RedisJSON | ||
```yaml | ||
redis-module: | ||
enabled: true | ||
redisjson: | ||
enabled: true | ||
config: | | ||
singleServerConfig: | ||
idleConnectionTimeout: 10000 | ||
connectTimeout: 10000 | ||
timeout: 3000 | ||
retryAttempts: 3 | ||
retryInterval: 1500 | ||
password: null | ||
subscriptionsPerConnection: 5 | ||
clientName: null | ||
address: "redis://127.0.0.1:6379" | ||
subscriptionConnectionMinimumIdleSize: 1 | ||
subscriptionConnectionPoolSize: 50 | ||
connectionMinimumIdleSize: 24 | ||
connectionPoolSize: 64 | ||
database: 0 | ||
dnsMonitoringInterval: 5000 | ||
threads: 16 | ||
nettyThreads: 32 | ||
codec: !<org.redisson.codec.Kryo5Codec> {} | ||
transportMode: "NIO" | ||
``` | ||
Use in Spring | ||
```java | ||
@Autowired(required = false) | ||
private RedisJSONClient redisJSONClient; | ||
|
||
public void test() { | ||
RedisJSON redisJSON = redisJSONClient.getRedisJSON(); | ||
String key = "foo"; | ||
redisJSON.set(key, SetArgs.Builder.create(".", "\"bar\"")); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.github.dengliming.redismodule</groupId> | ||
<artifactId>redis-modules-java</artifactId> | ||
<version>2.0.4-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>spring-boot-starter</artifactId> | ||
<name>SpringBootStarter</name> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-dependencies</artifactId> | ||
<version>${spring-boot.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-autoconfigure</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-configuration-processor</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.junit.vintage</groupId> | ||
<artifactId>junit-vintage-engine</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.github.dengliming.redismodule</groupId> | ||
<artifactId>commons</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.github.dengliming.redismodule</groupId> | ||
<artifactId>all</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
145 changes: 145 additions & 0 deletions
145
...dengliming/redismodule/springboot/starter/autoconfigure/RedisModuleAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/* | ||
* Copyright 2024 dengliming. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.github.dengliming.redismodule.springboot.starter.autoconfigure; | ||
|
||
import io.github.dengliming.redismodule.redisai.client.RedisAIClient; | ||
import io.github.dengliming.redismodule.redisbloom.client.RedisBloomClient; | ||
import io.github.dengliming.redismodule.redisearch.client.RediSearchClient; | ||
import io.github.dengliming.redismodule.redisgears.client.RedisGearsClient; | ||
import io.github.dengliming.redismodule.redisgraph.client.RedisGraphClient; | ||
import io.github.dengliming.redismodule.redisjson.client.RedisJSONClient; | ||
import io.github.dengliming.redismodule.redistimeseries.client.RedisTimeSeriesClient; | ||
import io.github.dengliming.redismodule.springboot.starter.env.RedisModuleProperties; | ||
import org.redisson.Redisson; | ||
import org.redisson.config.Config; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.io.IOException; | ||
|
||
@ConditionalOnProperty( | ||
prefix = RedisModuleProperties.PREFIX, | ||
name = "enabled", | ||
havingValue = "true", | ||
matchIfMissing = true | ||
) | ||
@ConditionalOnClass(Redisson.class) | ||
@EnableConfigurationProperties(RedisModuleProperties.class) | ||
@Configuration | ||
public class RedisModuleAutoConfiguration { | ||
private final RedisModuleProperties redisModuleProperties; | ||
|
||
public RedisModuleAutoConfiguration(RedisModuleProperties redisModuleProperties) { | ||
this.redisModuleProperties = redisModuleProperties; | ||
} | ||
|
||
@ConditionalOnProperty( | ||
prefix = RedisModuleProperties.PREFIX + ".redisearch", | ||
name = "enabled", | ||
havingValue = "true" | ||
) | ||
@Bean(destroyMethod = "shutdown") | ||
@ConditionalOnMissingBean | ||
public RediSearchClient rediSearchClient() { | ||
return new RediSearchClient(parseRedisModuleConfig(redisModuleProperties.getRedisearch().getConfig())); | ||
} | ||
|
||
@ConditionalOnProperty( | ||
prefix = RedisModuleProperties.PREFIX + ".redisai", | ||
name = "enabled", | ||
havingValue = "true" | ||
) | ||
@Bean(destroyMethod = "shutdown") | ||
@ConditionalOnMissingBean | ||
public RedisAIClient redisAIClient() { | ||
return new RedisAIClient(parseRedisModuleConfig(redisModuleProperties.getRedisai().getConfig())); | ||
} | ||
|
||
@ConditionalOnProperty( | ||
prefix = RedisModuleProperties.PREFIX + ".redisbloom", | ||
name = "enabled", | ||
havingValue = "true" | ||
) | ||
@Bean(destroyMethod = "shutdown") | ||
@ConditionalOnMissingBean | ||
public RedisBloomClient redisBloomClient() { | ||
return new RedisBloomClient(parseRedisModuleConfig(redisModuleProperties.getRedisbloom().getConfig())); | ||
} | ||
|
||
@ConditionalOnProperty( | ||
prefix = RedisModuleProperties.PREFIX + ".redisgears", | ||
name = "enabled", | ||
havingValue = "true" | ||
) | ||
@Bean(destroyMethod = "shutdown") | ||
@ConditionalOnMissingBean | ||
public RedisGearsClient redisGearsClient() { | ||
return new RedisGearsClient(parseRedisModuleConfig(redisModuleProperties.getRedisgears().getConfig())); | ||
} | ||
|
||
@ConditionalOnProperty( | ||
prefix = RedisModuleProperties.PREFIX + ".redisgraph", | ||
name = "enabled", | ||
havingValue = "true" | ||
) | ||
@Bean(destroyMethod = "shutdown") | ||
@ConditionalOnMissingBean | ||
public RedisGraphClient redisGraphClient() { | ||
return new RedisGraphClient(parseRedisModuleConfig(redisModuleProperties.getRedisgraph().getConfig())); | ||
} | ||
|
||
@ConditionalOnProperty( | ||
prefix = RedisModuleProperties.PREFIX + ".redisjson", | ||
name = "enabled", | ||
havingValue = "true" | ||
) | ||
@Bean(destroyMethod = "shutdown") | ||
@ConditionalOnMissingBean | ||
public RedisJSONClient redisJSONClient() { | ||
return new RedisJSONClient(parseRedisModuleConfig(redisModuleProperties.getRedisjson().getConfig())); | ||
} | ||
|
||
@ConditionalOnProperty( | ||
prefix = RedisModuleProperties.PREFIX + ".redistimeseries", | ||
name = "enabled", | ||
havingValue = "true" | ||
) | ||
@Bean(destroyMethod = "shutdown") | ||
@ConditionalOnMissingBean | ||
public RedisTimeSeriesClient redisTimeSeriesClient() { | ||
return new RedisTimeSeriesClient(parseRedisModuleConfig(redisModuleProperties.getRedistimeseries().getConfig())); | ||
} | ||
|
||
private Config parseRedisModuleConfig(String configStr) { | ||
Config config; | ||
try { | ||
config = Config.fromYAML(configStr); | ||
} catch (IOException e) { | ||
try { | ||
config = Config.fromJSON(configStr); | ||
} catch (IOException ex) { | ||
ex.addSuppressed(e); | ||
throw new IllegalArgumentException("Can't parse config", ex); | ||
} | ||
} | ||
return config; | ||
} | ||
} |
Oops, something went wrong.