All Downloads are FREE. Search and download functionalities are using the official Maven repository.

redis.clients.jedis.csc.util.AllowAndDenyListWithStringKeys Maven / Gradle / Ivy

There is a newer version: 6.0.0-beta2
Show newest version
package redis.clients.jedis.csc.util;

import java.util.List;
import java.util.Set;
import redis.clients.jedis.commands.ProtocolCommand;
import redis.clients.jedis.csc.DefaultCacheable;
import redis.clients.jedis.csc.Cacheable;

public class AllowAndDenyListWithStringKeys implements Cacheable {

  private final Set allowCommands;
  private final Set denyCommands;

  private final Set allowKeys;
  private final Set denyKeys;

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

  @Override
  public boolean isCacheable(ProtocolCommand command, List 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 DefaultCacheable.isDefaultCacheableCommand(command);
  }
}