2
我使用Redis的存放有序組項目。下面是一個示例代碼:Redis的隊列順序有誤
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)
}
}
}
}
當我運行的製片人,我得到
publishing:1
publishing:2
publishing:3
publishing:4
publishing:5
publishing:6
publishing:7
publishing:8
publishing:9
publishing:10
而當我跑的消費者,我得到
processing:1
processing:2
processing:4
processing:5
processing:6
processing:7
processing:9
processing:10
processing:8
processing:3
爲什麼項目的順序不正確,這不是真正的先入先出。