LPOP
Remove and return the first element (left side) of the list. If the list is empty or the key does not exist, return nil.
Redis Native Command Syntax
Section titled “Redis Native Command Syntax”LPOP keyParameter Description
- key: The key of the list
Detailed Explanation
Section titled “Detailed Explanation”The LPOP command is one of the list operation commands. It removes and returns the first element of the list. If the list is empty or the key does not exist, it returns nil.
Redisun Usage
Section titled “Redisun Usage”In redisun, the LPOP command is implemented through the LPopCommand class and the lpop method in the Redisun class.
Basic Usage
Section titled “Basic Usage”Redisun redisun = Redisun.create(options -> { options.setAddress("redis://127.0.0.1:6379");});
// Remove and get element from the head of the listString result = redisun.lpop("mylist");if (result != null) { System.out.println("Popped element: " + result);} else { System.out.println("List is empty or key does not exist");}
// Asynchronous versionCompletableFuture<String> future = redisun.asyncLpop("mylist");future.thenAccept(element -> { if (element != null) { System.out.println("Async popped element: " + element); } else { System.out.println("List is empty or key does not exist"); }});- If the list is empty or the key does not exist, return null
- If the key exists but is not of list type, an exception will be thrown
- The operation is atomic
- In the blocking version of the BLPOP command, it will block and wait when the list is empty, but LPOP will not block