-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support white-list and black-list commands and keys (#3755)
* Create csc package * Create csc.util package * Create a config interface for client-side caching * Default isCacheable * Config to WhiteList/BlackList commands and String keys * Create csc test package(s) * Test white-list/black-list commands and keys * Merge fix * Remove csc.util package * Fix javadoc links * Added ClientSideCacheable interface and removed ClientSideCacheConfig interface * Format imports * Re-create csc.util package * Rename to allow/deny instead of white/black
- Loading branch information
Showing
25 changed files
with
359 additions
and
83 deletions.
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
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
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
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
8 changes: 8 additions & 0 deletions
8
src/main/java/redis/clients/jedis/csc/ClientSideCacheable.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,8 @@ | ||
package redis.clients.jedis.csc; | ||
|
||
import redis.clients.jedis.commands.ProtocolCommand; | ||
|
||
public interface ClientSideCacheable { | ||
|
||
boolean isCacheable(ProtocolCommand command, Object... keys); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/redis/clients/jedis/csc/DefaultClientSideCacheable.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,15 @@ | ||
package redis.clients.jedis.csc; | ||
|
||
import redis.clients.jedis.commands.ProtocolCommand; | ||
|
||
public class DefaultClientSideCacheable implements ClientSideCacheable { | ||
|
||
public static final DefaultClientSideCacheable INSTANCE = new DefaultClientSideCacheable(); | ||
|
||
public DefaultClientSideCacheable() { } | ||
|
||
@Override | ||
public boolean isCacheable(ProtocolCommand command, Object... keys) { | ||
return true; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/redis/clients/jedis/csc/util/AllowAndDenyListWithStringKeys.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,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 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
Oops, something went wrong.