Skip to content

Commit

Permalink
Support for ACL commands #1538
Browse files Browse the repository at this point in the history
Original pull request: #1602.
  • Loading branch information
sokomishalov authored and mp911de committed Mar 2, 2021
1 parent 273f257 commit 38fc408
Show file tree
Hide file tree
Showing 32 changed files with 2,631 additions and 181 deletions.
86 changes: 81 additions & 5 deletions src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@
* @author Andrey Shlykov
*/
@SuppressWarnings("unchecked")
public abstract class AbstractRedisAsyncCommands<K, V> implements RedisHashAsyncCommands<K, V>, RedisKeyAsyncCommands<K, V>,
RedisStringAsyncCommands<K, V>, RedisListAsyncCommands<K, V>, RedisSetAsyncCommands<K, V>,
RedisSortedSetAsyncCommands<K, V>, RedisScriptingAsyncCommands<K, V>, RedisServerAsyncCommands<K, V>,
RedisHLLAsyncCommands<K, V>, BaseRedisAsyncCommands<K, V>, RedisTransactionalAsyncCommands<K, V>,
RedisGeoAsyncCommands<K, V>, RedisClusterAsyncCommands<K, V> {
public abstract class AbstractRedisAsyncCommands<K, V> implements RedisAclAsyncCommands<K,V>,
RedisHashAsyncCommands<K, V>, RedisKeyAsyncCommands<K, V>, RedisStringAsyncCommands<K, V>,
RedisListAsyncCommands<K, V>, RedisSetAsyncCommands<K, V>, RedisSortedSetAsyncCommands<K, V>,
RedisScriptingAsyncCommands<K, V>, RedisServerAsyncCommands<K, V>, RedisHLLAsyncCommands<K, V>,
BaseRedisAsyncCommands<K, V>, RedisTransactionalAsyncCommands<K, V>, RedisGeoAsyncCommands<K, V>,
RedisClusterAsyncCommands<K, V> {

private final StatefulConnection<K, V> connection;

Expand All @@ -78,6 +79,81 @@ public AbstractRedisAsyncCommands(StatefulConnection<K, V> connection, RedisCode
this.commandBuilder = new RedisCommandBuilder<>(codec);
}

@Override
public RedisFuture<List<AclCategory>> aclCat() {
return dispatch(commandBuilder.aclCat());
}

@Override
public RedisFuture<List<CommandType>> aclCat(AclCategory category) {
return dispatch(commandBuilder.aclCat(category));
}

@Override
public RedisFuture<Long> aclDeluser(String... usernames) {
return dispatch(commandBuilder.aclDeluser(usernames));
}

@Override
public RedisFuture<String> aclGenpass() {
return dispatch(commandBuilder.aclGenpass());
}

@Override
public RedisFuture<String> aclGenpass(int bits) {
return dispatch(commandBuilder.aclGenpass(bits));
}

@Override
public RedisFuture<Map<String, Object>> aclGetuser(String username) {
return dispatch(commandBuilder.aclGetuser(username));
}

@Override
public RedisFuture<List<String>> aclList() {
return dispatch(commandBuilder.aclList());
}

@Override
public RedisFuture<String> aclLoad() {
return dispatch(commandBuilder.aclLoad());
}

@Override
public RedisFuture<List<Map<String, Object>>> aclLog() {
return dispatch(commandBuilder.aclLog());
}

@Override
public RedisFuture<List<Map<String, Object>>> aclLog(int count) {
return dispatch(commandBuilder.aclLog(count));
}

@Override
public RedisFuture<String> aclLogReset() {
return dispatch(commandBuilder.aclLogReset());
}

@Override
public RedisFuture<String> aclSave() {
return dispatch(commandBuilder.aclSave());
}

@Override
public RedisFuture<String> aclSetuser(String username, AclSetuserArgs args) {
return dispatch(commandBuilder.aclSetuser(username, args));
}

@Override
public RedisFuture<List<String>> aclUsers() {
return dispatch(commandBuilder.aclUsers());
}

@Override
public RedisFuture<String> aclWhoami() {
return dispatch(commandBuilder.aclWhoami());
}

@Override
public RedisFuture<Long> append(K key, V value) {
return dispatch(commandBuilder.append(key, value));
Expand Down
87 changes: 81 additions & 6 deletions src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import io.lettuce.core.tracing.Tracing;
import io.netty.util.concurrent.EventExecutorGroup;
import io.netty.util.concurrent.ImmediateEventExecutor;

/**
* A reactive and thread-safe API for a Redis connection.
*
Expand All @@ -65,11 +64,12 @@
* @author Andrey Shlykov
* @since 4.0
*/
public abstract class AbstractRedisReactiveCommands<K, V> implements RedisHashReactiveCommands<K, V>,
RedisKeyReactiveCommands<K, V>, RedisStringReactiveCommands<K, V>, RedisListReactiveCommands<K, V>,
RedisSetReactiveCommands<K, V>, RedisSortedSetReactiveCommands<K, V>, RedisScriptingReactiveCommands<K, V>,
RedisServerReactiveCommands<K, V>, RedisHLLReactiveCommands<K, V>, BaseRedisReactiveCommands<K, V>,
RedisTransactionalReactiveCommands<K, V>, RedisGeoReactiveCommands<K, V>, RedisClusterReactiveCommands<K, V> {
public abstract class AbstractRedisReactiveCommands<K, V> implements RedisAclReactiveCommands<K, V>,
RedisHashReactiveCommands<K, V>, RedisKeyReactiveCommands<K, V>, RedisStringReactiveCommands<K, V>,
RedisListReactiveCommands<K, V>, RedisSetReactiveCommands<K, V>, RedisSortedSetReactiveCommands<K, V>,
RedisScriptingReactiveCommands<K, V>, RedisServerReactiveCommands<K, V>, RedisHLLReactiveCommands<K, V>,
BaseRedisReactiveCommands<K, V>, RedisTransactionalReactiveCommands<K, V>, RedisGeoReactiveCommands<K, V>,
RedisClusterReactiveCommands<K, V> {

private final StatefulConnection<K, V> connection;

Expand Down Expand Up @@ -110,6 +110,81 @@ private EventExecutorGroup getScheduler() {
return this.scheduler = schedulerToUse;
}

@Override
public Flux<AclCategory> aclCat() {
return createDissolvingFlux(commandBuilder::aclCat);
}

@Override
public Flux<CommandType> aclCat(AclCategory category) {
return createDissolvingFlux(() -> commandBuilder.aclCat(category));
}

@Override
public Mono<Long> aclDeluser(String... usernames) {
return createMono(() -> commandBuilder.aclDeluser(usernames));
}

@Override
public Mono<String> aclGenpass() {
return createMono(commandBuilder::aclGenpass);
}

@Override
public Mono<String> aclGenpass(int bits) {
return createMono(() -> commandBuilder.aclGenpass(bits));
}

@Override
public Mono<Map<String, Object>> aclGetuser(String username) {
return createMono(() -> commandBuilder.aclGetuser(username));
}

@Override
public Flux<String> aclList() {
return createDissolvingFlux(commandBuilder::aclList);
}

@Override
public Mono<String> aclLoad() {
return createMono(commandBuilder::aclLoad);
}

@Override
public Flux<Map<String, Object>> aclLog() {
return createDissolvingFlux(commandBuilder::aclLog);
}

@Override
public Flux<Map<String, Object>> aclLog(int count) {
return createDissolvingFlux(() -> commandBuilder.aclLog(count));
}

@Override
public Mono<String> aclLogReset() {
return createMono(commandBuilder::aclLogReset);
}

@Override
public Mono<String> aclSave() {
return createMono(commandBuilder::aclSave);
}

@Override
public Mono<String> aclSetuser(String username, AclSetuserArgs args) {
return createMono(() -> commandBuilder.aclSetuser(username, args));
}

@Override
public Flux<String> aclUsers() {
return createDissolvingFlux(commandBuilder::aclUsers);
}

@Override
public Mono<String> aclWhoami() {
return createMono(commandBuilder::aclWhoami);
}

@Override
public Mono<Long> append(K key, V value) {
return createMono(() -> commandBuilder.append(key, value));
Expand Down
115 changes: 115 additions & 0 deletions src/main/java/io/lettuce/core/AclCategory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package io.lettuce.core;

/**
* Enum object describing Redis ACL categories.
*
* @since 6.1
* @author Mikhael Sokolov
*/
public enum AclCategory {

/**
* command affects keyspace
*/
KEYSPACE,

/**
* read command
*/
READ,

/**
* write command
*/
WRITE,

/**
* command for sets
*/
SET,

/**
* command for sorted sets
*/
SORTEDSET,

/**
* command for lists
*/
LIST,

/**
* command for hash ops
*/
HASH,

/**
* command for strings
*/
STRING,

/**
* command for bitmaps
*/
BITMAP,

/**
* command for hyperloglog
*/
HYPERLOGLOG,

/**
* geo command
*/
GEO,

/**
* streaming command
*/
STREAM,

/**
* pubsub command
*/
PUBSUB,

/**
* admin command
*/
ADMIN,

/**
* fast command
*/
FAST,

/**
* slow command
*/
SLOW,

/**
* blocking command
*/
BLOCKING,

/**
* dangerous command
*/
DANGEROUS,

/**
* connection-establishing command
*/
CONNECTION,

/**
* transactional command
*/
TRANSACTION,

/**
* scripting command
*/
SCRIPTING
}
Loading

0 comments on commit 38fc408

Please sign in to comment.