Prepare the key associated string value for DMA access, and returns * a pointer and size (by reference), that the user can use to read or * modify the string in-place accessing it directly via pointer. * * The 'mode' is composed by bitwise OR-ing the following flags: * * REDISMODULE_READ -- Read access * REDISMODULE_WRITE -- Write access * * If the DMA is not requested for writing
| 2487 | * the string, and later call StringDMA() again to get the pointer. |
| 2488 | */ |
| 2489 | char *RM_StringDMA(RedisModuleKey *key, size_t *len, int mode) { |
| 2490 | /* We need to return *some* pointer for empty keys, we just return |
| 2491 | * a string literal pointer, that is the advantage to be mapped into |
| 2492 | * a read only memory page, so the module will segfault if a write |
| 2493 | * attempt is performed. */ |
| 2494 | char *emptystring = "<dma-empty-string>"; |
| 2495 | if (key->value == NULL) { |
| 2496 | *len = 0; |
| 2497 | return emptystring; |
| 2498 | } |
| 2499 | |
| 2500 | if (key->value->type != OBJ_STRING) return NULL; |
| 2501 | |
| 2502 | /* For write access, and even for read access if the object is encoded, |
| 2503 | * we unshare the string (that has the side effect of decoding it). */ |
| 2504 | if ((mode & REDISMODULE_WRITE) || key->value->encoding != OBJ_ENCODING_RAW) |
| 2505 | key->value = dbUnshareStringValue(key->db, key->key, key->value); |
| 2506 | |
| 2507 | *len = sdslen(key->value->ptr); |
| 2508 | return key->value->ptr; |
| 2509 | } |
| 2510 | |
| 2511 | /* If the string is open for writing and is of string type, resize it, padding |
| 2512 | * with zero bytes if the new length is greater than the old one. |
nothing calls this directly
no test coverage detected