Exemplo n.º 1
0
int z_keys_star(void *cptr, char *arg) {
	redisClient *c = (redisClient *)cptr;
	robj *argv[2], *keys, *star;

	printf("z_keys_star: %s\n", arg);

	keys = createStringObject("KEYS", 4);
	star = createStringObject("*", 1);

	argv[0] = keys;
	argv[1] = star;

	c->argv = argv;
	c->argc = 2;

	keysCommand(c);

	freeStringObject(keys);
	freeStringObject(star);

	c->argv = NULL;
	c->argc = 0;

	return 0;
}
Exemplo n.º 2
0
int z_sadd(void *cptr, char * name, char * val) {
	redisClient *c = (redisClient *)cptr;
	robj *argv[10], *sadd, *rkey, *rval;

	sadd = createStringObject("SADD", 4);
	rkey = createStringObject(name, strlen(name));
	rval = createStringObject(val, strlen(val));

	argv[0] = sadd;
	argv[1] = rkey;
	argv[2] = rval;

	c->argv = argv;
	c->argc = 3;

	saddCommand(c);

	c->argv = NULL;
	c->argc = 0;

	freeStringObject(sadd);
	freeStringObject(rkey);
	// FAILS! tryObjectEncoding() in t_set.c .. freeStringObject(rval);

	return 0;
}
Exemplo n.º 3
0
int z_incr_key(void *cptr, char *arg) {
	redisClient *c = (redisClient *)cptr;
	robj *argv[2], *cmd, *key;
	int i, increment_max = 1000;

	printf("z_incr_key: %s\n", arg);

	z_set(c, "incr", "1");

	cmd = createStringObject("INCR", 4);
	key = createStringObject("incr", 4);

	argv[0] = cmd;
	argv[1] = key;
	
	c->argv = argv;
	c->argc = 2;

	if(arg) {
		increment_max = atoi(arg);
	}

	for(i = 0; i < increment_max; i++) {
		incrDecrCommand(c, 1);
	}

	freeStringObject(cmd);
	freeStringObject(key);

	c->argv = NULL;
	c->argc = 0;

	return 0;
}
Exemplo n.º 4
0
int z_set(void *cptr, char * key, char * val) {
	redisClient *c = (redisClient *) cptr;
	robj *rkey, *rval;
	rkey = createStringObject(key, strlen(key));
	rval = createStringObject(val, strlen(val));

	setGenericCommand(c, 0, rkey, rval, NULL, 0, NULL, NULL);

	freeStringObject(rkey);
	freeStringObject(rval);

	return 0;
}
Exemplo n.º 5
0
void decrRefCount(void *obj) {
    robj *o = obj;
    if (o->refcount <= 0) redisPanic("decrRefCount against refcount <= 0");
    if (o->refcount == 1) {
        switch(o->type) {
        case REDIS_STRING:
            freeStringObject(o);
            break;
        case REDIS_LIST:
            freeListObject(o);
            break;
        case REDIS_SET:
            freeSetObject(o);
            break;
        case REDIS_ZSET:
            freeZsetObject(o);
            break;
        case REDIS_HASH:
            freeHashObject(o);
            break;
        default:
            redisPanic("Unknown object type");
            break;
        }
        zfree(o);
    } else {
        o->refcount--;
    }
}
Exemplo n.º 6
0
void decrRefCount(void *obj) {
    robj *o = obj;

    if (o->refcount <= 0) redisPanic("decrRefCount against refcount <= 0");
    if (--(o->refcount) == 0) {
        switch(o->type) {
        case REDIS_STRING:
            freeStringObject(o);
            break;
        case REDIS_LIST:
            freeListObject(o);
            break;
        case REDIS_SET:
            freeSetObject(o);
            break;
        case REDIS_ZSET:
            freeZsetObject(o);
            break;
        case REDIS_HASH:
            freeHashObject(o);
            break;
        default:
            redisPanic("Unknown object type");
            break;
        }
        o->ptr = NULL; /* defensive programming. We'll see NULL in traces. */
        zfree(o);
    }
}
Exemplo n.º 7
0
static void decrRefCount(void *obj) {
    robj *o = obj;

    /* Object is a key of a swapped out value, or in the process of being
     * loaded. */
    if (server.vm_enabled &&
        (o->storage == REDIS_VM_SWAPPED || o->storage == REDIS_VM_LOADING))
    {
        if (o->storage == REDIS_VM_SWAPPED || o->storage == REDIS_VM_LOADING) {
            redisAssert(o->refcount == 1);
        }
        if (o->storage == REDIS_VM_LOADING) vmCancelThreadedIOJob(obj);
        redisAssert(o->type == REDIS_STRING);
        freeStringObject(o);
        vmMarkPagesFree(o->vm.page,o->vm.usedpages);
        pthread_mutex_lock(&server.obj_freelist_mutex);
        if (listLength(server.objfreelist) > REDIS_OBJFREELIST_MAX ||
            !listAddNodeHead(server.objfreelist,o))
            zfree(o);
        pthread_mutex_unlock(&server.obj_freelist_mutex);
        server.vm_stats_swapped_objects--;
        return;
    }
    /* Object is in memory, or in the process of being swapped out. */
    if (--(o->refcount) == 0) {
        if (server.vm_enabled && o->storage == REDIS_VM_SWAPPING)
            vmCancelThreadedIOJob(obj);
        switch(o->type) {
        case REDIS_STRING: freeStringObject(o); break;
        case REDIS_LIST: freeListObject(o); break;
        case REDIS_SET: freeSetObject(o); break;
        case REDIS_ZSET: freeZsetObject(o); break;
        case REDIS_HASH: freeHashObject(o); break;
        default: redisAssert(0); break;
        }
        if (server.vm_enabled) pthread_mutex_lock(&server.obj_freelist_mutex);
        if (listLength(server.objfreelist) > REDIS_OBJFREELIST_MAX ||
            !listAddNodeHead(server.objfreelist,o))
            zfree(o);
        if (server.vm_enabled) pthread_mutex_unlock(&server.obj_freelist_mutex);
    }
}
Exemplo n.º 8
0
void decrRefCount(robj *o) {
    if (o->refcount <= 0) serverPanic("decrRefCount against refcount <= 0");
    if (o->refcount == 1) {
        switch(o->type) {
        case OBJ_STRING: freeStringObject(o); break;
        default: serverPanic("Unknown object type"); break;
        }
        zfree(o);
    } else {
        o->refcount--;
    }
}
Exemplo n.º 9
0
void freeRedisObject(robj *o) {
    switch(o->type) {
    case REDIS_STRING: freeStringObject(o); break;
    case REDIS_LIST: freeListObject(o); break;
    case REDIS_SET: freeSetObject(o); break;
    case REDIS_ZSET: freeZsetObject(o); break;
    case REDIS_HASH: freeHashObject(o); break;
    case REDIS_SSS: freeSssObject (o); break;
    default: redisPanic("Unknown object type"); break;
    }
    zfree(o);
}
Exemplo n.º 10
0
void freeObject(robj *o) {
    if (o->constant) return;
    
    switch(o->type) {
    case OBJ_STRING: freeStringObject(o); break;
    case OBJ_LIST: freeListObject(o); break;
    case OBJ_SET: freeSetObject(o); break;
    case OBJ_ZSET: freeZsetObject(o); break;
    case OBJ_HASH: freeHashObject(o); break;
    default: serverPanic("Unknown object type"); break;
    }
    dfree(o);
}
Exemplo n.º 11
0
int z_sunion(void *cptr, char *arg) {
	redisClient *c = (redisClient *)cptr;
	robj * argv[3], *sunion, *set1, *set2;
	char *ptr_set1, *ptr_set2;

	printf("z_sunion: %s\n", arg);

	if(!arg) return -1;

	ptr_set1 = strtok(arg, ",");
	if(!ptr_set1) return -1;

	ptr_set2 = strtok(NULL, "");
	if(!ptr_set2) return -1;

	sunion = createStringObject("SUNION", 6);
	set1 = createStringObject(ptr_set1, strlen(ptr_set1));
	set2 = createStringObject(ptr_set2, strlen(ptr_set2));

	argv[0] = sunion;
	argv[1] = set1;
	argv[2] = set2;

	c->argv = argv;
	c->argc = 3;

	sunionCommand(c);

	c->argv = NULL;
	c->argc = 0;

	freeStringObject(sunion);
	freeStringObject(set1);
	freeStringObject(set2);

	return 0;
}
Exemplo n.º 12
0
void decrRefCount(robj *o) {
    if (o->refcount == 1) {
        switch(o->type) {
        case OBJ_STRING: freeStringObject(o); break;
        case OBJ_HASH: freeHashObject(o); break;
        case OBJ_HEAPQ: freeHeapqObject(o); break;
        case OBJ_FTS: freeFTSObject(o); break;
        default: rr_log(RR_LOG_ERROR, "Unknown object type"); break;
        }
        rr_free(o);
    } else {
        if (o->refcount <= 0) rr_log(RR_LOG_ERROR, "decrRefCount against refcount <= 0");
        if (o->refcount != OBJ_SHARED_REFCOUNT) o->refcount--;
    }
}
Exemplo n.º 13
0
void decrRefCount(robj *o) {
    if (o->refcount <= 0) serverPanic("decrRefCount against refcount <= 0");
    if (o->refcount == 1) {
        switch(o->type) {
        case OBJ_STRING: freeStringObject(o); break;
        case OBJ_LIST: freeListObject(o); break;
        case OBJ_SET: freeSetObject(o); break;
        case OBJ_ZSET: freeZsetObject(o); break;
        case OBJ_HASH: freeHashObject(o); break;
        default: serverPanic("Unknown object type"); break;
        }
        dfree(o);
    } else {
        o->refcount--;
    }
}
Exemplo n.º 14
0
//引用计数减1
void decrRefCount(robj *o) {
    if (o->refcount <= 0) serverPanic("decrRefCount against refcount <= 0");

    //当引用对象等于1时,在操作引用计数减1,直接释放对象的ptr和对象空间
    if (o->refcount == 1) {
        switch(o->type) {
        case OBJ_STRING: freeStringObject(o); break;
        case OBJ_LIST: freeListObject(o); break;
        case OBJ_SET: freeSetObject(o); break;
        case OBJ_ZSET: freeZsetObject(o); break;
        case OBJ_HASH: freeHashObject(o); break;
        default: serverPanic("Unknown object type"); break;
        }
        zfree(o);
    } else {
        o->refcount--;  //否则减1
    }
}
Exemplo n.º 15
0
void decrRefCount(void *obj) {
    robj *o = obj;

    /* Object is a swapped out value, or in the process of being loaded. */
    if (server.vm_enabled &&
        (o->storage == REDIS_VM_SWAPPED || o->storage == REDIS_VM_LOADING))
    {
        vmpointer *vp = obj;
        if (o->storage == REDIS_VM_LOADING) vmCancelThreadedIOJob(o);
        vmMarkPagesFree(vp->page,vp->usedpages);
        server.vm_stats_swapped_objects--;
        zfree(vp);
        return;
    }

    if (o->refcount <= 0) redisPanic("decrRefCount against refcount <= 0");
    /* Object is in memory, or in the process of being swapped out.
     *
     * If the object is being swapped out, abort the operation on
     * decrRefCount even if the refcount does not drop to 0: the object
     * is referenced at least two times, as value of the key AND as
     * job->val in the iojob. So if we don't invalidate the iojob, when it is
     * done but the relevant key was removed in the meantime, the
     * complete jobs handler will not find the key about the job and the
     * assert will fail. */
    if (server.vm_enabled && o->storage == REDIS_VM_SWAPPING)
        vmCancelThreadedIOJob(o);
    if (--(o->refcount) == 0) {
        switch(o->type) {
        case REDIS_STRING: freeStringObject(o); break;
        case REDIS_LIST: freeListObject(o); break;
        case REDIS_SET: freeSetObject(o); break;
        case REDIS_ZSET: freeZsetObject(o); break;
        case REDIS_HASH: freeHashObject(o); break;
        default: redisPanic("Unknown object type"); break;
        }
        o->ptr = NULL; /* defensive programming. We'll see NULL in traces. */
        if (server.vm_enabled) pthread_mutex_lock(&server.obj_freelist_mutex);
        if (listLength(server.objfreelist) > REDIS_OBJFREELIST_MAX ||
            !listAddNodeHead(server.objfreelist,o))
            zfree(o);
        if (server.vm_enabled) pthread_mutex_unlock(&server.obj_freelist_mutex);
    }
}
Exemplo n.º 16
0
void decrRefCount(void *obj) {
		robj *o = obj;

		if (o->refcount <= 0) redisPanic("decrRefCount against refcount <= 0");
		/* Object is in memory, or in the process of being swapped out.
		 *
		 * If the object is being swapped out, abort the operation on
		 * decrRefCount even if the refcount does not drop to 0: the object
		 * is referenced at least two times, as value of the key AND as
		 * job->val in the iojob. So if we don't invalidate the iojob, when it is
		 * done but the relevant key was removed in the meantime, the
		 * complete jobs handler will not find the key about the job and the
		 * assert will fail. */
		if (o->refcount == 1) {
				switch(o->type) {
						case REDIS_STRING: freeStringObject(o); break;
						default: redisPanic("Unknown object type"); break;
				}
				zfree(o);
		} else {
				o->refcount--;
		}
}