Skip to content

Commit 5f9d005

Browse files
nsdivmp911de
authored andcommitted
DATAREDIS-444 - Return result of delete in DefaultHashOperation.
Delete in DefaultHashOperation returns now the result of the HDEL command. Original pull request: spring-projects#184. CLA: 169220160326121428 (Ninad Divadkar)
1 parent 1b3fe81 commit 5f9d005

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

src/main/java/org/springframework/data/redis/core/BoundHashOperations.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public interface BoundHashOperations<H, HK, HV> extends BoundKeyOperations<H> {
5252

5353
Long size();
5454

55-
void delete(Object... keys);
55+
Long delete(Object... keys);
5656

5757
Map<HK, HV> entries();
5858

src/main/java/org/springframework/data/redis/core/DefaultBoundHashOperations.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ class DefaultBoundHashOperations<H, HK, HV> extends DefaultBoundKeyOperations<H>
3838
* Constructs a new <code>DefaultBoundHashOperations</code> instance.
3939
*
4040
* @param key
41-
* @param template
41+
* @param operations
4242
*/
4343
public DefaultBoundHashOperations(H key, RedisOperations<H, ?> operations) {
4444
super(key, operations);
4545
this.ops = operations.opsForHash();
4646
}
4747

48-
public void delete(Object... keys) {
49-
ops.delete(getKey(), keys);
48+
public Long delete(Object... keys) {
49+
return ops.delete(getKey(), keys);
5050
}
5151

5252
public HV get(Object key) {

src/main/java/org/springframework/data/redis/core/DefaultHashOperations.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,14 @@ public List<byte[]> doInRedis(RedisConnection connection) {
201201
return deserializeHashValues(rawValues);
202202
}
203203

204-
public void delete(K key, Object... hashKeys) {
204+
public Long delete(K key, Object... hashKeys) {
205205
final byte[] rawKey = rawKey(key);
206206
final byte[][] rawHashKeys = rawHashKeys(hashKeys);
207207

208-
execute(new RedisCallback<Object>() {
208+
return execute(new RedisCallback<Long>() {
209209

210-
public Object doInRedis(RedisConnection connection) {
211-
connection.hDel(rawKey, rawHashKeys);
212-
return null;
210+
public Long doInRedis(RedisConnection connection) {
211+
return connection.hDel(rawKey, rawHashKeys);
213212
}
214213
}, true);
215214
}

src/main/java/org/springframework/data/redis/core/HashOperations.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
public interface HashOperations<H, HK, HV> {
3030

31-
void delete(H key, Object... hashKeys);
31+
Long delete(H key, Object... hashKeys);
3232

3333
Boolean hasKey(H key, Object hashKey);
3434

src/test/java/org/springframework/data/redis/core/DefaultHashOperationsTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@ public void testDelete() {
134134
HV val2 = hashValueFactory.instance();
135135
hashOps.put(key, key1, val1);
136136
hashOps.put(key, key2, val2);
137-
hashOps.delete(key, key1, key2);
137+
Long numDeleted = hashOps.delete(key, key1, key2);
138138
assertTrue(hashOps.keys(key).isEmpty());
139+
assertEquals(2L, numDeleted.longValue());
139140
}
140141

141142
/**

0 commit comments

Comments
 (0)