Implementation:A616567126 GPT WEB JAVA QueueUtil
Appearance
| 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 exceedsQUEUE_SIZEgetPosition(value)— Linear scan to find request position; returns -1 if not foundgetCurrentQueueLength()— Returns list sizegetCurrentQueue()— Returns all queued itemsremove(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
- Principle:A616567126_GPT_WEB_JAVA_Task_Queueing
- Principle:A616567126_GPT_WEB_JAVA_SD_WebUI_Integration
Requires Environment
- Environment:A616567126_GPT_WEB_JAVA_Redis_Cache
- Environment:A616567126_GPT_WEB_JAVA_SD_WebUI_Service
Uses Heuristic
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment