UPDATE 06-11-2021
There Different ways to Remove all element from the List :
Step 1:
Using General DEL Command for delete any key into Redis like Anurag's solution
DEL list
Step 2:
Using LTRIM Command and Applying The next conditional from Documentation
if start is larger than the end of the list, or start > end, the
result will be an empty list (which causes key to be removed).
SO any of next Commands will works or Mohd Abdul Mujib's solution
LTRIM list 999 0
LTRIM list 1 0
LTRIM list 4 1
But Take care about using negative numbers as The start index, as From Documentation
start and end can also be negative numbers indicating offsets from the
end of the list, where -1 is the last element of the list, -2 the
penultimate element and so on.
Next Command Will Remove all elements under list IF list include more than one elements BUT IF list include only one element will Not Remove any thing
LTRIM list -1 0
Explain
First Case (list include more than one elements)
the index -1
as the start will translate to the last element which has 4
index(if list include 4 elements) SO the condition start > end
has been applyed
Second Case (list include one elements)
the index -1
as the start will translate to the last element which has 0
index SO the condition become start == end
Not start > end
Here Example for Above commands:
redis 127.0.0.1:6379> RPUSH mylist four 1 3 1
(integer) 4
redis 127.0.0.1:6379> KEYS *
1) "test4"
2) "firstList"
3) "mylist"
redis 127.0.0.1:6379> LTRIM mylist 999 0
OK
redis 127.0.0.1:6379> KEYS *
1) "test4"
2) "firstList"
redis 127.0.0.1:6379> RPUSH mylist four 1 3 1
(integer) 4
redis 127.0.0.1:6379> KEYS *
1) "test4"
2) "firstList"
3) "mylist"
redis 127.0.0.1:6379> LTRIM mylist -1 0
OK
redis 127.0.0.1:6379> LRANGE mylist 0 -1
(empty list or set)
redis 127.0.0.1:6379> KEYS *
1) "test4"
2) "firstList"
redis 127.0.0.1:6379> RPUSH mylist four
(integer) 1
redis 127.0.0.1:6379> KEYS *
1) "test4"
2) "firstList"
3) "mylist"
redis 127.0.0.1:6379> LTRIM mylist -1 0
OK
redis 127.0.0.1:6379> KEYS *
1) "test4"
2) "firstList"
3) "mylist"
mylist
would make your question clearer. For example, redis.io/commands/ltrim writes:LTRIM mylist 1 -1
. The page you cite is a command reference and should not be considered a "convention" for making good examples. – Egidio