Skip to content

Commit

Permalink
Merge branch 'master' into json-resp3-2
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 committed Aug 10, 2023
2 parents 356dfc9 + ba63cf2 commit 617bd50
Show file tree
Hide file tree
Showing 27 changed files with 144 additions and 61 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021-2023, Redis, inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
22 changes: 0 additions & 22 deletions LICENSE.txt

This file was deleted.

11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ The most recent version of this library supports redis version [5.0](https://git

The table below highlights version compatibility of the most-recent library versions and Redis versions. Compatibility means communication features, and Redis command capabilities.

| Library version | Supported redis versions |
|-----------------|-------------------|
| 3.9+ | 5.0 and 6.2 Family of releases |
| >= 4.0 | Version 5.0 to current |

| Library version | Supported redis versions | JDK Compatibility |
|-----------------|-------------------|-------------------|
| 3.9+ | 5.0 and 6.2 Family of releases | 8, 11 |
| >= 4.0 | Version 5.0 to current | 8, 11, 17 |

## Getting started

Expand Down Expand Up @@ -78,7 +79,7 @@ for the complete list of supported commands.

### Easier way of using connection pool

Using a *try-with-resources* block for each command may be cumbursome, so you may consider using JedisPooled.
Using a *try-with-resources* block for each command may be cumbersome, so you may consider using JedisPooled.

```java
JedisPooled jedis = new JedisPooled("localhost", 6379);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20230227</version>
<version>20230618</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/redis/clients/jedis/BuilderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,37 @@ public String toString() {
}
};

public static final Builder<Map<String, Long>> STRING_LONG_MAP = new Builder<Map<String, Long>>() {
@Override
@SuppressWarnings("unchecked")
public Map<String, Long> build(Object data) {
final List<Object> list = (List<Object>) data;
if (list.isEmpty()) return Collections.emptyMap();

if (list.get(0) instanceof KeyValue) {
final Map<String, Long> map = new LinkedHashMap<>(list.size(), 1f);
final Iterator iterator = list.iterator();
while (iterator.hasNext()) {
KeyValue kv = (KeyValue) iterator.next();
map.put(STRING.build(kv.getKey()), LONG.build(kv.getValue()));
}
return map;
} else {
final Map<String, Long> map = new LinkedHashMap<>(list.size() / 2, 1f);
final Iterator iterator = list.iterator();
while (iterator.hasNext()) {
map.put(STRING.build(iterator.next()), LONG.build(iterator.next()));
}
return map;
}
}

@Override
public String toString() {
return "Map<String, Long>";
}
};

public static final Builder<KeyValue<String, String>> KEYED_ELEMENT = new Builder<KeyValue<String, String>>() {
@Override
@SuppressWarnings("unchecked")
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/redis/clients/jedis/CommandObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -4059,6 +4059,11 @@ public final CommandObject<List<String>> topkList(String key) {
return new CommandObject<>(commandArguments(TopKCommand.LIST).key(key), BuilderFactory.STRING_LIST);
}

public final CommandObject<Map<String, Long>> topkListWithCount(String key) {
return new CommandObject<>(commandArguments(TopKCommand.LIST).key(key)
.add(RedisBloomKeyword.WITHCOUNT), BuilderFactory.STRING_LONG_MAP);
}

public final CommandObject<Map<String, Object>> topkInfo(String key) {
return new CommandObject<>(commandArguments(TopKCommand.INFO).key(key), BuilderFactory.ENCODED_OBJECT_MAP);
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/redis/clients/jedis/PipelineBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -4059,6 +4059,11 @@ public Response<List<String>> topkList(String key) {
return appendCommand(commandObjects.topkList(key));
}

@Override
public Response<Map<String, Long>> topkListWithCount(String key) {
return appendCommand(commandObjects.topkListWithCount(key));
}

@Override
public Response<Map<String, Object>> topkInfo(String key) {
return appendCommand(commandObjects.topkInfo(key));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/redis/clients/jedis/StreamEntryID.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public int hashCode() {

@Override
public int compareTo(StreamEntryID other) {
int timeComapre = Long.compare(this.time, other.time);
return timeComapre != 0 ? timeComapre : Long.compare(this.sequence, other.sequence);
int timeCompare = Long.compare(this.time, other.time);
return timeCompare != 0 ? timeCompare : Long.compare(this.sequence, other.sequence);
}

public long getTime() {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/redis/clients/jedis/TransactionBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -4227,6 +4227,11 @@ public Response<List<String>> topkList(String key) {
return appendCommand(commandObjects.topkList(key));
}

@Override
public Response<Map<String, Long>> topkListWithCount(String key) {
return appendCommand(commandObjects.topkListWithCount(key));
}

@Override
public Response<Map<String, Object>> topkInfo(String key) {
return appendCommand(commandObjects.topkInfo(key));
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/redis/clients/jedis/UnifiedJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -4583,6 +4583,11 @@ public List<String> topkList(String key) {
return executeCommand(commandObjects.topkList(key));
}

@Override
public Map<String, Long> topkListWithCount(String key) {
return executeCommand(commandObjects.topkListWithCount(key));
}

@Override
public Map<String, Object> topkInfo(String key) {
return executeCommand(commandObjects.topkInfo(key));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public byte[] getRaw() {
public enum RedisBloomKeyword implements Rawable {

CAPACITY, ERROR, NOCREATE, EXPANSION, NONSCALING, BUCKETSIZE, MAXITERATIONS, ITEMS, WEIGHTS,
COMPRESSION, OVERRIDE;
COMPRESSION, OVERRIDE, WITHCOUNT;

private final byte[] raw;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package redis.clients.jedis.bloom.commands;

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

Expand Down Expand Up @@ -35,6 +36,18 @@ public interface TopKFilterCommands {
*/
List<String> topkAdd(String key, String... items);

/**
* {@code TOPK.INCRBY {key} {item} {increment}}
*
* @param key
* @param item
* @param increment
* @return item dropped from list
*/
default String topkIncrBy(String key, String item, long increment) {
return topkIncrBy(key, Collections.singletonMap(item, increment)).get(0);
}

/**
* {@code TOPK.INCRBY {key} {item} {increment} [{item} {increment} ...]}
*
Expand All @@ -61,6 +74,14 @@ public interface TopKFilterCommands {
*/
List<String> topkList(String key);

/**
* {@code TOPK.LIST {key} WITHCOUNT}
*
* @param key
* @return k (or less) items in Top K list
*/
Map<String, Long> topkListWithCount(String key);

/**
* {@code TOPK.INFO {key}}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ public interface TopKFilterPipelineCommands {

Response<List<String>> topkList(String key);

Response<Map<String, Long>> topkListWithCount(String key);

Response<Map<String, Object>> topkInfo(String key);
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public interface ServerCommands {
* The SAVE commands performs a synchronous save of the dataset producing a point in time snapshot
* of all the data inside the Redis instance, in the form of an RDB file. You almost never want to
* call SAVE in production environments where it will block all the other clients. Instead usually
* BGSAVE is used. However in case of issues preventing Redis to create the background saving
* BGSAVE is used. However, in case of issues preventing Redis to create the background saving
* child (for instance errors in the fork(2) system call), the SAVE command can be a good last
* resort to perform the dump of the latest dataset.
* @return result of the save
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/redis/clients/jedis/params/MigrateParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class MigrateParams implements IParams {
private boolean copy = false;
private boolean replace = false;
private String username = null;
private String passowrd = null;
private String password = null;

public MigrateParams() {
}
Expand All @@ -28,13 +28,13 @@ public MigrateParams replace() {
}

public MigrateParams auth(String password) {
this.passowrd = password;
this.password = password;
return this;
}

public MigrateParams auth2(String username, String password) {
this.username = username;
this.passowrd = password;
this.password = password;
return this;
}

Expand All @@ -47,9 +47,9 @@ public void addParams(CommandArguments args) {
args.add(Keyword.REPLACE);
}
if (username != null) {
args.add(Keyword.AUTH2).add(username).add(passowrd);
} else if (passowrd != null) {
args.add(Keyword.AUTH).add(passowrd);
args.add(Keyword.AUTH2).add(username).add(password);
} else if (password != null) {
args.add(Keyword.AUTH).add(password);
}
}
}
12 changes: 6 additions & 6 deletions src/main/java/redis/clients/jedis/params/ZAddParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class ZAddParams implements IParams {

private Keyword existance;
private Keyword existence;
private Keyword comparison;
private boolean change;

Expand All @@ -21,16 +21,16 @@ public static ZAddParams zAddParams() {
* @return ZAddParams
*/
public ZAddParams nx() {
this.existance = Keyword.NX;
this.existence = Keyword.NX;
return this;
}

/**
* Only set the key if it already exist.
* Only set the key if it already exists.
* @return ZAddParams
*/
public ZAddParams xx() {
this.existance = Keyword.XX;
this.existence = Keyword.XX;
return this;
}

Expand Down Expand Up @@ -64,8 +64,8 @@ public ZAddParams ch() {

@Override
public void addParams(CommandArguments args) {
if (existance != null) {
args.add(existance);
if (existence != null) {
args.add(existence);
}
if (comparison != null) {
args.add(comparison);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
* This class holds information about an Access Control Log entry (returned by ACL LOG command) They
* can be access via getters. For future purpose there is also {@link #getlogEntry} method that
* can be accessed via getters. For future purpose there is also {@link #getlogEntry} method that
* returns a generic {@code Map} - in case where more info is returned from a server
*/
// TODO: remove
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

/**
* This class holds information about a stream consumer with command
* {@code xinfo stream mystream full}. They can be access via getters. There is also
* {@code xinfo stream mystream full}. They can be accessed via getters. There is also
* {@link StreamConsumerFullInfo#getConsumerInfo()} method that returns a generic {@link Map} in
* case more info are returned from the server.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.Map;

/**
* This class holds information about a consumer. They can be access via getters. There is also
* This class holds information about a consumer. They can be accessed via getters. There is also
* {@link StreamConsumersInfo#getConsumerInfo()}} method that returns a generic {@code Map} in case
* more info are returned from the server.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.Map;

/**
* This class holds information about a consumer. They can be access via getters. There is also
* This class holds information about a consumer. They can be accessed via getters. There is also
* {@link StreamConsumersInfo#getConsumerInfo()}} method that returns a generic {@code Map} in case
* more info are returned from the server.
* @deprecated Use {@link StreamConsumerInfo}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/**
* This class holds information about a stream info with command {@code xinfo stream mystream full}.
* They can be access via getters. There is also {@link StreamFullInfo#getStreamFullInfo()} method
* They can be accessed via getters. There is also {@link StreamFullInfo#getStreamFullInfo()} method
* that returns a generic {@link Map} in case where more info are returned from the server.
*/
public class StreamFullInfo implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/**
* This class holds information about a stream group with command {@code xinfo stream mystream full}.
* They can be access via getters. There is also {@link StreamGroupFullInfo#getGroupFullInfo()}
* They can be accessed via getters. There is also {@link StreamGroupFullInfo#getGroupFullInfo()}
* method that returns a generic {@link Map} in case more info are returned from the server.
*/
public class StreamGroupFullInfo implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import redis.clients.jedis.StreamEntryID;

/**
* This class holds information about a stream group. They can be access via getters. There is also
* This class holds information about a stream group. They can be accessed via getters. There is also
* {@link StreamGroupInfo#getGroupInfo()} method that returns a generic {@code Map} in case more
* info are returned from the server.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/redis/clients/jedis/resps/StreamInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import redis.clients.jedis.StreamEntryID;

/**
* This class holds information about stream. They can be access via getters. There is also
* This class holds information about stream. They can be accessed via getters. There is also
* {@link StreamInfo#getStreamInfo} method that returns a generic {@code Map} in case more info are
* returned from the server.
*/
Expand Down
Loading

0 comments on commit 617bd50

Please sign in to comment.