// XX 对应的getset实现吗? void setCommand(redisClient *c) { int j; robj *expire = NULL; int unit = UNIT_SECONDS; int flags = REDIS_SET_NO_FLAGS; for (j = 3; j < c->argc; j++) { char *a = c->argv[j]->ptr; robj *next = (j == c->argc-1) ? NULL : c->argv[j+1]; if ((a[0] == 'n' || a[0] == 'N') && (a[1] == 'x' || a[1] == 'X') && a[2] == '\0') { flags |= REDIS_SET_NX; } else if ((a[0] == 'x' || a[0] == 'X') && (a[1] == 'x' || a[1] == 'X') && a[2] == '\0') { flags |= REDIS_SET_XX; } else if ((a[0] == 'e' || a[0] == 'E') && (a[1] == 'x' || a[1] == 'X') && a[2] == '\0' && next) { unit = UNIT_SECONDS; expire = next; j++; } else if ((a[0] == 'p' || a[0] == 'P') && (a[1] == 'x' || a[1] == 'X') && a[2] == '\0' && next) { unit = UNIT_MILLISECONDS; expire = next; j++; } else { addReply(c,shared.syntaxerr); return; } } c->argv[2] = tryObjectEncoding(c->argv[2]); setGenericCommand(c,flags,c->argv[1],c->argv[2],expire,unit,NULL,NULL); }
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; }
void psetexCommand(redisClient *c) { c->argv[3] = tryObjectEncoding(c->argv[3]); setGenericCommand(c,REDIS_SET_NO_FLAGS,c->argv[1],c->argv[3],c->argv[2],UNIT_MILLISECONDS,NULL,NULL); }
void setnxCommand(redisClient *c) { c->argv[2] = tryObjectEncoding(c->argv[2]); setGenericCommand(c,REDIS_SET_NX,c->argv[1],c->argv[2],NULL,0,shared.cone,shared.czero); }
void setexCommand(redisClient *c) { c->argv[3] = tryObjectEncoding(c->argv[3]); setGenericCommand(c,0,c->argv[1],c->argv[3],c->argv[2]); }
void setnxCommand(redisClient *c) { c->argv[2] = tryObjectEncoding(c->argv[2]); setGenericCommand(c,1,c->argv[1],c->argv[2],NULL); }
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 setexCommand(client *c) { c->argv[3] = tryObjectEncoding(c->argv[3]); setGenericCommand(c,OBJ_SET_NO_FLAGS,c->argv[1],c->argv[3],c->argv[2],UNIT_SECONDS,NULL,NULL); }
void setexCommand(redisClient *c) { setGenericCommand(c,0,c->argv[1],c->argv[3],c->argv[2]); }
void setnxCommand(redisClient *c) { setGenericCommand(c,1,c->argv[1],c->argv[2],NULL); }