Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7865575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:07:51+00:00 2026-06-03T00:07:51+00:00

I am using redis to store an ordered set of items. Here is a

  • 0

I am using redis to store an ordered set of items. Here is a sample code:

object Producer{
  def main(args:Array[String]){
    val jedis = new Jedis("localhost")
    for (i<-1 to 10){
      println("publishing:"+(i))
      jedis.lpush("q1",i.toString)
    }
  }
}
object Consumer {
  def main(args:Array[String]){
    val jedis = new Jedis("localhost")
    while(true){
      while(jedis.llen("q1")>0){
        val msg=jedis.lpop("q1")
        println("processing:"+msg)
      }
    }

  }
}

When I run the producer, I get

publishing:1
publishing:2
publishing:3
publishing:4
publishing:5
publishing:6
publishing:7
publishing:8
publishing:9
publishing:10

while when I run consumer, I get

processing:1
processing:2
processing:4
processing:5
processing:6
processing:7
processing:9
processing:10
processing:8
processing:3

Why order of items are not correct, this is not really FIFO.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:07:52+00:00Added an answer on June 3, 2026 at 12:07 am

    This is not really FIFO because the code is wrong.

    If you use lpush to queue item, you should use rpop rather than lpop to dequeue them in FIFO order.

    redis 127.0.0.1:6379> lpush x 10
    (integer) 1
    redis 127.0.0.1:6379> lpush x 20
    (integer) 2
    redis 127.0.0.1:6379> lpush x 30
    (integer) 3
    redis 127.0.0.1:6379> lpop x
    "30"
    redis 127.0.0.1:6379> lpop x
    "20"
    redis 127.0.0.1:6379> lpop x
    "10"
    

    Normally you should retrieve the items in reverse order (LIFO). But your two agents probably run concurrently, so the order you get with lpop is not deterministic.

    Please note your dequeuing agent is poorly implemented since it takes 100% of the CPU (there is no wait state) and will saturate Redis with llen commands when the queue is empty. Consider using a blocking call such as brpop instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently using Socket.IO with redis store. And I'm using Room feature with it.
Currently I'm using https://github.com/mranney/node_redis as my node redis client. client.retry_delay is set to 250ms
I am using Redis to store two databases : 0 and 1 via the
If using Redis , we can use one record (sets and ordered sets) to
I'm trying to create a simple event store using C# and [ServiceStack] Redis. public
I'm using redis to store hashes with ~100k records per hash. I want to
I'm not understanding how to make a persistent store in Redis. Using the options
I am using Connect on node.js with connect-redis as session store. Is there a
I'm matching a bunch of strings using REDIS.hmget . The full store has about
Must be missing something here, but I'm using Node_redis as Node.js client for Redis.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.