Skip to content

Commit 8d5f45c

Browse files
authored
Separate interfaces for bit commands (#3279)
1 parent 6dc33b1 commit 8d5f45c

8 files changed

+207
-177
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package redis.clients.jedis.commands;
2+
3+
import java.util.List;
4+
5+
import redis.clients.jedis.args.BitCountOption;
6+
import redis.clients.jedis.args.BitOP;
7+
import redis.clients.jedis.params.BitPosParams;
8+
9+
public interface BitBinaryCommands {
10+
11+
boolean setbit(byte[] key, long offset, boolean value);
12+
13+
boolean getbit(byte[] key, long offset);
14+
15+
long bitcount(byte[] key);
16+
17+
long bitcount(byte[] key, long start, long end);
18+
19+
long bitcount(byte[] key, long start, long end, BitCountOption option);
20+
21+
long bitpos(byte[] key, boolean value);
22+
23+
long bitpos(byte[] key, boolean value, BitPosParams params);
24+
25+
List<Long> bitfield(byte[] key, byte[]... arguments);
26+
27+
List<Long> bitfieldReadonly(byte[] key, byte[]... arguments);
28+
29+
long bitop(BitOP op, byte[] destKey, byte[]... srcKeys);
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package redis.clients.jedis.commands;
2+
3+
import java.util.List;
4+
5+
import redis.clients.jedis.args.BitCountOption;
6+
import redis.clients.jedis.args.BitOP;
7+
import redis.clients.jedis.params.BitPosParams;
8+
9+
public interface BitCommands {
10+
11+
/**
12+
* <b><a href="http://redis.io/commands/setbit">SetBit Command</a></b>
13+
* Sets or clears the bit at offset in the string value stored at key.
14+
* <p>
15+
* Time complexity: O(1)
16+
* @param key
17+
* @param offset
18+
* @param value
19+
* @return The original bit value stored at offset
20+
*/
21+
boolean setbit(String key, long offset, boolean value);
22+
23+
/**
24+
* <b><a href="http://redis.io/commands/getbit">GetBit Command</a></b>
25+
* Returns the bit value at offset in the string value stored at key.
26+
* <p>
27+
* Time complexity: O(1)
28+
* @param key
29+
* @param offset
30+
* @return The bit value stored at offset
31+
*/
32+
boolean getbit(String key, long offset);
33+
34+
/**
35+
* <b><a href="http://redis.io/commands/bitcount">Bitcount Command</a></b>
36+
* Count the number of set bits (population counting) in a string.
37+
* @param key
38+
* @return The number of bits set to 1
39+
*/
40+
long bitcount(String key);
41+
42+
/**
43+
* <b><a href="http://redis.io/commands/bitcount">Bitcount Command</a></b>
44+
* Count the number of set bits (population counting) in a string only in an interval start and end.
45+
* <p>
46+
* Like for the GETRANGE command start and end can contain negative values in order to index bytes
47+
* starting from the end of the string, where -1 is the last byte, -2 is the penultimate, and so forth.
48+
* @param key
49+
* @param start byte start index
50+
* @param end byte end index
51+
* @return The number of bits set to 1
52+
*/
53+
long bitcount(String key, long start, long end);
54+
55+
/**
56+
* @see StringCommands#bitcount(String, long, long)
57+
* @param key
58+
* @param start byte start index
59+
* @param end byte end index
60+
* @param option indicate BYTE or BIT
61+
* @return The number of bits set to 1
62+
*/
63+
long bitcount(String key, long start, long end, BitCountOption option);
64+
65+
/**
66+
* <b><a href="http://redis.io/commands/bitpos">Bitpos Command</a></b>
67+
* Return the position of the first bit set to 1 or 0 in a string.
68+
* @param key
69+
* @param value the bit value
70+
* @return The position of the first bit set to 1 or 0 according to the request
71+
*/
72+
long bitpos(String key, boolean value);
73+
74+
/**
75+
* <b><a href="http://redis.io/commands/bitpos">Bitpos Command</a></b>
76+
* Return the position of the first bit set to 1 or 0 in a string.
77+
* @param key
78+
* @param value the bit value
79+
* @param params {@link BitPosParams}
80+
* @return The position of the first bit set to 1 or 0 according to the request
81+
*/
82+
long bitpos(String key, boolean value, BitPosParams params);
83+
84+
/**
85+
* <b><a href="http://redis.io/commands/bitfield">Bitfield Command</a></b>
86+
* The command treats a Redis string as an array of bits, and is capable of addressing specific integer
87+
* fields of varying bit widths and arbitrary non (necessary) aligned offset.
88+
* @param key
89+
* @param arguments may be used with optional arguments
90+
* @return A List of results
91+
*/
92+
List<Long> bitfield(String key, String...arguments);
93+
94+
/**
95+
* The readonly version of {@link StringCommands#bitfield(String, String...) BITFIELD}
96+
*/
97+
List<Long> bitfieldReadonly(String key, String...arguments);
98+
99+
/**
100+
* <b><a href="http://redis.io/commands/bitop">Bitop Command</a></b>
101+
* Perform a bitwise operation between multiple keys (containing string values) and store the result in the destKey.
102+
* @param op can be AND, OR, XOR or NOT
103+
* @param destKey
104+
* @param srcKeys
105+
* @return The size of the string stored in the destKey
106+
*/
107+
long bitop(BitOP op, String destKey, String... srcKeys);
108+
109+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package redis.clients.jedis.commands;
2+
3+
import java.util.List;
4+
5+
import redis.clients.jedis.Response;
6+
import redis.clients.jedis.args.BitCountOption;
7+
import redis.clients.jedis.args.BitOP;
8+
import redis.clients.jedis.params.BitPosParams;
9+
10+
public interface BitPipelineBinaryCommands {
11+
12+
Response<Boolean> setbit(byte[] key, long offset, boolean value);
13+
14+
Response<Boolean> getbit(byte[] key, long offset);
15+
16+
Response<Long> bitcount(byte[] key);
17+
18+
Response<Long> bitcount(byte[] key, long start, long end);
19+
20+
Response<Long> bitcount(byte[] key, long start, long end, BitCountOption option);
21+
22+
Response<Long> bitpos(byte[] key, boolean value);
23+
24+
Response<Long> bitpos(byte[] key, boolean value, BitPosParams params);
25+
26+
Response<List<Long>> bitfield(byte[] key, byte[]... arguments);
27+
28+
Response<List<Long>> bitfieldReadonly(byte[] key, byte[]... arguments);
29+
30+
Response<Long> bitop(BitOP op, byte[] destKey, byte[]... srcKeys);
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package redis.clients.jedis.commands;
2+
3+
import redis.clients.jedis.Response;
4+
import redis.clients.jedis.args.BitCountOption;
5+
import redis.clients.jedis.args.BitOP;
6+
import redis.clients.jedis.params.BitPosParams;
7+
8+
import java.util.List;
9+
10+
public interface BitPipelineCommands {
11+
12+
Response<Boolean> setbit(String key, long offset, boolean value);
13+
14+
Response<Boolean> getbit(String key, long offset);
15+
16+
Response<Long> bitcount(String key);
17+
18+
Response<Long> bitcount(String key, long start, long end);
19+
20+
Response<Long> bitcount(String key, long start, long end, BitCountOption option);
21+
22+
Response<Long> bitpos(String key, boolean value);
23+
24+
Response<Long> bitpos(String key, boolean value, BitPosParams params);
25+
26+
Response<List<Long>> bitfield(String key, String...arguments);
27+
28+
Response<List<Long>> bitfieldReadonly(String key, String...arguments);
29+
30+
Response<Long> bitop(BitOP op, String destKey, String... srcKeys);
31+
}

src/main/java/redis/clients/jedis/commands/StringBinaryCommands.java

+1-24
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22

33
import java.util.List;
44

5-
import redis.clients.jedis.args.BitCountOption;
6-
import redis.clients.jedis.args.BitOP;
7-
import redis.clients.jedis.params.BitPosParams;
85
import redis.clients.jedis.params.GetExParams;
96
import redis.clients.jedis.params.SetParams;
107
import redis.clients.jedis.params.StrAlgoLCSParams;
118
import redis.clients.jedis.params.LCSParams;
129
import redis.clients.jedis.resps.LCSMatchResult;
1310

14-
public interface StringBinaryCommands {
11+
public interface StringBinaryCommands extends BitBinaryCommands {
1512

1613
String set(byte[] key, byte[] value);
1714

@@ -28,10 +25,6 @@ public interface StringBinaryCommands {
2825

2926
byte[] getEx(byte[] key, GetExParams params);
3027

31-
boolean setbit(byte[] key, long offset, boolean value);
32-
33-
boolean getbit(byte[] key, long offset);
34-
3528
long setrange(byte[] key, long offset, byte[] value);
3629

3730
byte[] getrange(byte[] key, long startOffset, long endOffset);
@@ -66,22 +59,6 @@ public interface StringBinaryCommands {
6659

6760
long strlen(byte[] key);
6861

69-
long bitcount(byte[] key);
70-
71-
long bitcount(byte[] key, long start, long end);
72-
73-
long bitcount(byte[] key, long start, long end, BitCountOption option);
74-
75-
long bitpos(byte[] key, boolean value);
76-
77-
long bitpos(byte[] key, boolean value, BitPosParams params);
78-
79-
List<Long> bitfield(byte[] key, byte[]... arguments);
80-
81-
List<Long> bitfieldReadonly(byte[] key, byte[]... arguments);
82-
83-
long bitop(BitOP op, byte[] destKey, byte[]... srcKeys);
84-
8562
/**
8663
* @deprecated STRALGO LCS command will be removed from Redis 7.
8764
* {@link StringBinaryCommands#lcs(byte[], byte[], LCSParams) LCS} can be used instead of this method.

0 commit comments

Comments
 (0)