Skip to content

Commit

Permalink
Rename to allow/deny instead of white/black
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 committed Mar 6, 2024
1 parent bbc3514 commit 5df3093
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package redis.clients.jedis.csc.util;

import java.util.Set;
import redis.clients.jedis.commands.ProtocolCommand;
import redis.clients.jedis.csc.ClientSideCacheable;

public class AllowAndDenyListWithStringKeys implements ClientSideCacheable {

private final Set<ProtocolCommand> allowCommands;
private final Set<ProtocolCommand> denyCommands;

private final Set<String> allowKeys;
private final Set<String> denyKeys;

public AllowAndDenyListWithStringKeys(Set<ProtocolCommand> allowCommands, Set<ProtocolCommand> denyCommands,
Set<String> allowKeys, Set<String> denyKeys) {
this.allowCommands = allowCommands;
this.denyCommands = denyCommands;
this.allowKeys = allowKeys;
this.denyKeys = denyKeys;
}

@Override
public boolean isCacheable(ProtocolCommand command, Object... keys) {
if (allowCommands != null && !allowCommands.contains(command)) return false;
if (denyCommands != null && denyCommands.contains(command)) return false;

for (Object key : keys) {
if (!(key instanceof String)) return false;
if (allowKeys != null && !allowKeys.contains((String) key)) return false;
if (denyKeys != null && denyKeys.contains((String) key)) return false;
}

return true;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import redis.clients.jedis.JedisClientConfig;
import redis.clients.jedis.JedisPooled;
import redis.clients.jedis.Protocol;
import redis.clients.jedis.csc.util.StringWhiteListBlackListClientSideCacheable;
import redis.clients.jedis.csc.util.AllowAndDenyListWithStringKeys;

public class WhiteListBlackListClientSideCacheTest {
public class AllowAndDenyListClientSideCacheTest {

protected static final HostAndPort hnp = HostAndPorts.getRedisServers().get(1);

Expand Down Expand Up @@ -54,7 +54,7 @@ public void tearDown() throws Exception {
public void none() {
HashMap<Long, Object> map = new HashMap<>();
try (JedisPooled jedis = new JedisPooled(hnp, clientConfig.get(),
new MapCSC(map, new StringWhiteListBlackListClientSideCacheable(null, null, null, null)),
new MapCSC(map, new AllowAndDenyListWithStringKeys(null, null, null, null)),
singleConnectionPoolConfig.get())) {
control.set("foo", "bar");
assertThat(map, Matchers.aMapWithSize(0));
Expand All @@ -67,7 +67,7 @@ public void none() {
public void whiteListCommand() {
HashMap<Long, Object> map = new HashMap<>();
try (JedisPooled jedis = new JedisPooled(hnp, clientConfig.get(),
new MapCSC(map, new StringWhiteListBlackListClientSideCacheable(singleton(Protocol.Command.GET), null, null, null)),
new MapCSC(map, new AllowAndDenyListWithStringKeys(singleton(Protocol.Command.GET), null, null, null)),
singleConnectionPoolConfig.get())) {
control.set("foo", "bar");
assertThat(map, Matchers.aMapWithSize(0));
Expand All @@ -80,7 +80,7 @@ public void whiteListCommand() {
public void blackListCommand() {
HashMap<Long, Object> map = new HashMap<>();
try (JedisPooled jedis = new JedisPooled(hnp, clientConfig.get(),
new MapCSC(map, new StringWhiteListBlackListClientSideCacheable(null, singleton(Protocol.Command.GET), null, null)),
new MapCSC(map, new AllowAndDenyListWithStringKeys(null, singleton(Protocol.Command.GET), null, null)),
singleConnectionPoolConfig.get())) {
control.set("foo", "bar");
assertThat(map, Matchers.aMapWithSize(0));
Expand All @@ -93,7 +93,7 @@ public void blackListCommand() {
public void whiteListKey() {
HashMap<Long, Object> map = new HashMap<>();
try (JedisPooled jedis = new JedisPooled(hnp, clientConfig.get(),
new MapCSC(map, new StringWhiteListBlackListClientSideCacheable(null, null, singleton("foo"), null)),
new MapCSC(map, new AllowAndDenyListWithStringKeys(null, null, singleton("foo"), null)),
singleConnectionPoolConfig.get())) {
control.set("foo", "bar");
assertThat(map, Matchers.aMapWithSize(0));
Expand All @@ -106,7 +106,7 @@ public void whiteListKey() {
public void blackListKey() {
HashMap<Long, Object> map = new HashMap<>();
try (JedisPooled jedis = new JedisPooled(hnp, clientConfig.get(),
new MapCSC(map, new StringWhiteListBlackListClientSideCacheable(null, null, null, singleton("foo"))),
new MapCSC(map, new AllowAndDenyListWithStringKeys(null, null, null, singleton("foo"))),
singleConnectionPoolConfig.get())) {
control.set("foo", "bar");
assertThat(map, Matchers.aMapWithSize(0));
Expand Down

0 comments on commit 5df3093

Please sign in to comment.