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 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. */
| 146 | * space (for instance when the INCR command is used), so we want LFU/LRU |
| 147 | * values specific for each key. */ |
| 148 | robj *createStringObjectFromLongLongWithOptions(long long value, int valueobj) { |
| 149 | robj *o; |
| 150 | |
| 151 | if (server.maxmemory == 0 || |
| 152 | !(server.maxmemory_policy & MAXMEMORY_FLAG_NO_SHARED_INTEGERS)) |
| 153 | { |
| 154 | /* If the maxmemory policy permits, we can still return shared integers |
| 155 | * even if valueobj is true. */ |
| 156 | valueobj = 0; |
| 157 | } |
| 158 | |
| 159 | if (value >= 0 && value < OBJ_SHARED_INTEGERS && valueobj == 0) { |
| 160 | incrRefCount(shared.integers[value]); |
| 161 | o = shared.integers[value]; |
| 162 | } else { |
| 163 | if (value >= LONG_MIN && value <= LONG_MAX) { |
| 164 | o = createObject(OBJ_STRING, NULL); |
| 165 | o->encoding = OBJ_ENCODING_INT; |
| 166 | o->ptr = (void*)((long)value); |
| 167 | } else { |
| 168 | o = createObject(OBJ_STRING,sdsfromlonglong(value)); |
| 169 | } |
| 170 | } |
| 171 | return o; |
| 172 | } |
| 173 | |
| 174 | /* Wrapper for createStringObjectFromLongLongWithOptions() always demanding |
| 175 | * to create a shared object if possible. */ |
no test coverage detected