RedisHash extends AbstractRedisData { public int hset(Region<ByteArrayWrapper, RedisData> region, ByteArrayWrapper key, List<ByteArrayWrapper> fieldsToSet, boolean nx) { int fieldsAdded = 0; AddsDeltaInfo deltaInfo = null; Iterator<ByteArrayWrapper> iterator = fieldsToSet.iterator(); while (iterator.hasNext()) { ByteArrayWrapper field = iterator.next(); ByteArrayWrapper value = iterator.next(); boolean added = true; boolean newField; if (nx) { newField = hashPutIfAbsent(field, value) == null; added = newField; } else { newField = hashPut(field, value) == null; } if (added) { if (deltaInfo == null) { deltaInfo = new AddsDeltaInfo(); } deltaInfo.add(field); deltaInfo.add(value); } if (newField) { fieldsAdded++; } } storeChanges(region, key, deltaInfo); return fieldsAdded; } RedisHash(List<ByteArrayWrapper> fieldsToSet);  RedisHash(); @Override synchronized void toData(DataOutput out); @Override void fromData(DataInput in); int hset(Region<ByteArrayWrapper, RedisData> region, ByteArrayWrapper key,
      List<ByteArrayWrapper> fieldsToSet, boolean nx); int hdel(Region<ByteArrayWrapper, RedisData> region, ByteArrayWrapper key,
      List<ByteArrayWrapper> fieldsToRemove); Collection<ByteArrayWrapper> hgetall(); int hexists(ByteArrayWrapper field); ByteArrayWrapper hget(ByteArrayWrapper field); int hlen(); int hstrlen(ByteArrayWrapper field); List<ByteArrayWrapper> hmget(List<ByteArrayWrapper> fields); Collection<ByteArrayWrapper> hvals(); Collection<ByteArrayWrapper> hkeys(); List<Object> hscan(Pattern matchPattern, int count, int cursor); long hincrby(Region<ByteArrayWrapper, RedisData> region, ByteArrayWrapper key,
      ByteArrayWrapper field, long increment); double hincrbyfloat(Region<ByteArrayWrapper, RedisData> region,
      ByteArrayWrapper key,
      ByteArrayWrapper field, double increment); @Override RedisDataType getType(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static final RedisHash NULL_REDIS_HASH; }
@SuppressWarnings("unchecked") @Test public void hset_stores_delta_that_is_stable() throws IOException { Region<ByteArrayWrapper, RedisData> region = Mockito.mock(Region.class); RedisHash o1 = createRedisHash("k1", "v1", "k2", "v2"); ByteArrayWrapper k3 = createByteArrayWrapper("k3"); ByteArrayWrapper v3 = createByteArrayWrapper("v3"); ArrayList<ByteArrayWrapper> adds = new ArrayList<>(); adds.add(k3); adds.add(v3); o1.hset(region, null, adds, false); assertThat(o1.hasDelta()).isTrue(); HeapDataOutputStream out = new HeapDataOutputStream(100); o1.toDelta(out); assertThat(o1.hasDelta()).isFalse(); ByteArrayDataInput in = new ByteArrayDataInput(out.toByteArray()); RedisHash o2 = createRedisHash("k1", "v1", "k2", "v2"); assertThat(o2).isNotEqualTo(o1); o2.fromDelta(in); assertThat(o2).isEqualTo(o1); }