RedisDBHandler implements IDBHandler { @Override public Map<Integer, byte[]> remove(String key) { Map<Integer, byte[]> removedMap = new HashMap<Integer, byte[]>(); try { if (hasKey(key)) { byte[] serializedKey = serialize(key); Set<byte[]> byteSequencIds = redis.hkeys(serializedKey); for (byte[] bs : byteSequencIds) { removedMap.put((Integer) deserialize(bs), redis.hget(serializedKey, bs)); redis.hdel(serializedKey, bs); } } } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } return removedMap; } RedisDBHandler(); synchronized Jedis getJedisConnection(); @Override String getDatabaseVendor(); byte[] serialize(Object obj); Object deserialize(byte[] bytes); @Override boolean hasKey(String key); @Override String put(String key, int sequenceId, byte[] value); @Override Map<Integer, byte[]> get(String key); @Override List<Integer> getSequenceIds(String key); @Override boolean update(String key, int sequenceId, byte[] value); @Override String store(byte[] value); @Override Map<Integer, byte[]> remove(String key);  }
@Test public void testRemove() { Map<Integer, byte[]> expectedMap = new HashMap<Integer, byte[]>(); String obtainedKey = ""; try { expectedMap.put(0, serialize("data1")); obtainedKey = dbHandler.store(serialize("data1")); Map<Integer, byte[]> map = new HashMap<Integer, byte[]>(); map = dbHandler.remove(obtainedKey); for (Integer i : map.keySet()) { assertTrue(Arrays.equals(expectedMap.get(i), map.get(i))); } assertFalse(dbHandler.hasKey(obtainedKey)); } catch (IOException e) { e.printStackTrace(); } }