Today, we will be learning about Redis' second data structure, which is the `list`. #thread 🧵
If you haven't read the first thread, check it out
`List`: are like an array but we can use the list as a stack that follows Last-In-First-Out(LIFO) principle and a queue that follows First-In-First-Out (FIFO) principle
In this example, we gonna add users to our beta_list to send invitations in the near future
In the list, we use the push command, and to remove an item, we use the pop command. However, it's important to note that there are different types of push and pop commands available
LPUSH -> pushes the item to the left side/top of the list
LRANGE -> to view items within a range, pass the start and end index values as parameters
LPOP -> removes an item from the left side/top of a list
RPUSH -> push an item to the right side/bottom of the list
RPOP -> remove an item from the right side/bottom of a list
LLEN -> to view the size of the list
LTRIM -> keeps the data from start and end offset index value in the list and deletes others
Bonus:
Combine LPUSH and LPOP the list becomes a stack
Combine RPUSH and LPOP the list becomes a queue
The list can hold 4 billion entries (2^32)
Performance:
LPOP, LPUSH, RPUSH -> O(1)
LRANGE ->O(s+n) n- length of list and s is the start offset
Thanks for reading this thread! If you're interested in learning more about Redis, follow me @_rshiva
& don't forget to retweet the 1st thread to help other devs.
I'm passionate about #buildinginpublic,
web development, &
sharing my learnings with others.
Stay tuned for more
Share this Scrolly Tale with your friends.
A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.