Example #1
0
int proc_zclear(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(2);
	
	const Bytes &name = req[1];
	int64_t count = 0;
	while(1){
		ZIterator *it = serv->ssdb->zrange(name, 0, 1000);
		int num = 0;
		while(it->next()){
			int ret = serv->ssdb->zdel(name, it->key);
			if(ret == -1){
				resp->push_back("error");
				delete it;
				return 0;
			}
			num ++;
		};
		delete it;
		
		if(num == 0){
			break;
		}
		count += num;
	}
    serv->save_kv_stats();
	resp->reply_int(0, count);

	return 0;
}
Example #2
0
int proc_zrscan(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(6);

	uint64_t limit = req[5].Uint64();
	uint64_t offset = 0;
	if(req.size() > 6){
		offset = limit;
		limit = offset + req[6].Uint64();
	}
	ZIterator *it = serv->ssdb->zrscan(req[1], req[2], req[3], req[4], limit);
	if(offset > 0){
		it->skip(offset);
	}
	resp->push_back("ok");
	uint64_t size = 0;
	while(it->next()){
		size += it->key.size() + it->score.size();
		CHECK_SCAN_OUTPUT_LIMIT(size);
		resp->push_back(it->key);
		resp->push_back(it->score);
	}
	delete it;
	return 0;
}
Example #3
0
int proc_countbit(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(2);
	CHECK_KEY_RANGE(1);

	const Bytes &key = req[1];
	int start = 0;
	if(req.size() > 2){
		start = req[2].Int();
	}
	std::string val;
	int ret = serv->ssdb->get(key, &val);
	if(ret == -1){
		resp->push_back("error");
	}else{
		std::string str;
		int size = -1;
		if(req.size() > 3){
			size = req[3].Int();
			str = substr(val, start, size);
		}else{
			str = substr(val, start, val.size());
		}
		int count = bitcount(str.data(), str.size());
		resp->reply_int(0, count);
	}
	return 0;
}
Example #4
0
int proc_getrange(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(2);
	CHECK_KEY_RANGE(1);

	const Bytes &key = req[1];
	int start = 0;
	if(req.size() > 2){
		start = req[2].Int();
	}
	int size = -1;
	if(req.size() > 3){
		size = req[3].Int();
	}
	std::string val;
	int ret = serv->ssdb->get(key, &val);
	if(ret == -1){
		resp->push_back("error");
	}else{
		std::string str = str_slice(val, start, size);
		resp->push_back("ok");
		resp->push_back(str);
	}
	return 0;
}
Example #5
0
static inline
int proc_qtrim_func(NetworkServer *net, Link *link, const Request &req, Response *resp, int front_or_back){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(2);
	
	uint64_t size = 1;
	if(req.size() > 2){
		size = req[2].Uint64();
	}
		
	int count = 0;
	for(; count<size; count++){
		int ret;
		std::string item;
		if(front_or_back == QFRONT){
			ret = serv->ssdb->qpop_front(req[1], &item);
		}else{
			ret = serv->ssdb->qpop_back(req[1], &item);
		}
		if(ret <= 0){
			break;
		}
	}
	resp->reply_int(0, count);

	return 0;
}
Example #6
0
int proc_ndel(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(3);

	Locking l(&serv->expiration->mutex);
	int ret = serv->ssdb->ndel(req[1], req[2]);
	if(ret == -1){
		resp->push_back("error");
	}else{
		std::string buf;
		buf.append(1, DataType::NSET);
		buf.append(1, (uint8_t)req[1].size());
		buf.append(req[1].data(), req[1].size());

		int64_t s = req[2].Int64();
		if(s < 0){
			buf.append(1, '-');
		}else{
			buf.append(1, '=');
		}
		s = encode_score(s);

		buf.append((char *)&s, sizeof(int64_t));

		serv->expiration->del_ttl(Bytes(buf));

		resp->push_back("ok");
		resp->push_back("1");
	}
	return 0;
}
Example #7
0
int proc_qsize(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(2);

	int64_t ret = serv->ssdb->qsize(req[1]);
	resp->reply_int(ret, ret);
	return 0;
}
Example #8
0
int proc_zdel(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(3);

	int ret = serv->ssdb->zdel(req[1], req[2]);
    serv->save_kv_stats();
	resp->reply_bool(ret);
	return 0;
}
Example #9
0
int proc_zget(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(3);

	std::string score;
	int ret = serv->ssdb->zget(req[1], req[2], &score);
	resp->reply_get(ret, &score);
	return 0;
}
Example #10
0
int proc_getbit(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(3);
	CHECK_KEY_RANGE(1);

	int ret = serv->ssdb->getbit(req[1], req[2].Int());
	resp->reply_bool(ret);
	return 0;
}
Example #11
0
int proc_qback(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(2);

	std::string item;
	int ret = serv->ssdb->qback(req[1], &item);
	resp->reply_get(ret, &item);
	return 0;
}
Example #12
0
int proc_qrlist(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(4);

	uint64_t limit = req[3].Uint64();
	std::vector<std::string> list;
	int ret = serv->ssdb->qrlist(req[1], req[2], limit, &list);
	resp->reply_list(ret, list);
	return 0;
}
Example #13
0
int proc_qget(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(3);

	int64_t index = req[2].Int64();
	std::string item;
	int ret = serv->ssdb->qget(req[1], index, &item);
	resp->reply_get(ret, &item);
	return 0;
}
Example #14
0
int proc_get(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(2);
	CHECK_KEY_RANGE(1);

	std::string val;
	int ret = serv->ssdb->get(req[1], &val);
	resp->reply_get(ret, &val);
	return 0;
}
Example #15
0
int proc_ttl(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(2);
	CHECK_KEY_RANGE(1);

	int64_t ttl = serv->expiration->get_ttl(req[1]);
	resp->push_back("ok");
	resp->push_back(str(ttl));
	return 0;
}
Example #16
0
int proc_npop_back(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(3);

	const Bytes &name = req[1];
	uint64_t limit = req[2].Uint64();
	NIterator *it = serv->ssdb->nrscan(name, "", "", limit);
	npop(it, serv, name, resp);
	delete it;
	return 0;
}
Example #17
0
int proc_zexists(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(3);

	const Bytes &name = req[1];
	const Bytes &key = req[2];
	std::string val;
	int ret = serv->ssdb->zget(name, key, &val);
	resp->reply_bool(ret);
	return 0;
}
Example #18
0
int proc_qslice(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(4);

	int64_t begin = req[2].Int64();
	int64_t end = req[3].Int64();
	std::vector<std::string> list;
	int ret = serv->ssdb->qslice(req[1], begin, end, &list);
	resp->reply_list(ret, list);
	return 0;
}
Example #19
0
int proc_strlen(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(2);
	CHECK_KEY_RANGE(1);

	const Bytes &key = req[1];
	std::string val;
	int ret = serv->ssdb->get(key, &val);
	resp->reply_int(ret, val.size());
	return 0;
}
Example #20
0
int proc_qfix(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(2);

	int ret = serv->ssdb->qfix(req[1]);
	if(ret == -1){
		resp->push_back("error");
	}else{
		resp->push_back("ok");
	}
	return 0;
}
Example #21
0
void TacticalManager::cmdShowTokens( const StringVector & args )
{
	const char *strUsage [] =
	{
		"show_tokens enable[int]",
		"> enable: Enable behavior token rendering for a pariticular client",
	};

	CHECK_NUM_PARAMS( args, 2, strUsage );
	CHECK_INT_PARAM( viewmode, 1, strUsage );

	mShowTokenClient = viewmode;
}
Example #22
0
// dir := +1|-1
static int _zincr(SSDBServer *serv, const Request &req, Response *resp, int dir){
	CHECK_NUM_PARAMS(3);

	int64_t by = 1;
	if(req.size() > 3){
		by = req[3].Int64();
	}
	int64_t new_val;
	int ret = serv->ssdb->zincr(req[1], req[2], dir * by, &new_val);
    serv->save_kv_stats();
	resp->reply_int(ret, new_val);
	return 0;
}
Example #23
0
int proc_zsum(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(4);

	int64_t sum = 0;
	ZIterator *it = serv->ssdb->zscan(req[1], "", req[2], req[3], -1);
	while(it->next()){
		sum += str_to_int64(it->score);
	}
	delete it;
	
	resp->reply_int(0, sum);
	return 0;
}
Example #24
0
int proc_nrrange(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(4);

	uint64_t offset = req[2].Uint64();
	uint64_t limit = req[3].Uint64();
	NIterator *it = serv->ssdb->nrrange(req[1], offset, limit);
	resp->push_back("ok");
	while(it->next()){
		resp->push_back(it->val);
		resp->push_back(it->score);
	}
	delete it;
	return 0;
}
Example #25
0
int proc_set(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(3);
	CHECK_KEY_RANGE(1);

	int ret = serv->ssdb->set(req[1], req[2]);
	if(ret == -1){
		resp->push_back("error");
	}else{
        serv->save_kv_stats();
		resp->push_back("ok");
		resp->push_back("1");
	}
	return 0;
}
Example #26
0
int proc_qset(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(4);

	const Bytes &name = req[1];
	int64_t index = req[2].Int64();
	const Bytes &item = req[3];
	int ret = serv->ssdb->qset(name, index, item);
	if(ret == -1 || ret == 0){
		resp->push_back("error");
		resp->push_back("index out of range");
	}else{
		resp->push_back("ok");
	}
	return 0;
}
Example #27
0
// dir := +1|-1
static int _incr(SSDBServer *serv, const Request &req, Response *resp, int dir){
	CHECK_NUM_PARAMS(2);
	int64_t by = 1;
	if(req.size() > 2){
		by = req[2].Int64();
	}
	int64_t new_val;
	int ret = serv->ssdb->incr(req[1], dir * by, &new_val);
	if(ret == 0){
		resp->reply_status(-1, "value is not an integer or out of range");
	}else{
        serv->save_kv_stats();
		resp->reply_int(ret, new_val);
	}
	return 0;
}
Example #28
0
int proc_zkeys(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(6);

	uint64_t limit = req[5].Uint64();
	ZIterator *it = serv->ssdb->zscan(req[1], req[2], req[3], req[4], limit);
	resp->push_back("ok");
	uint64_t size = 0;
	while(it->next()){
		size += it->key.size();
		CHECK_SCAN_OUTPUT_LIMIT(size);
		resp->push_back(it->key);
	}
	delete it;
	return 0;
}
Example #29
0
int proc_setrange(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(4);
	CHECK_KEY_RANGE(1);

	const Bytes &key = req[1];
	int offset = req[2].Int();
	if(offset < 0 || errno != 0){
		resp->reply_client_error("offset is not an numeric or out of range");
		return 0;
	}
	int ret = serv->ssdb->setrange(key, offset, req[3]);
    serv->save_kv_stats();
	resp->reply_int(ret, ret);
	return 0;
}
Example #30
0
int proc_multi_zsize(NetworkServer *net, Link *link, const Request &req, Response *resp){
	SSDBServer *serv = (SSDBServer *)net->data;
	CHECK_NUM_PARAMS(2);

	resp->push_back("ok");
	for(Request::const_iterator it=req.begin()+1; it!=req.end(); it++){
		const Bytes &key = *it;
		int64_t ret = serv->ssdb->zsize(key);
		resp->push_back(key.String());
		if(ret == -1){
			resp->push_back("-1");
		}else{
			resp->add(ret);
		}
	}
	return 0;
}