diff options
Diffstat (limited to 'src/t_list.c')
-rw-r--r-- | src/t_list.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/t_list.c b/src/t_list.c index 64e917a41..1d046f403 100644 --- a/src/t_list.c +++ b/src/t_list.c @@ -514,7 +514,12 @@ void lrangeCommand(redisClient *c) { p = ziplistNext(o->ptr,p); } } else if (o->encoding == REDIS_ENCODING_LINKEDLIST) { - listNode *ln = listIndex(o->ptr,start); + listNode *ln; + + /* If we are nearest to the end of the list, reach the element + * starting from tail and going backward, as it is faster. */ + if (start > llen/2) start -= llen; + ln = listIndex(o->ptr,start); while(rangelen--) { addReplyBulk(c,ln->value); |