🔴 Redis
Beginner
What are LPUSH, RPUSH, LPOP, and RPOP in Redis?
Answer
These commands operate on Redis Lists. LPUSH key val inserts one or more values at the head (left) of the list, while RPUSH key val inserts at the tail (right). LPOP key removes and returns the first (leftmost) element; RPOP key removes and returns the last (rightmost) element. By combining these, you implement common data structures: RPUSH + LPOP gives a FIFO queue (enqueue on the right, dequeue from the left). RPUSH + RPOP gives a LIFO stack. LRANGE key 0 -1 retrieves all elements without consuming them. BLPOP/BRPOP are the blocking variants — the client waits until an element is available, useful for job queues.