int CodisClient::incrby(string key, int incr, int tt)
{

    Reply rep = RedisCommand(Command("INCRBY")(key)(int2string(incr)), tt);

    return (rep.error()) ? 0 : rep.integer();
}
bool CodisClient::exists(string key, int tt)
{
    Reply rep = RedisCommand(Command("EXISTS")(key), tt);

    return rep.integer()==1;

}
Beispiel #3
0
status_t
Server::_Listener()
{
	status_t result;
	uint32 size;
	void* buffer = NULL;

	while (!fThreadCancel) {
		result = fConnection->Receive(&buffer, &size);
		if (result == B_NO_MEMORY)
			continue;
		else if (result != B_OK) {
			fThreadError = result;
			return result;
		}

		ASSERT(buffer != NULL && size > 0);
		Reply* reply = new(std::nothrow) Reply(buffer, size);
		if (reply == NULL) {
			free(buffer);
			continue;
		}

		Request* req = fRequests.FindRequest(reply->GetXID());
		if (req != NULL) {
			*req->fReply = reply;
			req->fDone = true;
			req->fEvent.NotifyAll();
		} else
			delete reply;
	}

	return B_OK;
}
vector<string> CodisClient::mget(vector<string>& keys, int tt)
{
    vector<string> values;

    Command comm("MGET");
    for (size_t i=0; i<keys.size(); i++)
    {
        comm(keys[i]);
    }


    Reply rep = RedisCommand(comm, tt);

    if (rep.error())
    {
        return values;
    }
    else
    {
        for (size_t i=0; i<rep.elements().size(); i++)
        {
            values.push_back(rep.elements()[i].str());
        }
    }

    return values;
}
TEST_F(ReplyInterpreterTest, execute_calls_caller) {
    // Register metatypes
    qRegisterMetaType<Reply>();
    qRegisterMetaType<types::QtGpsLocation>();
    MetaTypeRegistrar& registrar = MetaTypeRegistrar::instance();
    registrar.registerReplyMetaType<types::QtGpsLocation>();

    // Create a mock callback
    QSharedPointer<MockCallback<joynr::types::QtGpsLocation>> callback(new MockCallback<joynr::types::QtGpsLocation>());
    int myAltitude = 13;
    EXPECT_CALL(*callback, onSuccess(Property(&types::QtGpsLocation::getAltitude, myAltitude)))
                .Times(1);

    // Create a reply caller
    QSharedPointer<IReplyCaller> icaller(new ReplyCaller<types::QtGpsLocation>(
            [callback](const RequestStatus& status, const types::QtGpsLocation& location) {
                callback->onSuccess(location);
            },
            [](const RequestStatus& status){
            }));

    // Create a reply
    types::QtGpsLocation location;
    location.setAltitude(myAltitude);
    QList<QVariant> response;
    response.append(QVariant::fromValue(location));
    Reply reply;
    reply.setResponse(response);

    // Interpret the reply
    IReplyInterpreter& interpreter = registrar.getReplyInterpreter(Util::getTypeId<types::QtGpsLocation>());
    interpreter.execute(icaller, reply);
}
TEST(RedisClientTest, getRedisCommand)
{
	vector<string> command;
	command.push_back("get");
	command.push_back("kk");
	Reply ret = client.RedisCommand(command);
	EXPECT_STREQ(ret.str().c_str(), "vv");
}
bool CodisClient::setex(string key, string value, int seconds, int tt)
{
    if (value.length()>1048576) {
        throw myex;
    }
    Reply rep = RedisCommand(Command("SETEX")(key)(int2string(seconds))(value), tt);

    return rep.str() == "OK";
}
bool CodisClient::setnx(string key, string value, int tt)
{
    if (value.length()>1048576) {
        throw myex;
    }
    Reply rep = RedisCommand(Command("SETNX")(key)(value), tt);

    return rep.integer() == 1;
}
bool CodisClient::hset(string key, string field, string value, int tt)
{
    if (value.length()>1048576) {
        throw myex;
    }
    Reply rep = RedisCommand(Command("HSET")(key)(field)(value), tt);

    return rep.integer();
}
Beispiel #10
0
long CodisClient::append(string key, string value, int tt)
{
    if (value.length()>1048576) {
        throw myex;
    }
    Reply rep = RedisCommand(Command("APPEND")(key)(value), tt);

    return rep.integer();
}
Beispiel #11
0
bool CodisClient::lset(string key, int index, string value, int tt)
{
    if (value.length()>1048576) {
        throw myex;
    }
    Reply rep = RedisCommand(Command("LSET")(key)(int2string(index))(value), tt);

    return rep.str()==string("OK");
}
Beispiel #12
0
int CodisClient::rpush(string key, string value, int tt)
{
    if (value.length()>1048576) {
        throw myex;
    }
    Reply rep = RedisCommand(Command("RPUSH")(key)(value), tt);

    return rep.integer();
}
Beispiel #13
0
Reply Reply::GetReply(Reply::StatusType status)
{
    Reply reply;
    reply.status = status;
    const ConstBuffer& statusBuffer = Replies::ToBuffer(status);
    reply.content.data.reset(const_cast<char*>(statusBuffer.data), [](const char*){} );
    reply.content.size = statusBuffer.size;
    reply.SetHeaders(reply.content.size, "text/html");
    return reply;
}
Beispiel #14
0
vector<string> CodisClient::lrange(string key, int start, int end, int tt)
{
    vector<string> values;
    Reply rep = RedisCommand(Command("LRANGE")(key)(int2string(start))(int2string(end)), tt);

    for (size_t i=0; i<rep.elements().size(); i++)
    {
        values.push_back(rep.elements()[i].str());
    }

    return values;
}
Beispiel #15
0
vector<string> CodisClient::hkeys(string key, int tt)
{
    vector<string> keys;
    Reply rep = RedisCommand(Command("HKEYS")(key), tt);

    for (size_t i=0; i<rep.elements().size(); i++)
    {
        keys.push_back(rep.elements()[i].str());
    }

    return keys;
}
Beispiel #16
0
vector<string> CodisClient::hvals(string key, int tt)
{
    vector<string> values;
    Reply rep = RedisCommand(Command("HVALS")(key), tt);

    for (size_t i=0; i<rep.elements().size(); i++)
    {
        values.push_back(rep.elements()[i].str());
    }

    return values;
}
Beispiel #17
0
string CodisClient::srandmember(string key, int tt)
{
    Reply rep = RedisCommand(Command("SRANDMEMBER")(key), tt);

    if (rep.error())
    {
        return "";
    }
    else
    {
        return rep.str();
    }
}
Beispiel #18
0
string CodisClient::spop(string key, int tt)
{
    Reply rep = RedisCommand(Command("SPOP")(key), tt);

    if (rep.error())
    {
        return "";
    }
    else
    {
        return rep.str();
    }
}
Beispiel #19
0
Reply Reply::StockReply(Reply::status_type status)
{
    Reply reply;
    reply.status = status;
    reply.content.clear();

    const std::string status_string = reply.ToString(status);
    reply.content.insert(reply.content.end(), status_string.begin(), status_string.end());
    reply.headers.emplace_back("Access-Control-Allow-Origin", "*");
    reply.headers.emplace_back("Content-Length", cast::integral_to_string(reply.content.size()));
    reply.headers.emplace_back("Content-Type", "text/html");
    return reply;
}
Beispiel #20
0
int CodisClient::sadd(string key, vector<string> members, int tt)
{
    Command comm("SADD");
    comm(key);
    for (size_t i=0; i<members.size(); i++)
    {
        comm(members[i]);
    }

    Reply rep = RedisCommand(comm, tt);

    return rep.integer();
}
Beispiel #21
0
string CodisClient::hget(string key, string field, int tt)
{
    Reply rep = RedisCommand(Command("HGET")(key)(field), tt);

    if (rep.error())
    {
        return "";
    }
    else
    {
        return rep.str();
    }
}
Beispiel #22
0
Scanner::Scanner(std::istream* in, std::unique_ptr<Message>& message) {
    if (!message) {
        lexer_.reset(new HeaderScanner(in));
    } else if (message->is_reply()) {
        Reply* reply = static_cast<Reply*>(message.get());
        if (reply->response_code() == STATUS_SeeOther)
            lexer_.reset(new ErrorScanner(in));
        else
            lexer_.reset(new MessageScanner(in, true));
    }

    if (!lexer_)
        lexer_.reset(new MessageScanner(in));
}
Beispiel #23
0
bool CodisClient::hgetall(string key, vector<string>& fields, vector<string>& values, int tt)
{
    Reply rep = RedisCommand(Command("HGETALL")(key), tt);

    if (rep.error()) return false;

    for (size_t i=1; i<rep.elements().size(); i+=2)
    {
        fields.push_back(rep.elements()[i-1].str());
        values.push_back(rep.elements()[i].str());
    }

    return true;
}
Beispiel #24
0
int CodisClient::del(vector<string>& keys, int tt)
{
    Command command("DEL");
    Reply rep;
    for (size_t i=0; i<keys.size(); i++)
    {
//		rep = RedisCommand(command(keys[i]));
        command(keys[i]);
    }

    rep = RedisCommand(command, tt);

    return rep.integer();
}
Beispiel #25
0
string CodisClient::getset(string key, string value, int tt)
{
    if (value.length()>1048576) {
        throw myex;
    }
    Reply rep = RedisCommand(Command("GETSET")(key)(value), tt);

    if (rep.error())
    {
        return "";
    }
    else
    {
        return rep.str();
    }
}
Beispiel #26
0
int CodisClient::rpush(string key, vector<string> values, int tt)
{
    Command comm("RPUSH");
    comm(key);
    for (size_t i=0; i<values.size(); i++)
    {
        if (values[i].length()>1048576) {
            throw myex;
        }
        comm(values[i]);
    }

    Reply rep = RedisCommand(comm, tt);

    return rep.integer();
}
Beispiel #27
0
/**
 * Handle a PortAssignment response.
 */
void UsbProDevice::HandlePortAssignmentResponse(RpcController *controller,
                                                string *response,
                                                ConfigureCallback *done,
                                                bool status,
                                                uint8_t port1_assignment,
                                                uint8_t port2_assignment) {
  if (!status) {
    controller->SetFailed("Get Port Assignments failed");
  } else {
    Reply reply;
    reply.set_type(ola::plugin::usbpro::Reply::USBPRO_PORT_ASSIGNMENT_REPLY);
    ola::plugin::usbpro::PortAssignmentReply *port_assignment_reply =
      reply.mutable_port_assignment();
    port_assignment_reply->set_port_assignment1(port1_assignment);
    port_assignment_reply->set_port_assignment2(port2_assignment);
    reply.SerializeToString(response);
  }
  done->Run();
}
Beispiel #28
0
vector<string> CodisClient::hmget(string key, vector<string>& fields, int tt)
{
    vector<string> values;
    Command command("HMGET");
    command(key);
    for (size_t i=0; i<fields.size(); i++)
    {
        command(fields[i]);
    }

    Reply rep = RedisCommand(command, tt);

    for (size_t i=0; i<rep.elements().size(); i++)
    {
        values.push_back(rep.elements()[i].str());
    }

    return values;
}
Beispiel #29
0
Reply Reply::StockReply(Reply::status_type status)
{
    Reply rep;
    rep.status = status;
    rep.content.clear();

    const std::string status_string = rep.ToString(status);
    rep.content.insert(rep.content.end(), status_string.begin(), status_string.end());
    rep.headers.resize(3);
    rep.headers[0].name = "Access-Control-Allow-Origin";
    rep.headers[0].value = "*";
    rep.headers[1].name = "Content-Length";

    std::string size_string = IntToString(rep.content.size());

    rep.headers[1].value = size_string;
    rep.headers[2].name = "Content-Type";
    rep.headers[2].value = "text/html";
    return rep;
}
void ReplyToString(Reply& reply, std::string &rep)
{
	stringstream stream;
	stream << reply.type() << ";"
			<< reply.str() << ";"
			<< reply.error() << ";"
			<< reply.integer() << ";";

	std::vector<Reply> elements = reply.elements();

	for (size_t i=0; i<elements.size(); i++)
	{
		stream << elements[i].type() << ";"
				<< elements[i].str() << ";"
				<< elements[i].error() << ";"
				<< elements[i].integer() << ";";
	}

	rep = stream.str();
}