Skip to content

Commit

Permalink
#274, #275: remove unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-bukhtoyarov committed Jul 13, 2022
1 parent c7f512a commit 06189b5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,7 @@ public boolean compareAndSwap(byte[] originalData, byte[] newData, RemoteBucketS

@Override
protected AsyncCompareAndSwapOperation beginAsyncCompareAndSwapOperation(byte[] key) {
return new AsyncCompareAndSwapOperation() {
@Override
public CompletableFuture<Optional<byte[]>> getStateData() {
return withResource(jedis -> CompletableFuture.supplyAsync(() -> Optional.ofNullable(jedis.get(key))));
}

@Override
public CompletableFuture<Boolean> compareAndSwap(byte[] originalData, byte[] newData, RemoteBucketState newState) {
return CompletableFuture.supplyAsync(() -> JedisBasedProxyManager.this.compareAndSwap(key, originalData, newData, newState));
}
};
throw new UnsupportedOperationException();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,18 @@ public class SpringDataRedisBasedProxyManager extends AbstractCompareAndSwapBase

private final RedisCommands commands;
private final long keepAfterRefillDurationMillis;
private final boolean isAsyncModeSupported;

/**
*
* @param redisCommands
* @param clientSideConfig
* @param keepAfterRefillDuration
* @param isAsyncModeSupported specifies how long bucket should be held in the cache after all consumed tokens have been refilled.
* @param keepAfterRefillDuration specifies how long bucket should be held in the cache after all consumed tokens have been refilled.
*/
public SpringDataRedisBasedProxyManager(RedisCommands redisCommands, ClientSideConfig clientSideConfig, Duration keepAfterRefillDuration, boolean isAsyncModeSupported) {
public SpringDataRedisBasedProxyManager(RedisCommands redisCommands, ClientSideConfig clientSideConfig, Duration keepAfterRefillDuration) {
super(clientSideConfig);
Objects.requireNonNull(redisCommands);
this.commands = redisCommands;
this.keepAfterRefillDurationMillis = keepAfterRefillDuration.toMillis();
this.isAsyncModeSupported = isAsyncModeSupported;
}

/**
*
* @param redisCommands
* @param clientSideConfig
* @param keepAfterRefillDuration specifies how long bucket should be held in the cache after all consumed tokens have been refilled.
*/
public SpringDataRedisBasedProxyManager(RedisCommands redisCommands, ClientSideConfig clientSideConfig, Duration keepAfterRefillDuration) {
this(redisCommands, clientSideConfig, keepAfterRefillDuration, true);
}

/**
Expand Down Expand Up @@ -91,17 +78,7 @@ public boolean compareAndSwap(byte[] originalData, byte[] newData, RemoteBucketS

@Override
protected AsyncCompareAndSwapOperation beginAsyncCompareAndSwapOperation(byte[] key) {
return new AsyncCompareAndSwapOperation() {
@Override
public CompletableFuture<Optional<byte[]>> getStateData() {
return CompletableFuture.supplyAsync(() -> Optional.ofNullable(commands.get(key)));
}

@Override
public CompletableFuture<Boolean> compareAndSwap(byte[] originalData, byte[] newData, RemoteBucketState newState) {
return CompletableFuture.supplyAsync(() -> SpringDataRedisBasedProxyManager.this.compareAndSwap(key, originalData, newData, newState));
}
};
throw new UnsupportedOperationException();
}

@Override
Expand All @@ -116,7 +93,7 @@ protected CompletableFuture<Void> removeAsync(byte[] key) {

@Override
public boolean isAsyncModeSupported() {
return isAsyncModeSupported;
return false;
}

private final byte[] scriptSetNx = "return redis.call('set', KEYS[1], ARGV[1], 'nx', 'px', ARGV[2])".getBytes(StandardCharsets.UTF_8);
Expand Down

0 comments on commit 06189b5

Please sign in to comment.