Skip to content

Commit

Permalink
Introduce BITPOS override to accept start without end position #623
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Oct 9, 2017
1 parent f350431 commit 7e1120d
Show file tree
Hide file tree
Showing 16 changed files with 178 additions and 49 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@
<dependency>
<groupId>com.github.javaparser</groupId>
<artifactId>javaparser-core</artifactId>
<version>2.5.1</version>
<version>2.3.0</version>
<scope>test</scope>
</dependency>

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ public RedisFuture<Long> bitpos(K key, boolean state) {
return dispatch(commandBuilder.bitpos(key, state));
}

@Override
public RedisFuture<Long> bitpos(K key, boolean state, long start) {
return dispatch(commandBuilder.bitpos(key, state, start));
}

@Override
public RedisFuture<Long> bitpos(K key, boolean state, long start, long end) {
return dispatch(commandBuilder.bitpos(key, state, start, end));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ public Mono<Long> bitpos(K key, boolean state) {
return createMono(() -> commandBuilder.bitpos(key, state));
}

@Override
public Mono<Long> bitpos(K key, boolean state, long start) {
return createMono(() -> commandBuilder.bitpos(key, state, start));
}

@Override
public Mono<Long> bitpos(K key, boolean state, long start, long end) {
return createMono(() -> commandBuilder.bitpos(key, state, start, end));
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/io/lettuce/core/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ Command<K, V, Long> bitpos(K key, boolean state) {
return createCommand(BITPOS, new IntegerOutput<>(codec), args);
}

Command<K, V, Long> bitpos(K key, boolean state, long start) {
notNullKey(key);

CommandArgs<K, V> args = new CommandArgs<>(codec);
args.addKey(key).add(state ? 1 : 0).add(start);
return createCommand(BITPOS, new IntegerOutput<>(codec), args);
}

Command<K, V, Long> bitpos(K key, boolean state, long start, long end) {
notNullKey(key);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2016 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,12 +17,14 @@

import java.util.List;
import java.util.Map;

import io.lettuce.core.output.KeyValueStreamingChannel;
import io.lettuce.core.output.ValueStreamingChannel;
import io.lettuce.core.BitFieldArgs;
import io.lettuce.core.KeyValue;
import io.lettuce.core.RedisFuture;
import io.lettuce.core.SetArgs;
import io.lettuce.core.output.KeyValueStreamingChannel;
import io.lettuce.core.Value;
import io.lettuce.core.RedisFuture;
import reactor.core.publisher.Mono;

/**
* Asynchronous executed commands for Strings.
Expand Down Expand Up @@ -91,13 +93,30 @@ public interface RedisStringAsyncCommands<K, V> {
*
* Basically the function consider the right of the string as padded with zeros if you look for clear bits and
* specify no range or the <em>start</em> argument <strong>only</strong>.
*
* However this behavior changes if you are looking for clear bits and specify a range with both
* <strong>start</strong> and <strong>end</strong>. If no clear bit is found in the specified range, the function
* returns -1 as the user specified a clear range and there are no 0 bits in that range.
*/
RedisFuture<Long> bitpos(K key, boolean state);

/**
* Find first bit set or clear in a string.
*
* @param key the key
* @param state the bit type: long
* @param start the start type: long
* @return Long integer-reply The command returns the position of the first bit set to 1 or 0 according to the request.
*
* If we look for set bits (the bit argument is 1) and the string is empty or composed of just zero bytes, -1 is
* returned.
*
* If we look for clear bits (the bit argument is 0) and the string only contains bit set to 1, the function returns
* the first bit not part of the string on the right. So if the string is tree bytes set to the value 0xff the
* command {@code BITPOS key 0} will return 24, since up to bit 23 all the bits are 1.
*
* Basically the function consider the right of the string as padded with zeros if you look for clear bits and
* specify no range or the <em>start</em> argument <strong>only</strong>.
* @since 5.0.1
*/
RedisFuture<Long> bitpos(K key, boolean state, long start);

/**
* Find first bit set or clear in a string.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2016 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,13 +16,11 @@
package io.lettuce.core.api.reactive;

import java.util.Map;

import io.lettuce.core.output.KeyValueStreamingChannel;
import io.lettuce.core.BitFieldArgs;
import io.lettuce.core.KeyValue;
import io.lettuce.core.SetArgs;
import io.lettuce.core.Value;
import io.lettuce.core.output.KeyValueStreamingChannel;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

Expand Down Expand Up @@ -93,13 +91,30 @@ public interface RedisStringReactiveCommands<K, V> {
*
* Basically the function consider the right of the string as padded with zeros if you look for clear bits and
* specify no range or the <em>start</em> argument <strong>only</strong>.
*
* However this behavior changes if you are looking for clear bits and specify a range with both
* <strong>start</strong> and <strong>end</strong>. If no clear bit is found in the specified range, the function
* returns -1 as the user specified a clear range and there are no 0 bits in that range.
*/
Mono<Long> bitpos(K key, boolean state);

/**
* Find first bit set or clear in a string.
*
* @param key the key
* @param state the bit type: long
* @param start the start type: long
* @return Long integer-reply The command returns the position of the first bit set to 1 or 0 according to the request.
*
* If we look for set bits (the bit argument is 1) and the string is empty or composed of just zero bytes, -1 is
* returned.
*
* If we look for clear bits (the bit argument is 0) and the string only contains bit set to 1, the function returns
* the first bit not part of the string on the right. So if the string is tree bytes set to the value 0xff the
* command {@code BITPOS key 0} will return 24, since up to bit 23 all the bits are 1.
*
* Basically the function consider the right of the string as padded with zeros if you look for clear bits and
* specify no range or the <em>start</em> argument <strong>only</strong>.
* @since 5.0.1
*/
Mono<Long> bitpos(K key, boolean state, long start);

/**
* Find first bit set or clear in a string.
*
Expand Down
33 changes: 26 additions & 7 deletions src/main/java/io/lettuce/core/api/sync/RedisStringCommands.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2016 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,11 +17,13 @@

import java.util.List;
import java.util.Map;

import io.lettuce.core.output.KeyValueStreamingChannel;
import io.lettuce.core.output.ValueStreamingChannel;
import io.lettuce.core.BitFieldArgs;
import io.lettuce.core.KeyValue;
import io.lettuce.core.SetArgs;
import io.lettuce.core.output.KeyValueStreamingChannel;
import io.lettuce.core.Value;
import reactor.core.publisher.Mono;

/**
* Synchronous executed commands for Strings.
Expand Down Expand Up @@ -90,13 +92,30 @@ public interface RedisStringCommands<K, V> {
*
* Basically the function consider the right of the string as padded with zeros if you look for clear bits and
* specify no range or the <em>start</em> argument <strong>only</strong>.
*
* However this behavior changes if you are looking for clear bits and specify a range with both
* <strong>start</strong> and <strong>end</strong>. If no clear bit is found in the specified range, the function
* returns -1 as the user specified a clear range and there are no 0 bits in that range.
*/
Long bitpos(K key, boolean state);

/**
* Find first bit set or clear in a string.
*
* @param key the key
* @param state the bit type: long
* @param start the start type: long
* @return Long integer-reply The command returns the position of the first bit set to 1 or 0 according to the request.
*
* If we look for set bits (the bit argument is 1) and the string is empty or composed of just zero bytes, -1 is
* returned.
*
* If we look for clear bits (the bit argument is 0) and the string only contains bit set to 1, the function returns
* the first bit not part of the string on the right. So if the string is tree bytes set to the value 0xff the
* command {@code BITPOS key 0} will return 24, since up to bit 23 all the bits are 1.
*
* Basically the function consider the right of the string as padded with zeros if you look for clear bits and
* specify no range or the <em>start</em> argument <strong>only</strong>.
* @since 5.0.1
*/
Long bitpos(K key, boolean state, long start);

/**
* Find first bit set or clear in a string.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2016 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,11 +17,14 @@

import java.util.List;
import java.util.Map;

import io.lettuce.core.output.KeyValueStreamingChannel;
import io.lettuce.core.output.ValueStreamingChannel;
import io.lettuce.core.BitFieldArgs;
import io.lettuce.core.KeyValue;
import io.lettuce.core.SetArgs;
import io.lettuce.core.output.KeyValueStreamingChannel;
import io.lettuce.core.Value;
import io.lettuce.core.RedisFuture;
import reactor.core.publisher.Mono;

/**
* Asynchronous executed commands on a node selection for Strings.
Expand Down Expand Up @@ -90,13 +93,30 @@ public interface NodeSelectionStringAsyncCommands<K, V> {
*
* Basically the function consider the right of the string as padded with zeros if you look for clear bits and
* specify no range or the <em>start</em> argument <strong>only</strong>.
*
* However this behavior changes if you are looking for clear bits and specify a range with both
* <strong>start</strong> and <strong>end</strong>. If no clear bit is found in the specified range, the function
* returns -1 as the user specified a clear range and there are no 0 bits in that range.
*/
AsyncExecutions<Long> bitpos(K key, boolean state);

/**
* Find first bit set or clear in a string.
*
* @param key the key
* @param state the bit type: long
* @param start the start type: long
* @return Long integer-reply The command returns the position of the first bit set to 1 or 0 according to the request.
*
* If we look for set bits (the bit argument is 1) and the string is empty or composed of just zero bytes, -1 is
* returned.
*
* If we look for clear bits (the bit argument is 0) and the string only contains bit set to 1, the function returns
* the first bit not part of the string on the right. So if the string is tree bytes set to the value 0xff the
* command {@code BITPOS key 0} will return 24, since up to bit 23 all the bits are 1.
*
* Basically the function consider the right of the string as padded with zeros if you look for clear bits and
* specify no range or the <em>start</em> argument <strong>only</strong>.
* @since 5.0.1
*/
AsyncExecutions<Long> bitpos(K key, boolean state, long start);

/**
* Find first bit set or clear in a string.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2016 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,11 +17,13 @@

import java.util.List;
import java.util.Map;

import io.lettuce.core.output.KeyValueStreamingChannel;
import io.lettuce.core.output.ValueStreamingChannel;
import io.lettuce.core.BitFieldArgs;
import io.lettuce.core.KeyValue;
import io.lettuce.core.SetArgs;
import io.lettuce.core.output.KeyValueStreamingChannel;
import io.lettuce.core.Value;
import reactor.core.publisher.Mono;

/**
* Synchronous executed commands on a node selection for Strings.
Expand Down Expand Up @@ -90,13 +92,30 @@ public interface NodeSelectionStringCommands<K, V> {
*
* Basically the function consider the right of the string as padded with zeros if you look for clear bits and
* specify no range or the <em>start</em> argument <strong>only</strong>.
*
* However this behavior changes if you are looking for clear bits and specify a range with both
* <strong>start</strong> and <strong>end</strong>. If no clear bit is found in the specified range, the function
* returns -1 as the user specified a clear range and there are no 0 bits in that range.
*/
Executions<Long> bitpos(K key, boolean state);

/**
* Find first bit set or clear in a string.
*
* @param key the key
* @param state the bit type: long
* @param start the start type: long
* @return Long integer-reply The command returns the position of the first bit set to 1 or 0 according to the request.
*
* If we look for set bits (the bit argument is 1) and the string is empty or composed of just zero bytes, -1 is
* returned.
*
* If we look for clear bits (the bit argument is 0) and the string only contains bit set to 1, the function returns
* the first bit not part of the string on the right. So if the string is tree bytes set to the value 0xff the
* command {@code BITPOS key 0} will return 24, since up to bit 23 all the bits are 1.
*
* Basically the function consider the right of the string as padded with zeros if you look for clear bits and
* specify no range or the <em>start</em> argument <strong>only</strong>.
* @since 5.0.1
*/
Executions<Long> bitpos(K key, boolean state, long start);

/**
* Find first bit set or clear in a string.
*
Expand Down
25 changes: 21 additions & 4 deletions src/main/templates/io/lettuce/core/api/RedisStringCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,30 @@ public interface RedisStringCommands<K, V> {
*
* Basically the function consider the right of the string as padded with zeros if you look for clear bits and
* specify no range or the <em>start</em> argument <strong>only</strong>.
*
* However this behavior changes if you are looking for clear bits and specify a range with both
* <strong>start</strong> and <strong>end</strong>. If no clear bit is found in the specified range, the function
* returns -1 as the user specified a clear range and there are no 0 bits in that range.
*/
Long bitpos(K key, boolean state);

/**
* Find first bit set or clear in a string.
*
* @param key the key
* @param state the bit type: long
* @param start the start type: long
* @return Long integer-reply The command returns the position of the first bit set to 1 or 0 according to the request.
*
* If we look for set bits (the bit argument is 1) and the string is empty or composed of just zero bytes, -1 is
* returned.
*
* If we look for clear bits (the bit argument is 0) and the string only contains bit set to 1, the function returns
* the first bit not part of the string on the right. So if the string is tree bytes set to the value 0xff the
* command {@code BITPOS key 0} will return 24, since up to bit 23 all the bits are 1.
*
* Basically the function consider the right of the string as padded with zeros if you look for clear bits and
* specify no range or the <em>start</em> argument <strong>only</strong>.
* @since 5.0.1
*/
Long bitpos(K key, boolean state, long start);

/**
* Find first bit set or clear in a string.
*
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/lettuce/apigenerator/CreateAsyncApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public CreateAsyncApi(String templateName) {

String targetName = templateName.replace("Commands", "AsyncCommands");

File templateFile = new File(Constants.TEMPLATES, "com/lambdaworks/redis/api/" + templateName + ".java");
File templateFile = new File(Constants.TEMPLATES, "io/lettuce/core/api/" + templateName + ".java");
String targetPackage;

if (templateName.contains("RedisSentinel")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static List<Object[]> arguments() {
public CreateAsyncNodeSelectionClusterApi(String templateName) {

String targetName = templateName.replace("Commands", "AsyncCommands").replace("Redis", "NodeSelection");
File templateFile = new File(Constants.TEMPLATES, "com/lambdaworks/redis/api/" + templateName + ".java");
File templateFile = new File(Constants.TEMPLATES, "io/lettuce/core/api/" + templateName + ".java");
String targetPackage = "io.lettuce.core.cluster.api.async";

factory = new CompilationUnitFactory(templateFile, Constants.SOURCES, targetPackage, targetName, commentMutator(),
Expand Down
Loading

0 comments on commit 7e1120d

Please sign in to comment.