Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:A616567126 GPT WEB JAVA QueueUtil

From Leeroopedia
Knowledge Sources
Domains Queue_Management, Redis
Last Updated 2026-10-13 00:00 GMT

Overview

Concrete tool for managing a Redis-backed FIFO queue for Stable Diffusion image generation requests, provided by the Spring framework.

Description

The QueueUtil class uses a Redis list (user_queue) to implement a bounded FIFO queue. Methods:

  • addUserToQueue(value) — Right-pushes serialized request to Redis list; throws if queue exceeds QUEUE_SIZE
  • getPosition(value) — Linear scan to find request position; returns -1 if not found
  • getCurrentQueueLength() — Returns list size
  • getCurrentQueue() — Returns all queued items
  • remove(value) — Removes a specific value from the queue

Usage

Import this utility when you need to:

  • Queue SD image generation requests in Redis
  • Check a user's queue position for progress polling
  • Remove processed items from the queue

Code Reference

Source Location

  • Repository: GPT-WEB-JAVA
  • File: src/main/java/com/intelligent/bot/utils/sys/QueueUtil.java

Signature

@Component
public class QueueUtil {
    public QueueUtil(RedisTemplate<String, String> redisTemplate);

    public void addUserToQueue(String value);
    public long getCurrentQueueLength();
    public List<String> getCurrentQueue();
    public int getPosition(String value);
    public void remove(String value);
}

Import

import com.intelligent.bot.utils.sys.QueueUtil;

I/O Contract

Inputs

Name Type Required Description
value String Yes Serialized SdCreateReq JSON

Outputs

Name Type Description
getPosition returns int Queue position (0-based), or -1 if not found
getCurrentQueueLength returns long Number of items in queue

Usage Examples

Adding to Queue

String value = JSONObject.toJSONString(req);
int position = queueUtil.getPosition(value);
if (position > -1) {
    throw new E("您已发起相同请求,请等待画图完成");
}
queueUtil.addUserToQueue(value);
// Throws E("队列已满请等待") if getCurrentQueueLength() > QUEUE_SIZE

Processing Queue Head

// In MyTask.run()
List<String> promptList = queueUtil.getCurrentQueue();
SdCreateReq req = JSONObject.parseObject(promptList.get(0), SdCreateReq.class);
// ... process request ...
queueUtil.remove(promptList.get(0));  // Remove after processing

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment