<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                [TOC] # 任務隊列簡介 ![](https://box.kancloud.cn/74d229854e314bd1e07b5617f3264cab_884x336.png) # 命令行 ![](https://box.kancloud.cn/b502571ea8b246d07844d6c48bb14ca9_410x302.png) # 常用 ## 增加 ~~~ jedis.lpushx("testList", "1,2,3,4,5,6,a,b,c,d,e,f");//向表插入數據,表不存在則忽略 jedis.lpush("testList", "1,2,3,4,5,6,a,b,c,d,e,f");//向表插入數據,表不存在就創建 jedis.linsert("testList", BinaryClient.LIST_POSITION.BEFORE, "e", "99");//在元素值是f的前面插入99 jedis.linsert("testList", BinaryClient.LIST_POSITION.AFTER, "f", "100");//在元素值是f的后面插入100 ~~~ ## 刪除 ~~~ jedis.rpop("testList");//彈出 jedis.lrem("testList", 2, "d");//指令會刪除count個值為value的元素; 如果count大于0則從頭遍歷;如果count小于0則從尾遍歷;如果count等于0,刪除鏈表中所有等于某個值的元素 ~~~ ## 修改 ~~~ jedis.lset("testList", 0, "aa");//修改指定索引號位置的值 ~~~ ## 查詢 ~~~ jedis.lrange("testList", 0, 3);//查找某范圍值 ~~~ # 例子 ## 生成隊列-生產者 ~~~ //創建一個jedis客戶端對象(redis的客戶端連接) Jedis jedis = new Jedis("127.0.0.1", 6379); //設置auth密碼 jedis.auth("root"); Random random = new Random(); while (true) { int nextInt = random.nextInt(1000); Thread.sleep(1000 + nextInt); //生成一個任務的id String taskid = UUID.randomUUID().toString(); jedis.lpush("task-queue", taskid); System.out.println("生成了一個任務" + taskid); } ~~~ ## 消耗隊列 ~~~ @Test public void testList() throws InterruptedException { //其他方法 Jedis jedis = init(); Random random = new Random(); while (true) { //消耗速度 Thread.sleep(1500); //從任務隊列中取出一個任務,同時放入到暫存隊列中 String taskid = jedis.rpoplpush("task-queue", "tmp-queue"); //處理任務 if (random.nextInt(19) % 9 == 0) { //模擬失敗 //失敗情況下,需要將任務從暫存隊列彈回任務隊列 jedis.rpoplpush("tmp-queue", "task-queue"); System.out.println("該任務處理失敗: " + taskid); } else { //模擬成功 //成功的情況下,只需要將任務從暫存隊列清除 jedis.rpop("tmp-queue"); System.out.println("任務處理成功: " + taskid); } } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看