Skip to content

Commit

Permalink
#184 #160 Spring Data Redis
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcGiffing committed Sep 29, 2023
1 parent 9e27314 commit dcebc2f
Show file tree
Hide file tree
Showing 36 changed files with 1,025 additions and 106 deletions.
6 changes: 4 additions & 2 deletions bucket4j-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>17</java.version>
<redisson.version>3.23.5</redisson.version>
<ignite-core.version>2.15.0</ignite-core.version>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -93,7 +95,7 @@
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>3.20.0</version>
<version>${redisson.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -114,7 +116,7 @@
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-core</artifactId>
<version>2.15.0</version>
<version>${ignite-core.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.giffing.bucket4j.spring.boot.starter.config.cache.redis.jedis.JedisBucket4jConfiguration;
import com.giffing.bucket4j.spring.boot.starter.config.cache.redis.lettuce.LettuceBucket4jConfiguration;
import com.giffing.bucket4j.spring.boot.starter.config.cache.redis.redisson.RedissonBucket4jConfiguration;
import com.giffing.bucket4j.spring.boot.starter.config.cache.redis.springdata.RedisSpringDataBucket4jConfiguration;

@Configuration
@AutoConfigureAfter(CacheAutoConfiguration.class)
Expand All @@ -26,7 +25,6 @@
JedisBucket4jConfiguration.class,
LettuceBucket4jConfiguration.class,
RedissonBucket4jConfiguration.class,
RedisSpringDataBucket4jConfiguration.class
})
public class Bucket4jCacheConfiguration {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.giffing.bucket4j.spring.boot.starter.config.cache.AsyncCacheResolver;
import com.giffing.bucket4j.spring.boot.starter.context.properties.Bucket4JBootProperties;
import io.github.bucket4j.redis.redisson.cas.RedissonBasedProxyManager;
import org.redisson.command.CommandExecutor;
import org.redisson.command.CommandAsyncExecutor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand All @@ -14,12 +14,12 @@
@Configuration
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
@ConditionalOnClass(RedissonBasedProxyManager.class)
@ConditionalOnBean(CommandExecutor.class)
@ConditionalOnBean(CommandAsyncExecutor.class)
@ConditionalOnProperty(prefix = Bucket4JBootProperties.PROPERTY_PREFIX, name = "cache-to-use", havingValue = "redis-redisson", matchIfMissing = true)
public class RedissonBucket4jConfiguration {

@Bean
public AsyncCacheResolver bucket4RedisResolver(CommandExecutor commandExecutor) {
public AsyncCacheResolver bucket4RedisResolver(CommandAsyncExecutor commandExecutor) {
return new RedissonCacheResolver(commandExecutor);
}
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
package com.giffing.bucket4j.spring.boot.starter.config.cache.redis.redisson;

import java.time.Duration;

import org.redisson.command.CommandExecutor;

import com.giffing.bucket4j.spring.boot.starter.config.cache.AsyncCacheResolver;
import com.giffing.bucket4j.spring.boot.starter.config.cache.CacheResolver;
import com.giffing.bucket4j.spring.boot.starter.config.cache.ProxyManagerWrapper;
import com.giffing.bucket4j.spring.boot.starter.context.ConsumptionProbeHolder;

import io.github.bucket4j.distributed.AsyncBucketProxy;
import io.github.bucket4j.distributed.ExpirationAfterWriteStrategy;
import io.github.bucket4j.distributed.proxy.ProxyManager;
import io.github.bucket4j.redis.redisson.cas.RedissonBasedProxyManager;
import org.redisson.command.CommandAsyncExecutor;

import java.time.Duration;

/**
* This class is the Redis implementation of the {@link CacheResolver}.
*
*/
public class RedissonCacheResolver implements AsyncCacheResolver {

private final CommandExecutor commandExecutor;
private final CommandAsyncExecutor commandExecutor;

public RedissonCacheResolver(CommandExecutor commandExecutor) {
public RedissonCacheResolver(CommandAsyncExecutor commandExecutor) {
this.commandExecutor = commandExecutor;
}

@Override
public ProxyManagerWrapper resolve(String cacheName) {
final ProxyManager<String> proxyManager = RedissonBasedProxyManager.builderFor(commandExecutor)
var proxyManager = RedissonBasedProxyManager.builderFor(commandExecutor)
.withExpirationStrategy(ExpirationAfterWriteStrategy.basedOnTimeForRefillingBucketUpToMax(Duration.ofSeconds(10)))
.build();

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package com.giffing.bucket4j.spring.boot.starter.config.filter.servlet.predicate;

import java.util.Collections;

import org.springframework.stereotype.Component;

import com.giffing.bucket4j.spring.boot.starter.config.filter.predicate.HeaderExecutePredicate;

import jakarta.servlet.http.HttpServletRequest;

@Component
import java.util.Collections;

public class ServletHeaderExecutePredicate extends HeaderExecutePredicate<HttpServletRequest>{

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package com.giffing.bucket4j.spring.boot.starter.config.filter.servlet.predicate;

import org.springframework.stereotype.Component;

import com.giffing.bucket4j.spring.boot.starter.config.filter.predicate.MethodExecutePredicate;

import jakarta.servlet.http.HttpServletRequest;

@Component
public class ServletMethodPredicate extends MethodExecutePredicate<HttpServletRequest> {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package com.giffing.bucket4j.spring.boot.starter.config.filter.servlet.predicate;

import org.springframework.stereotype.Component;

import com.giffing.bucket4j.spring.boot.starter.config.filter.predicate.PathExecutePredicate;

import jakarta.servlet.http.HttpServletRequest;

@Component
public class ServletPathExecutePredicate extends PathExecutePredicate<HttpServletRequest>{

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package com.giffing.bucket4j.spring.boot.starter.config.filter.servlet.predicate;

import org.springframework.stereotype.Component;

import com.giffing.bucket4j.spring.boot.starter.config.filter.predicate.QueryExecutePredicate;

import jakarta.servlet.http.HttpServletRequest;

@Component
public class ServletQueryExecutePredicate extends QueryExecutePredicate<HttpServletRequest> {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
package com.giffing.bucket4j.spring.boot.starter.config.filter.servlet.predicate;

import org.springframework.context.annotation.ComponentScan;
import com.giffing.bucket4j.spring.boot.starter.config.filter.servlet.Bucket4JAutoConfigurationServletFilter;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan
@AutoConfigureAfter(Bucket4JAutoConfigurationServletFilter.class)
@ConditionalOnBean(Bucket4JAutoConfigurationServletFilter.class)
public class ServletRequestExecutePredicateConfiguration {

@Bean
ServletHeaderExecutePredicate servletHeaderExecutePredicate() {
return new ServletHeaderExecutePredicate();
}

@Bean
ServletMethodPredicate servletMethodPredicate() {
return new ServletMethodPredicate();
}

@Bean
ServletPathExecutePredicate servletPathExecutePredicate() {
return new ServletPathExecutePredicate();
}

@Bean
ServletQueryExecutePredicate servletQueryExecutePredicate() {
return new ServletQueryExecutePredicate();
}

}
38 changes: 38 additions & 0 deletions examples/redis-jedis/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
65 changes: 65 additions & 0 deletions examples/redis-jedis/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.giffing.bucket4j.spring.boot.starter</groupId>
<artifactId>bucket4j-spring-boot-starter-parent</artifactId>
<version>${revision}</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>bucket4j-spring-boot-starter-example-redis-jedis</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<testcontainers-redis-junit.version>1.6.4</testcontainers-redis-junit.version>
<jedis.version>5.0.1</jedis.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>com.giffing.bucket4j.spring.boot.starter</groupId>
<artifactId>bucket4j-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.bucket4j</groupId>
<artifactId>bucket4j-redis</artifactId>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${jedis.version}</version>
</dependency>

<dependency>
<groupId>com.redis.testcontainers</groupId>
<artifactId>testcontainers-redis-junit</artifactId>
<version>${testcontainers-redis-junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>


</dependencies>

</project>
Loading

0 comments on commit dcebc2f

Please sign in to comment.