List Data Type in Redis
Redis Lists are similar to linked list of String values. Redis Lists can be used to implement stack and queue data structure.
Basic Command Used in List Data Structure in Redis:
- LPUSH – This command adds a new element to the head of the list.
- RPUSH – This command adds a new element to the tail of the list.
- LPOP – This command removes and return an element from the head of the list.
- RPOP – This command removes and return an element from the tail of the list.
- LLEN – This command returns the length of the list.
- LMOVE – This command automatically moves elements from one list to other list.
- LTRIM – This command will reduces a list to the specified range of elements.
Example:
LPUSH name: GFG city: Noida
LPUSH name: GFG articles : 500
RPOP name: GFG
(// command 1)
Output:
city: Noida
// command 2
RPOP name: GFG
Output:
articles : 500
Note: The max length of a Redis list is 2^32 – 1 (4,294,967,295) elements.
How Redis Stores List Data Types?
- Lists in Redis are implemented as a doubly-linked list of values.
- Each list has a unique key, and elements are stored in the order they were added.
- Lists are commonly used for implementing queues, message brokers, and more.
Complete Guide on Redis Data Types with Commands and Storage
Redis is an open-source, in-memory data store that supports various data types: such as String, Sets, Lists, Hashes, etc. to store data according to the needs of the user. These diverse data types make Redis versatile for caching, messaging, real-time analytics, and more.
Different Data Types in Redis
- 1. String Data Type in Redis
- 2. Hash Data type in Redis
- 3. List Data Type in Redis
- 4. Set Data type in Redis:
- 5. Sorted Set in Redis:
- 6. Streams in Redis:
- 7. HyperLogLog in Redis:
- 8. Bitmaps in Redis:
- 9. Bitfields in Redis
- 10. Probabilistic in Redis:
- 11. Geospatial Indexes in Redis:
- 12. Time-Series in Redis
Contact Us