Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/aof.c
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ int rewriteAppendOnlyFileRio(rio *aof) {
expiretime = getExpire(db,&key);

/* Save the key and associated value */
if (o->type == OBJ_STRING) {
if (o->type == OBJ_STRING || o->type == OBJ_STRING_PMEM) {
/* Emit a SET command */
char cmd[]="*3\r\n$3\r\nSET\r\n";
if (rioWrite(aof,cmd,sizeof(cmd)-1) == 0) goto werr;
Expand Down
14 changes: 7 additions & 7 deletions src/bitops.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ robj *lookupStringForBitCommand(client *c, size_t maxbit) {
o = createObject(OBJ_STRING,sdsnewlen(NULL, byte+1));
dbAdd(c->db,c->argv[1],o);
} else {
if (checkType(c,o,OBJ_STRING)) return NULL;
if (checkTypeStringvariant(c,o)) return NULL;
o = dbUnshareStringValue(c->db,c->argv[1],o);
o->ptr = sdsgrowzero(o->ptr,byte+1);
}
Expand All @@ -504,7 +504,7 @@ robj *lookupStringForBitCommand(client *c, size_t maxbit) {
* If the source object is NULL the function is guaranteed to return NULL
* and set 'len' to 0. */
unsigned char *getObjectReadOnlyString(robj *o, long *len, char *llbuf) {
serverAssert(o->type == OBJ_STRING);
serverAssert(o->type == OBJ_STRING || o->type == OBJ_STRING_PMEM);
unsigned char *p = NULL;

/* Set the 'p' pointer to the string, that can be just a stack allocated
Expand Down Expand Up @@ -572,7 +572,7 @@ void getbitCommand(client *c) {
return;

if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.czero)) == NULL ||
checkType(c,o,OBJ_STRING)) return;
checkTypeStringvariant(c,o)) return;

byte = bitoffset >> 3;
bit = 7 - (bitoffset & 0x7);
Expand Down Expand Up @@ -635,7 +635,7 @@ void bitopCommand(client *c) {
continue;
}
/* Return an error if one of the keys is not a string. */
if (checkType(c,o,OBJ_STRING)) {
if (checkTypeStringvariant(c,o)) {
unsigned long i;
for (i = 0; i < j; i++) {
if (objects[i])
Expand Down Expand Up @@ -774,7 +774,7 @@ void bitcountCommand(client *c) {

/* Lookup, check for type, and return 0 for non existing keys. */
if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.czero)) == NULL ||
checkType(c,o,OBJ_STRING)) return;
checkTypeStringvariant(c,o)) return;
p = getObjectReadOnlyString(o,&strlen,llbuf);

/* Parse start/end range if any. */
Expand Down Expand Up @@ -838,7 +838,7 @@ void bitposCommand(client *c) {
addReplyLongLong(c, bit ? -1 : 0);
return;
}
if (checkType(c,o,OBJ_STRING)) return;
if (checkTypeStringvariant(c,o)) return;
p = getObjectReadOnlyString(o,&strlen,llbuf);

/* Parse start/end range if any. */
Expand Down Expand Up @@ -1000,7 +1000,7 @@ void bitfieldGeneric(client *c, int flags) {
/* Lookup for read is ok if key doesn't exit, but errors
* if it's not a string. */
o = lookupKeyRead(c->db,c->argv[1]);
if (o != NULL && checkType(c,o,OBJ_STRING)) {
if (o != NULL && checkTypeStringvariant(c,o)) {
zfree(ops);
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ int dbDelete(redisDb *db, robj *key) {
* using an sdscat() call to append some data, or anything else.
*/
robj *dbUnshareStringValue(redisDb *db, robj *key, robj *o) {
serverAssert(o->type == OBJ_STRING);
serverAssert(o->type == OBJ_STRING || o->type == OBJ_STRING_PMEM);
if (o->refcount != 1 || o->encoding != OBJ_ENCODING_RAW) {
robj *decoded = getDecodedObject(o);
o = createRawStringObject(decoded->ptr, sdslen(decoded->ptr));
Expand Down Expand Up @@ -926,6 +926,7 @@ char* getObjectTypeName(robj *o) {
} else {
switch(o->type) {
case OBJ_STRING: type = "string"; break;
case OBJ_STRING_PMEM: type = "string"; break;
case OBJ_LIST: type = "list"; break;
case OBJ_SET: type = "set"; break;
case OBJ_ZSET: type = "zset"; break;
Expand Down
8 changes: 4 additions & 4 deletions src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void xorObjectDigest(redisDb *db, robj *keyobj, unsigned char *digest, robj *o)
char buf[128];

/* Save the key and associated value */
if (o->type == OBJ_STRING) {
if (o->type == OBJ_STRING || o->type == OBJ_STRING_PMEM) {
mixStringObjectDigest(digest,o);
} else if (o->type == OBJ_LIST) {
listTypeIterator *li = listTypeInitIterator(o,0,LIST_TAIL);
Expand Down Expand Up @@ -553,7 +553,7 @@ NULL
val = dictGetVal(de);
key = dictGetKey(de);

if (val->type != OBJ_STRING || !sdsEncodedObject(val)) {
if ((val->type != OBJ_STRING && val->type != OBJ_STRING_PMEM) || !sdsEncodedObject(val)) {
addReplyError(c,"Not an sds encoded string.");
} else {
addReplyStatusFormat(c,
Expand Down Expand Up @@ -833,7 +833,7 @@ void _serverAssertPrintClientInfo(const client *c) {
char buf[128];
char *arg;

if (c->argv[j]->type == OBJ_STRING && sdsEncodedObject(c->argv[j])) {
if ((c->argv[j]->type == OBJ_STRING || c->argv[j]->type == OBJ_STRING_PMEM) && sdsEncodedObject(c->argv[j])) {
arg = (char*) c->argv[j]->ptr;
} else {
snprintf(buf,sizeof(buf),"Object type: %u, encoding: %u",
Expand All @@ -849,7 +849,7 @@ void serverLogObjectDebugInfo(const robj *o) {
serverLog(LL_WARNING,"Object type: %d", o->type);
serverLog(LL_WARNING,"Object encoding: %d", o->encoding);
serverLog(LL_WARNING,"Object refcount: %d", o->refcount);
if (o->type == OBJ_STRING && sdsEncodedObject(o)) {
if ((o->type == OBJ_STRING || o->type == OBJ_STRING_PMEM) && sdsEncodedObject(o)) {
serverLog(LL_WARNING,"Object raw string len: %zu", sdslen(o->ptr));
if (sdslen(o->ptr) < 4096) {
sds repr = sdscatrepr(sdsempty(),o->ptr,sdslen(o->ptr));
Expand Down
6 changes: 3 additions & 3 deletions src/defrag.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ robj *activeDefragStringOb(robj* ob, long *defragged) {
return NULL;

/* try to defrag robj (only if not an EMBSTR type (handled below). */
if (ob->type!=OBJ_STRING || ob->encoding!=OBJ_ENCODING_EMBSTR) {
if ((ob->type!=OBJ_STRING && ob->type!=OBJ_STRING_PMEM) || ob->encoding!=OBJ_ENCODING_EMBSTR) {
if ((ret = activeDefragAlloc(ob))) {
ob = ret;
(*defragged)++;
}
}

/* try to defrag string object */
if (ob->type == OBJ_STRING) {
if ((ob->type == OBJ_STRING) || (ob->type == OBJ_STRING_PMEM)) {
if(ob->encoding==OBJ_ENCODING_RAW) {
sds newsds = activeDefragSds((sds)ob->ptr);
if (newsds) {
Expand Down Expand Up @@ -833,7 +833,7 @@ long defragKey(redisDb *db, dictEntry *de) {
ob = newob;
}

if (ob->type == OBJ_STRING) {
if ((ob->type == OBJ_STRING) || (ob->type == OBJ_STRING_PMEM)) {
/* Already handled in activeDefragStringOb. */
} else if (ob->type == OBJ_LIST) {
if (ob->encoding == OBJ_ENCODING_QUICKLIST) {
Expand Down
2 changes: 1 addition & 1 deletion src/gopher.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void processGopherRequest(client *c) {
robj *o = lookupKeyRead(c->db,keyname);

/* If there is no such key, return with a Gopher error. */
if (o == NULL || o->type != OBJ_STRING) {
if (o == NULL || (o->type != OBJ_STRING && o->type != OBJ_STRING_PMEM)) {
char *errstr;
if (o == NULL)
errstr = "Error: no content at the specified key";
Expand Down
2 changes: 1 addition & 1 deletion src/hyperloglog.c
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ int isHLLObjectOrReply(client *c, robj *o) {
struct hllhdr *hdr;

/* Key exists, check type */
if (checkType(c,o,OBJ_STRING))
if (checkTypeStringvariant(c,o))
return C_ERR; /* Error already sent. */

if (!sdsEncodedObject(o)) goto invalid;
Expand Down
6 changes: 4 additions & 2 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -2038,6 +2038,7 @@ int RM_KeyType(RedisModuleKey *key) {
* defines as desired. */
switch(key->value->type) {
case OBJ_STRING: return REDISMODULE_KEYTYPE_STRING;
case OBJ_STRING_PMEM: return REDISMODULE_KEYTYPE_STRING;
case OBJ_LIST: return REDISMODULE_KEYTYPE_LIST;
case OBJ_SET: return REDISMODULE_KEYTYPE_SET;
case OBJ_ZSET: return REDISMODULE_KEYTYPE_ZSET;
Expand All @@ -2057,6 +2058,7 @@ size_t RM_ValueLength(RedisModuleKey *key) {
if (key == NULL || key->value == NULL) return 0;
switch(key->value->type) {
case OBJ_STRING: return stringObjectLen(key->value);
case OBJ_STRING_PMEM: return stringObjectLen(key->value);
case OBJ_LIST: return listTypeLength(key->value);
case OBJ_SET: return setTypeSize(key->value);
case OBJ_ZSET: return zsetLength(key->value);
Expand Down Expand Up @@ -2202,7 +2204,7 @@ char *RM_StringDMA(RedisModuleKey *key, size_t *len, int mode) {
return emptystring;
}

if (key->value->type != OBJ_STRING) return NULL;
if (key->value->type != OBJ_STRING && key->value->type != OBJ_STRING_PMEM) return NULL;

/* For write access, and even for read access if the object is encoded,
* we unshare the string (that has the side effect of decoding it). */
Expand All @@ -2227,7 +2229,7 @@ char *RM_StringDMA(RedisModuleKey *key, size_t *len, int mode) {
* unless the new length value requested is zero. */
int RM_StringTruncate(RedisModuleKey *key, size_t newlen) {
if (!(key->mode & REDISMODULE_WRITE)) return REDISMODULE_ERR;
if (key->value && key->value->type != OBJ_STRING) return REDISMODULE_ERR;
if (key->value && key->value->type != OBJ_STRING && key->value->type != OBJ_STRING_PMEM) return REDISMODULE_ERR;
if (newlen > 512*1024*1024) return REDISMODULE_ERR;

/* Empty key and new len set to 0. Just return REDISMODULE_OK without
Expand Down
4 changes: 2 additions & 2 deletions src/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ size_t sdsZmallocSize(sds s) {
/* Return the amount of memory used by the sds string at object->ptr
* for a string object. */
size_t getStringObjectSdsUsedMemory(robj *o) {
serverAssertWithInfo(NULL,o,o->type == OBJ_STRING);
serverAssertWithInfo(NULL,o,o->type == OBJ_STRING || o->type == OBJ_STRING_PMEM);
switch(o->encoding) {
case OBJ_ENCODING_RAW: return sdsZmallocSize(o->ptr);
case OBJ_ENCODING_EMBSTR: return zmalloc_size(o)-sizeof(robj);
Expand Down Expand Up @@ -1718,7 +1718,7 @@ int processMultibulkBuffer(client *c) {
sdsclear(c->querybuf);
} else {
c->argv[c->argc++] =
createStringObject(c->querybuf+c->qb_pos,c->bulklen);
createStringObjectOptim(c->querybuf+c->qb_pos,c->bulklen);
c->qb_pos += c->bulklen+2;
}
c->bulklen = -1;
Expand Down
Loading