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. */
| 172 | * space (for instance when the INCR command is used), so we want LFU/LRU |
| 173 | * values specific for each key. */ |
| 174 | robj *createStringObjectFromLongLongWithOptions(long long value, int valueobj) { |
| 175 | robj *o; |
| 176 | |
| 177 | if (g_pserver->maxmemory == 0 || |
| 178 | !(g_pserver->maxmemory_policy & MAXMEMORY_FLAG_NO_SHARED_INTEGERS)) |
| 179 | { |
| 180 | /* If the maxmemory policy permits, we can still return shared integers |
| 181 | * even if valueobj is true. */ |
| 182 | valueobj = 0; |
| 183 | } |
| 184 | |
| 185 | if (value >= 0 && value < OBJ_SHARED_INTEGERS && valueobj == 0) { |
| 186 | incrRefCount(shared.integers[value]); |
| 187 | o = shared.integers[value]; |
| 188 | } else { |
| 189 | if (value >= LONG_MIN && value <= LONG_MAX) { |
| 190 | o = createObject(OBJ_STRING, NULL); |
| 191 | o->encoding = OBJ_ENCODING_INT; |
| 192 | o->m_ptr = (void*)((long)value); |
| 193 | } else { |
| 194 | o = createObject(OBJ_STRING,sdsfromlonglong(value)); |
| 195 | } |
| 196 | } |
| 197 | return o; |
| 198 | } |
| 199 | |
| 200 | /* Wrapper for createStringObjectFromLongLongWithOptions() always demanding |
| 201 | * to create a shared object if possible. */ |
no test coverage detected