Get the App
SLTechnology News&Howtos  ›  Database  › 

List type and operation of Redis

Shulou Source: shulou.com Published: 2022-06-01 06:43:49 09月10日 Update

Lpush: add a string element to the header of the list corresponding to key.

127.0.0.1 purl 6379 > lpush mylist world

(integer) 1

127.0.0.1 purl 6379 > lpush mylist hello

(integer) 2

127.0.0.1 lrange mylist 6379 > 0-1

1) "hello"

2) "world"

Rpush: add a string element to the end of the list corresponding to key.

127.0.0.1 purl 6379 > rpush mylist2 world

(integer) 1

127.0.0.1 purl 6379 > rpush mylist2 hello

(integer) 2

127.0.0.1 lrange mylist2 6379 > 0-1

1) "world"

2) "hello"

Linsert: add a string before or after the specific position of the list corresponding to the key.

127.0.0.1 purl 6379 > rpush mylist3 world

(integer) 1

127.0.0.1 purl 6379 > linsert mylist3 before world hello

(integer) 2

127.0.0.1 lrange mylist3 6379 > 0-1

1) "hello"

2) "world"

Lset: sets the element value of the specified subscript in the list.

127.0.0.1 purl 6379 > rpush mylist4 hello

(integer) 1

127.0.0.1 lrange mylist4 6379 > 0-1

1) "hello"

127.0.0.1 6379 > lset mylist4 0 world

OK

127.0.0.1 lrange mylist4 6379 > 0-1

1) "world"

Lrem: delete n elements that are the same as value from the corresponding list of key. (n rpush mylist5 hello

(integer) 1

127.0.0.1 purl 6379 > rpush mylist5 hello

(integer) 2

127.0.0.1 purl 6379 > rpush mylist5 hello

(integer) 3

127.0.0.1 lrange mylist5 6379 > 0-1

1) "hello"

2) "hello"

3) "hello"

127.0.0.1 6379 > lrem mylist5 1 hello

(integer) 1

127.0.0.1 lrange mylist5 6379 > 0-1

1) "hello"

2) "hello"

127.0.0.1 6379 > lrem mylist5 2 hello

(integer) 2

127.0.0.1 lrange mylist5 6379 > 0-1

(empty list or set)

Ltrim: retains data within the value range of the specified key.

127.0.0.1 purl 6379 > rpush mylist6 one

(integer) 1

127.0.0.1 purl 6379 > rpush mylist6 two

(integer) 2

127.0.0.1 purl 6379 > rpush mylist6 three

(integer) 3

127.0.0.1 lrange mylist6 6379 > 0-1

1) "one"

2) "two"

3) "three"

127.0.0.1 ltrim mylist6 6379 > 1-1

OK

127.0.0.1 lrange mylist6 6379 > 0-1

1) "two"

2) "three"

Lpop: deletes the element from the header of the list and returns the deleted element.

127.0.0.1 lrange mylist6 6379 > 0-1

1) "two"

2) "three"

127.0.0.1 purl 6379 > lpop mylist6

"two"

127.0.0.1 lrange mylist6 6379 > 0-1

1) "three"

Rpop: removes the element from the tail of the list and returns the deleted element.

127.0.0.1 purl 6379 > lpush mylist6 tow

(integer) 2

127.0.0.1 lrange mylist6 6379 > 0-1

1) "tow"

2) "three"

127.0.0.1 purl 6379 > rpop mylist6

"three"

127.0.0.1 lrange mylist6 6379 > 0-1

1) "tow"

Rpoplpush: removes the element from the tail of the first list and adds it to the header of the second list.

127.0.0.1 lrange mylist6 6379 > 0-1

1) "tow"

127.0.0.1 lrange mylist5 6379 > 0-1

1) "two"

127.0.0.1 lrange mylist6 6379 > 0-1

1) "tow"

127.0.0.1 purl 6379 > rpoplpush mylist5 mylist6

"two"

127.0.0.1 lrange mylist5 6379 > 0-1

(empty list or set)

127.0.0.1 lrange mylist6 6379 > 0-1

1) "two"

2) "tow"

Lindex: returns the element of index location in the list with the name key.

127.0.0.1 lrange mylist6 6379 > 0-1

1) "two"

2) "tow"

127.0.0.1 lindex mylist6 6379 > 0

"two"

127.0.0.1 lindex mylist6 6379 > 1

"tow

Tags: Element header character string tail position same subscript middle finger name data range from tail complete type Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Information Microsoft NVidia MySQL