void getsetCommand(redisClient *c) { if (getGenericCommand(c) == REDIS_ERR) return; c->argv[2] = tryObjectEncoding(c->argv[2]); setKey(c->db,c->argv[1],c->argv[2]); notifyKeyspaceEvent(REDIS_NOTIFY_STRING,"set",c->argv[1],c->db->id); server.dirty++; }
void getsetCommand(redisClient *c) { uint16_t version = sdsversion(c->argv[1]->ptr); if (getGenericCommand(c) == REDIS_ERR) return; c->argv[2] = tryObjectEncoding(c->argv[2]); if (c->returncode == REDIS_OK_NOT_EXIST) { sdsversion_change(c->argv[1]->ptr, 0); } else { if(c->version_care && version != 0 && version != c->version) { c->returncode = REDIS_ERR_VERSION_ERROR; return; } else { sdsversion_change(c->argv[1]->ptr, c->version); } } if(c->version_care) { sdsversion_add(c->argv[1]->ptr, 1); } dbSuperReplace(c->db,c->argv[1],c->argv[2]); incrRefCount(c->argv[2]); c->db->dirty++; if (c->expiretime > 0) { setExpire(c->db,c->argv[1],c->expiretime); } else if(c->expiretime == 0) { removeXExpire(c->db, c->argv[1]); } c->returncode = REDIS_OK; }
void getsetCommand(redisClient *c) { if (getGenericCommand(c) == REDIS_ERR) return; dbReplace(c->db,c->argv[1],c->argv[2]); incrRefCount(c->argv[2]); server.dirty++; removeExpire(c->db,c->argv[1]); }
char* CTPMessage::toByte() { int totalMessageSize = 2; // version and genericCommand int totalPackageSize = 0, i = 0; CTPParam* param = (CTPParam*)params.front(); while(param) { totalMessageSize += 2; totalMessageSize += param->getValueLength(); param = (CTPParam*) params.next(); } totalPackageSize = totalMessageSize +2; setPackageLength(totalPackageSize); // the whole package setBufferLength(totalPackageSize); // the same package that is in the buffer buffer = new char[totalPackageSize]; if (totalMessageSize < 255) { buffer[0] = 0x00; buffer[1] = (unsigned char)totalMessageSize; } else { int upper = 0, down = 0; upper = totalMessageSize >> 8 ; buffer[0] = (unsigned char)(upper); down = totalMessageSize; upper <<= 8; down = down ^ upper; buffer[1] = (unsigned char)down; } buffer[2] = getProtocolVersion(); buffer[3] = getGenericCommand(); char* p; if (totalPackageSize == 4) { goto finally; } p = &buffer[4]; param = (CTPParam*)params.front(); while(param) { p[i++] = param->getParamCode(); p[i++] = param->getValueLength(); memcpy(&p[i], param->getValue(), param->getValueLength()); i += param->getValueLength(); param = (CTPParam*) params.next(); } finally: return buffer; }
void getsetCommand(redisClient *c) { if (getGenericCommand(c) == REDIS_ERR) return; #ifdef AUTH_FEATURE /* Check mod permissions */ if (authCheckModOrReply(c) == REDIS_ERR) return; /* Check path permissions */ if (authCheckPathOrReply(c, c->argv[2]) == REDIS_ERR) return; #endif c->argv[2] = tryObjectEncoding(c->argv[2]); dbReplace(c->db,c->argv[1],c->argv[2]); incrRefCount(c->argv[2]); touchWatchedKey(c->db,c->argv[1]); server.dirty++; removeExpire(c->db,c->argv[1]); }
void getCommand(redisClient *c) { getGenericCommand(c); }
int32_t CTPMessage::parse(const char* package, int32_t maxPackageLen) { // This macro increments local pointer p or return error if out of bounds. #define IncP(Num) p+(Num)<end ? p+=(Num) : p = NULL LOG.debug("Parsing msg..."); int32_t ret = 0; setBufferLength(0); if (buffer) { delete [] buffer; buffer = NULL; } if (from) { delete [] from; from = NULL; } //get the length of the message (first 2 bytes) int messageLen = (int)((unsigned char)package[0]); int messageLen1 = (int)((unsigned char)package[1]); messageLen <<= 8; messageLen = messageLen | messageLen1; //LOG.debug("messageLen = %d", messageLen); if (maxPackageLen) { // Safe check on message length if (messageLen+2 > maxPackageLen) { messageLen = maxPackageLen - 2; LOG.info("Warning: recv received only %d bytes: set messageLength to %d", maxPackageLen, messageLen); } else if (messageLen+2 < maxPackageLen) { LOG.info("Warning: recv received more bytes: %d", maxPackageLen); } } setPackageLength(messageLen + 2); // variables at the beginning and the end of the message const char *p = &package[2], *end = p + messageLen; ////////// Save the msg received to file //char name[32]; //sprintf(name, "/dump/%d.dmp", time((void*)NULL)); //saveFile(name, package, messageLen+2, true); //const char* start = p; ////////// // Protocol version if (p == NULL) { LOG.debug("Error in parsing ctp message: protocol version not found"); ret = -1; goto finally; } setProtocolVersion(*p); // command or status IncP(1); if (p == NULL) { LOG.debug("Error in parsing ctp message: command or status not found"); ret = -1; goto finally; } setGenericCommand(*p); // now could be or not params while (IncP(1)) { // param-code CTPParam param; param.setParamCode(*p); IncP(1); //value-length if (p == NULL) { LOG.debug("Error in parsing ctp message: Param-value-length not found"); ret = -1; goto finally; } int valLen = (int)((unsigned char)(*p)); // Safe check on value-length: if (p+valLen-1 >= end) { LOG.debug("Warning! value length too big (%d), using: %d", valLen, end-p); valLen = end-p; } IncP(1); param.setValue((const void*)p, valLen); IncP(valLen - 1); params.add(param); // The max params for the status sent by the server are only 2. if (params.size() == 1) { if (ST_SYNC == getGenericCommand()) { // the server is sending the <san> LOG.debug("SAN param found"); np = new SyncNotification(); np->parse((const char*)param.getValue(), valLen); } else if (ST_JUMP == getGenericCommand()) { LOG.debug("FROM param found"); from = new char[valLen]; memcpy(from, param.getValue(), valLen); setFromLength(valLen); } else { LOG.debug("param found"); buffer = new char[valLen]; memcpy(buffer, param.getValue(), valLen); setBufferLength(valLen); } } else if (params.size() == 2) { if (ST_JUMP == getGenericCommand()) { LOG.debug("TO param found"); buffer = new char[valLen]; memcpy(buffer, param.getValue(), valLen); setBufferLength(valLen); } } if (!p) goto finally; } finally: return ret; }
void getCommand(client *c) { getGenericCommand(c); }