+static void hdelCommand(redisClient *c) {
+ robj *o = lookupKeyRead(c->db,c->argv[1]);
+
+ if (o == NULL) {
+ addReply(c,shared.czero);
+ return;
+ } else {
+ int deleted = 0;
+
+ if (o->type != REDIS_HASH) {
+ addReply(c,shared.wrongtypeerr);
+ return;
+ }
+
+ if (o->encoding == REDIS_ENCODING_ZIPMAP) {
+ o->ptr = zipmapDel((unsigned char*) o->ptr,
+ (unsigned char*) c->argv[2]->ptr,
+ sdslen(c->argv[2]->ptr), &deleted);
+ } else {
+ deleted = dictDelete((dict*)o->ptr,c->argv[2]) == DICT_OK;
+ }
+ addReply(c,deleted ? shared.cone : shared.czero);
+ }
+}
+
+static void convertToRealHash(robj *o) {
+ unsigned char *key, *val, *p, *zm = o->ptr;
+ unsigned int klen, vlen;
+ dict *dict = dictCreate(&hashDictType,NULL);
+
+ assert(o->type == REDIS_HASH && o->encoding != REDIS_ENCODING_HT);
+ p = zipmapRewind(zm);
+ while((p = zipmapNext(p,&key,&klen,&val,&vlen)) != NULL) {
+ robj *keyobj, *valobj;
+
+ keyobj = createStringObject((char*)key,klen);
+ valobj = createStringObject((char*)val,vlen);
+ tryObjectEncoding(keyobj);
+ tryObjectEncoding(valobj);
+ dictAdd(dict,keyobj,valobj);
+ }
+ o->encoding = REDIS_ENCODING_HT;
+ o->ptr = dict;
+ zfree(zm);
+}
+