`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
• • •
Missing some Tweet in this thread? You can try to
force a refresh
Redis Series Part 4 thread is here!
Today, we're diving into Redis `Hashes`, simple explanations, and real-world example #redis#series#thread 🧵
If you haven't read the previous thread about the list, check it out
Hash is essentially a collection of field-value pairs, where each field is a unique identifier and each value is the associated data. Just like JSON object or python dictionary. Everything inside the hash is a string.
In this example, we gonna store the user preferences when they want to receive threadletters in nooli.in
HSET: command adds one or more fields-values to key
HSET <KEY> field1 value1 field2 value2
Redis Part 3 is here! Today, we'll be exploring the power of Redis 'Sets'. #redis#thread 🧵
If you haven't read the previous thread about the list, check it out
Redis Sets are a unique way to store your data! They allow for an unordered collection of strings with no duplicates. Perfect for managing sets of items without worrying about repetition
Let's dive in with an example, Say we want to give one lucky user a year of free membership to Nooli. With Redis Sets, users can enroll in the giveaway but only once, preventing duplicates. Easy and efficient!
Excited to teach Redis core concepts in the next few days! 🧵 #Redis#thread 👇
Redis: Open-source, highly-replicated, performant, non-relational, database & caching server. Maps keys to values with the predefined data model. Data stored in-memory data store, It is good for caching, message brokers & streaming engines
Let's start with the string data structure
String: Store and retrieve a string, serialized json, numerical values, and binary data
Syntax:
SET <KEY> <VALUE>
GET <KEY>
MSET & MGET to assign and retreive multiple key valye in single command
Super charged Plain Old Ruby Object(PORO) with Active Model.
Simple Car class which does not inherit from the active record. Cannot create a new object by with a hash of attributes
ActiveModel::Attributes You can assign a hash of attributes to the new method, initialize method takes an
arguments then call the assign_attributes on our car object with that hash