Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

HSET fixes, now the new pointer is stored back in the object pointer …

…field
  • Loading branch information...
commit cbba7dd7c90f7b5b845d1dea86390572e5b4fa2c 1 parent 18e61fa
@antirez authored
Showing with 42 additions and 2 deletions.
  1. +28 −2 redis.c
  2. +7 −0 redis.conf
  3. +7 −0 zipmap.c
View
30 redis.c
@@ -226,6 +226,10 @@
#define APPENDFSYNC_ALWAYS 1
#define APPENDFSYNC_EVERYSEC 2
+/* Hashes related defaults */
+#define REDIS_HASH_MAX_ZIPMAP_ENTRIES 64
+#define REDIS_HASH_MAX_ZIPMAP_VALUE 512
+
/* We can print the stacktrace, so our assert is defined this way: */
#define redisAssert(_e) ((_e)?(void)0 : (_redisAssert(#_e,__FILE__,__LINE__),_exit(1)))
static void _redisAssert(char *estr, char *file, int line);
@@ -391,6 +395,9 @@ struct redisServer {
off_t vm_page_size;
off_t vm_pages;
unsigned long long vm_max_memory;
+ /* Hashes config */
+ size_t hash_max_zipmap_entries;
+ size_t hash_max_zipmap_value;
/* Virtual memory state */
FILE *vm_fp;
int vm_fd;
@@ -1465,6 +1472,8 @@ static void initServerConfig() {
server.vm_max_memory = 1024LL*1024*1024*1; /* 1 GB of RAM */
server.vm_max_threads = 4;
server.vm_blocked_clients = 0;
+ server.hash_max_zipmap_entries = REDIS_HASH_MAX_ZIPMAP_ENTRIES;
+ server.hash_max_zipmap_value = REDIS_HASH_MAX_ZIPMAP_VALUE;
resetServerSaveParams();
@@ -1725,6 +1734,12 @@ static void loadServerConfig(char *filename) {
server.vm_pages = strtoll(argv[1], NULL, 10);
} else if (!strcasecmp(argv[0],"vm-max-threads") && argc == 2) {
server.vm_max_threads = strtoll(argv[1], NULL, 10);
+ } else if (!strcasecmp(argv[0],"hash-max-zipmap-entries") && argc == 2){
+ server.hash_max_zipmap_entries = strtol(argv[1], NULL, 10);
+ } else if (!strcasecmp(argv[0],"hash-max-zipmap-value") && argc == 2){
+ server.hash_max_zipmap_value = strtol(argv[1], NULL, 10);
+ } else if (!strcasecmp(argv[0],"vm-max-threads") && argc == 2) {
+ server.vm_max_threads = strtoll(argv[1], NULL, 10);
} else {
err = "Bad directive or wrong number of arguments"; goto loaderr;
}
@@ -2603,7 +2618,17 @@ static void freeZsetObject(robj *o) {
}
static void freeHashObject(robj *o) {
- dictRelease((dict*) o->ptr);
+ switch (o->encoding) {
+ case REDIS_ENCODING_HT:
+ dictRelease((dict*) o->ptr);
+ break;
+ case REDIS_ENCODING_ZIPMAP:
+ zfree(o->ptr);
+ break;
+ default:
+ redisAssert(0);
+ break;
+ }
}
static void incrRefCount(robj *o) {
@@ -5577,7 +5602,7 @@ static void zrankCommand(redisClient *c) {
}
}
-/* ==================================== Hash ================================ */
+/* =================================== Hashes =============================== */
static void hsetCommand(redisClient *c) {
int update = 0;
robj *o = lookupKeyWrite(c->db,c->argv[1]);
@@ -5597,6 +5622,7 @@ static void hsetCommand(redisClient *c) {
zm = zipmapSet(zm,c->argv[2]->ptr,sdslen(c->argv[2]->ptr),
c->argv[3]->ptr,sdslen(c->argv[3]->ptr),&update);
+ o->ptr = zm;
} else {
if (dictAdd(o->ptr,c->argv[2],c->argv[3]) == DICT_OK) {
incrRefCount(c->argv[2]);
View
7 redis.conf
@@ -271,3 +271,10 @@ glueoutputbuf yes
# your development environment so that we can test it better.
shareobjects no
shareobjectspoolsize 1024
+
+# Hashes are encoded in a special way (much more memory efficient) when they
+# have at max a given numer of elements, and the biggest element does not
+# exceed a given threshold. You can configure this limits with the following
+# configuration directives.
+hash-max-zipmap-entries 64
+hash-max-zipmap-value 512
View
7 zipmap.c
@@ -405,6 +405,13 @@ int main(void) {
unsigned char *zm;
zm = zipmapNew();
+
+ zm = zipmapSet(zm,(unsigned char*) "name",4, (unsigned char*) "foo",3,NULL);
+ zm = zipmapSet(zm,(unsigned char*) "surname",7, (unsigned char*) "foo",3,NULL);
+ zm = zipmapSet(zm,(unsigned char*) "age",3, (unsigned char*) "foo",3,NULL);
+ zipmapRepr(zm);
+ exit(1);
+
zm = zipmapSet(zm,(unsigned char*) "hello",5, (unsigned char*) "world!",6,NULL);
zm = zipmapSet(zm,(unsigned char*) "foo",3, (unsigned char*) "bar",3,NULL);
zm = zipmapSet(zm,(unsigned char*) "foo",3, (unsigned char*) "!",1,NULL);
Please sign in to comment.
Something went wrong with that request. Please try again.