YouTip LogoYouTip

Lists Lrem

Redis Lrem Command | Novice Tutorial

Novice Tutorial -- Learning Not Just Technology, But Dreams!

Redis Tutorial Redis TutorialRedis IntroductionRedis InstallationRedis ConfigurationRedis Data Types

Redis Commands

Redis CommandsRedis KeysRedis StringsRedis HashRedis ListRedis SetRedis Sorted SetRedis HyperLogLogRedis Publish SubscribeRedis TransactionsRedis ScriptingRedis ConnectionRedis ServerRedis GEORedis Stream

Redis Advanced Tutorial

Redis Data Backup and RecoveryRedis SecurityRedis Performance TestingRedis Client ConnectionRedis PipeliningRedis PartitioningJava Using RedisPHP Using Redis Redis Hash Redis Set

Redis Lrem Command

Image 3 Redis List Redis Lrem removes elements from the list that are equal to the parameter VALUE based on the value of the parameter COUNT. The value of COUNT can be the following: * count > 0: Start searching from the head of the list towards the tail, remove COUNT number of elements that are equal to VALUE. * count < 0: Start searching from the tail of the list towards the head, remove COUNT absolute value number of elements that are equal to VALUE. * count = 0: Remove all values in the list that are equal to VALUE.

Syntax

Basic syntax of redis Lrem command is as follows:
redis 127.0.0.1:6379> LREM key count VALUE

Available Versions

>= 1.0.0

Return Value

Number of elements removed. Returns 0 when the list does not exist.

Example

redis> RPUSH mylist "hello"
(integer) 1
redis> RPUSH mylist "hello"
(integer) 2
redis> RPUSH mylist "foo"
(integer) 3
redis> RPUSH mylist "hello"
(integer) 4
redis> LREM mylist -2 "hello"
(integer) 2
redis> LRANGE mylist 0 -1
1) "hello"
2) "foo"
redis> 
Image 4 Redis List
← Lists LsetLists Lrange β†’