- /* Convert to real hash if the number of items is too large.
- * We don't check the max item size as this requires an O(N)
- * scan usually. */
- if (zipmapLen(o->ptr) > server.hash_max_zipmap_entries) {
- convertToRealHash(o);
+
+ /* Fix the object encoding, and make sure to convert the encoded
+ * data type into the base type if accordingly to the current
+ * configuration there are too many elements in the encoded data
+ * type. Note that we only check the length and not max element
+ * size as this is an O(N) scan. Eventually everything will get
+ * converted. */
+ switch(type) {
+ case REDIS_HASH_ZIPMAP:
+ o->type = REDIS_HASH;
+ o->encoding = REDIS_ENCODING_ZIPMAP;
+ if (zipmapLen(o->ptr) > server.hash_max_zipmap_entries)
+ convertToRealHash(o);
+ break;
+ case REDIS_LIST_ZIPLIST:
+ o->type = REDIS_LIST;
+ o->encoding = REDIS_ENCODING_ZIPLIST;
+ if (ziplistLen(o->ptr) > server.list_max_ziplist_entries)
+ listTypeConvert(o,REDIS_ENCODING_LINKEDLIST);
+ break;
+ case REDIS_SET_INTSET:
+ o->type = REDIS_SET;
+ o->encoding = REDIS_ENCODING_INTSET;
+ if (intsetLen(o->ptr) > server.set_max_intset_entries)
+ setTypeConvert(o,REDIS_ENCODING_HT);
+ break;
+ case REDIS_ZSET_ZIPLIST:
+ o->type = REDIS_ZSET;
+ o->encoding = REDIS_ENCODING_ZIPLIST;
+ if (zsetLength(o) > server.zset_max_ziplist_entries)
+ zsetConvert(o,REDIS_ENCODING_RAW);
+ break;
+ default:
+ redisPanic("Unknown enoding");
+ break;