Skip to content

Commit 1d898f1

Browse files
Fix jedis#hdel docs (#3290)
* Fix jedis#hdel docs * Apply suggestions from code review --------- Co-authored-by: M Sazzadul Hoque <[email protected]>
1 parent e536712 commit 1d898f1

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/main/java/redis/clients/jedis/Jedis.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5687,13 +5687,15 @@ public boolean hexists(final String key, final String field) {
56875687
}
56885688

56895689
/**
5690-
* Remove the specified field from an hash stored at key.
5690+
* Remove the specified field(s) from a hash stored at key. Specified fields that do not exist
5691+
* within this hash are ignored.
56915692
* <p>
56925693
* <b>Time complexity:</b> O(1)
56935694
* @param key
56945695
* @param fields
5695-
* @return If the field was present in the hash it is deleted and 1 is returned, otherwise 0 is
5696-
* returned and no operation is performed.
5696+
* @return The number of fields that were removed from the hash, not including specified but
5697+
* non-existing fields. If key does not exist, it is treated as an empty hash and this
5698+
* command returns 0.
56975699
*/
56985700
@Override
56995701
public long hdel(final String key, final String... fields) {

src/test/java/redis/clients/jedis/commands/jedis/HashesCommandsTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public void hexists() {
200200

201201
@Test
202202
public void hdel() {
203-
Map<String, String> hash = new HashMap<String, String>();
203+
Map<String, String> hash = new HashMap<>();
204204
hash.put("bar", "car");
205205
hash.put("car", "bar");
206206
jedis.hmset("foo", hash);
@@ -211,7 +211,7 @@ public void hdel() {
211211
assertNull(jedis.hget("foo", "bar"));
212212

213213
// Binary
214-
Map<byte[], byte[]> bhash = new HashMap<byte[], byte[]>();
214+
Map<byte[], byte[]> bhash = new HashMap<>();
215215
bhash.put(bbar, bcar);
216216
bhash.put(bcar, bbar);
217217
jedis.hmset(bfoo, bhash);
@@ -220,6 +220,13 @@ public void hdel() {
220220
assertEquals(0, jedis.hdel(bfoo, bfoo));
221221
assertEquals(1, jedis.hdel(bfoo, bbar));
222222
assertNull(jedis.hget(bfoo, bbar));
223+
224+
// Deleting multiple fields returns the right value.
225+
jedis.hmset("foo", hash);
226+
assertEquals(2, jedis.hdel("foo", "bar", "car", "dne"));
227+
228+
jedis.hmset(bfoo, bhash);
229+
assertEquals(2, jedis.hdel(bfoo, bbar, bcar, bbar1));
223230
}
224231

225232
@Test

0 commit comments

Comments
 (0)