- if (o->encoding == REDIS_ENCODING_ZIPMAP) {
- key = getDecodedObject(key);
- o->ptr = zipmapDel(o->ptr,key->ptr,sdslen(key->ptr), &deleted);
- decrRefCount(key);
+
+ if (o->encoding == REDIS_ENCODING_ZIPLIST) {
+ unsigned char *zl, *fptr, *vptr;
+
+ field = getDecodedObject(field);
+
+ zl = o->ptr;
+ fptr = ziplistIndex(zl, ZIPLIST_HEAD);
+ while (fptr != NULL) {
+ /* Compare field in ziplist with specified field */
+ if (ziplistCompare(fptr, field->ptr, sdslen(field->ptr))) {
+ zl = ziplistDelete(zl,&fptr);
+ zl = ziplistDelete(zl,&fptr);
+ o->ptr = zl;
+ deleted = 1;
+ break;
+ }
+
+ /* Grab pointer to the value (fptr points to the field) */
+ vptr = ziplistNext(zl, fptr);
+ redisAssert(vptr != NULL);
+
+ /* Grab pointer (if any) to the next field */
+ fptr = ziplistNext(zl, vptr);
+ }
+
+ decrRefCount(field);
+
+ } else if (o->encoding == REDIS_ENCODING_HT) {
+ if (dictDelete((dict*)o->ptr, field) == REDIS_OK) {
+ deleted = 1;
+
+ /* Always check if the dictionary needs a resize after a delete. */
+ if (htNeedsResize(o->ptr)) dictResize(o->ptr);
+ }
+