Big Data & Tools with NoSQL
  • Big Data & Tools
  • ReadMe
  • Big Data Overview
    • Overview
    • Job Opportunities
    • What is Data?
    • How does it help?
    • Types of Data
    • The Big 4 V's
      • Variety
      • Volume
      • Velocity
      • Veracity
      • Other V's
    • Trending Technologies
    • Big Data Concerns
    • Big Data Challenges
    • Data Integration
    • Scaling
      • CAP Theorem
      • Optimistic concurrency
      • Eventual consistency
      • Concurrent vs. Parallel Programming
    • Big Data Tools
    • No SQL Databases
    • What does Big Data learning means?
  • Linux & Tools
    • Overview
    • Linux Commands - 01
    • Linux Commands - 02
    • AWK
    • CSVKIT
    • CSVSQL
    • CSVGREP
  • Data Format
    • Storage Formats
    • CSV/TSV/Parquet
    • Parquet Example
    • JSON
    • HTTP & REST API
      • Terms to Know
        • Statefulness
        • Statelessness
        • Monolithic Architecture
        • Microservices
        • Idempotency
    • REST API
    • Python
      • Setup
      • Decorator
      • Unit Testing
      • Flask Demo
      • Flask Demo - 01
      • Flask Demo - 02
      • Flask Demo - 03
      • Flask Demo - 04
      • Flask Demo - 06
    • API Testing
    • Flask Demo Testing
    • API Performance
    • API in Big Data World
  • NoSQL
    • Types of NoSQL Databases
    • Redis
      • Overview
      • Terms to know
      • Redis - (RDBMS) MySql
      • Redis Cache Demo
      • Use Cases
      • Data Structures
        • Strings
        • List
        • Set
        • Hash
        • Geospatial Index
        • Pub/Sub
        • Redis - Python
      • Redis JSON
      • Redis Search
      • Persistence
      • Databases
      • Timeseries
    • Neo4J
      • Introduction
      • Neo4J Terms
      • Software
      • Neo4J Components
      • Hello World
      • Examples
        • MySQL: Neo4J
        • Sample Transactions
        • Sample
        • Create Nodes
        • Update Nodes
        • Relation
        • Putting it all together
        • Commonly used Functions
        • Data Profiling
        • Queries
        • Python Scripts
      • More reading
    • MongoDB
      • Sample JSON
      • Introduction
      • Software
      • MongoDB Best Practices
      • MongoDB Commands
      • Insert Document
      • Querying MongoDB
      • Update & Remove
      • Import
      • Logical Operators
      • Data Types
      • Operators
      • Aggregation Pipeline
      • Further Reading
      • Fun Task
        • Sample
    • InfluxDB
      • Data Format
      • Scripts
  • Python
    • Python Classes
    • Serialization-Deserialization
  • Tools
    • JQ
    • DUCK DB
    • CICD Intro
    • CICD Tools
      • CI YAML
      • CD Yaml
    • Containers
      • VMs or Containers
      • What container does
      • Podman
      • Podman Examples
  • Cloud Everywhere
    • Overview
    • Types of Cloud Services
    • Challenges of Cloud Computing
    • High Availability
    • Azure Cloud
      • Services
      • Storages
      • Demo
    • Terraform
  • Data Engineering
    • Batch vs Streaming
    • Kafka
      • Introduction
      • Kafka Use Cases
      • Kafka Software
      • Python Scripts
      • Different types of Streaming
    • Quality & Governance
    • Medallion Architecture
    • Data Engineering Model
    • Data Mesh
  • Industry Trends
    • Roadmap - Data Engineer
    • Good Reads
      • IP & SUBNET
Powered by GitBook
On this page
  1. NoSQL
  2. Redis
  3. Data Structures

List

PreviousStringsNextSet

Last updated 1 year ago

Redis lists are linked lists of string values. Redis lists are frequently used to:

  • Implement stacks and queues.

  • Build queue management for background worker systems.

Image website tracking user experience

LPUSH (add elements to the beginning of a list):

  • Example: LPUSH "recentPages" "/home"

  • LPUSH "recentPages" "/about" "/contact"

  • Use case: Track a user's page visit history. New pages the user visits are added to the front, showing the most recent visit at the top.

The list will look like

contact about home

RPUSH (add elements to the end of a list):

  • Example: RPUSH "pageQueue" "/checkout" "/confirmation" "/thankyou"

  • Use case: Queue pages for batch processing, like sequentially processing user actions.

LRANGE (get a range of elements from a list):

  • Example: LRANGE "recentPages" 0 -1

  • Use case: Display the pages a user has recently visited on their profile or dashboard.

LLEN (get the length of a list):

  • Example: LLEN "recentPages"

  • Use case: Show the number of pages users have visited in their current session or a set period.

LPOP (remove and get the first element in a list):

  • Example: LPOP "recentPages"

  • Use case: Remove the oldest page in the user's visit history when the list exceeds a certain size to maintain only a fixed number of recent pages.

RPOP (remove and get the last element in a list):

  • Example: RPOP "pageQueue"

  • Use case: Process the last action in a user's action queue, like the previous step in a multi-step form.

How do we track which User accessed which page?

Remember Namespaces?

  • LPUSH "user:123:recentPages" "/home"

  • LPUSH "user:123:recentPages" "/contact"

  • LRANGE "user:123:recentPages" 0 -1

Use Case: Managing Queues of Work

FIFO: First In, First Out

LIFO: Last In, First Out

Create a Task Queue

RPUSH taskQueue "task1" "task2" "task3"
LRANGE taskQueue 0 -1

Worker Fetching a Task (FIFO):

LPOP taskQueue
LRANGE taskQueue 0 -1

Creating a Stack or LIFO Queue:

LPUSH jobStack "task1" "task2" "task3"
LPOP jobStack

adds a new element to the head of a list; adds to the tail.

removes and returns an element from the head of a list; does the same but from the tails of a list.

Returns the length of a list.

Atomically moves elements from one list to another.

Reduces a list to the specified range of elements.

LPUSH
RPUSH
LPOP
RPOP
LLEN
LMOVE
LTRIM
src:
https://linuxhint.com/redis-lpop/