mirror of
https://github.com/fluencelabs/redis
synced 2025-03-31 14:51:04 +00:00
Refactor createObjectFromLongLong() to be suitable for value objects.
This commit is contained in:
parent
2076660843
commit
bd92389c2d
34
src/object.c
34
src/object.c
@ -123,9 +123,25 @@ robj *createStringObject(const char *ptr, size_t len) {
|
|||||||
return createRawStringObject(ptr,len);
|
return createRawStringObject(ptr,len);
|
||||||
}
|
}
|
||||||
|
|
||||||
robj *createStringObjectFromLongLong(long long value) {
|
/* Create a string object from a long long value. When possible returns a
|
||||||
|
* shared integer object, or at least an integer encoded one.
|
||||||
|
*
|
||||||
|
* If valueobj is non zero, the function avoids returning a a shared
|
||||||
|
* integer, because the object is going to be used as value in the Redis key
|
||||||
|
* space (for instance when the INCR command is used), so we want LFU/LRU
|
||||||
|
* values specific for each key. */
|
||||||
|
robj *createStringObjectFromLongLongWithOptions(long long value, int valueobj) {
|
||||||
robj *o;
|
robj *o;
|
||||||
if (value >= 0 && value < OBJ_SHARED_INTEGERS) {
|
|
||||||
|
if (server.maxmemory == 0 ||
|
||||||
|
!(server.maxmemory_policy & MAXMEMORY_FLAG_NO_SHARED_INTEGERS))
|
||||||
|
{
|
||||||
|
/* If the maxmemory policy permits, we can still return shared integers
|
||||||
|
* even if valueobj is true. */
|
||||||
|
valueobj = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value >= 0 && value < OBJ_SHARED_INTEGERS && valueobj == 0) {
|
||||||
incrRefCount(shared.integers[value]);
|
incrRefCount(shared.integers[value]);
|
||||||
o = shared.integers[value];
|
o = shared.integers[value];
|
||||||
} else {
|
} else {
|
||||||
@ -140,6 +156,20 @@ robj *createStringObjectFromLongLong(long long value) {
|
|||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Wrapper for createStringObjectFromLongLongWithOptions() always demanding
|
||||||
|
* to create a shared object if possible. */
|
||||||
|
robj *createStringObjectFromLongLong(long long value) {
|
||||||
|
return createStringObjectFromLongLongWithOptions(value,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Wrapper for createStringObjectFromLongLongWithOptions() avoiding a shared
|
||||||
|
* object when LFU/LRU info are needed, that is, when the object is used
|
||||||
|
* as a value in the key space, and Redis is configured to evict based on
|
||||||
|
* LFU/LRU. */
|
||||||
|
robj *createStringObjectFromLongLongForValue(long long value) {
|
||||||
|
return createStringObjectFromLongLongWithOptions(value,1);
|
||||||
|
}
|
||||||
|
|
||||||
/* Create a string object from a long double. If humanfriendly is non-zero
|
/* Create a string object from a long double. If humanfriendly is non-zero
|
||||||
* it does not use exponential format and trims trailing zeroes at the end,
|
* it does not use exponential format and trims trailing zeroes at the end,
|
||||||
* however this results in loss of precision. Otherwise exp format is used
|
* however this results in loss of precision. Otherwise exp format is used
|
||||||
|
@ -1501,6 +1501,7 @@ robj *tryObjectEncoding(robj *o);
|
|||||||
robj *getDecodedObject(robj *o);
|
robj *getDecodedObject(robj *o);
|
||||||
size_t stringObjectLen(robj *o);
|
size_t stringObjectLen(robj *o);
|
||||||
robj *createStringObjectFromLongLong(long long value);
|
robj *createStringObjectFromLongLong(long long value);
|
||||||
|
robj *createStringObjectFromLongLongForValue(long long value);
|
||||||
robj *createStringObjectFromLongDouble(long double value, int humanfriendly);
|
robj *createStringObjectFromLongDouble(long double value, int humanfriendly);
|
||||||
robj *createQuicklistObject(void);
|
robj *createQuicklistObject(void);
|
||||||
robj *createZiplistObject(void);
|
robj *createZiplistObject(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user