Talk about jesque’s data structure in redis

  redis

Order

This article mainly introduces jesque’s storage structure in redis.

Sample configuration

namespace=demo
listen-queue=demoqueue

Reids object at startup

127.0.0.1:6379> keys *
1) "demo:worker:Mars.local:3820-3:JAVA_DYNAMIC_QUEUES,demoqueue:started"
2) "demo:worker:Mars.local:3820-1:JAVA_DYNAMIC_QUEUES,demoqueue:started"
3) "demo:worker:Mars.local:3820-0:JAVA_DYNAMIC_QUEUES,demoqueue:started"
4) "demo:workers"
5) "demo:worker:Mars.local:3820-2:JAVA_DYNAMIC_QUEUES,demoqueue:started"
6) "demo:worker:Mars.local:3820-4:JAVA_DYNAMIC_QUEUES,demoqueue:started"
127.0.0.1:6379> type demo:workers
set
127.0.0.1:6379> smembers demo:workers
1) "Mars.local:3820-4:JAVA_DYNAMIC_QUEUES,demoqueue"
2) "Mars.local:3820-2:JAVA_DYNAMIC_QUEUES,demoqueue"
3) "Mars.local:3820-1:JAVA_DYNAMIC_QUEUES,demoqueue"
4) "Mars.local:3820-0:JAVA_DYNAMIC_QUEUES,demoqueue"
5) "Mars.local:3820-3:JAVA_DYNAMIC_QUEUES,demoqueue"

namespace:workers

Set-type data interface that stores the names of workers under the namespace

namespace:worker:host:queueType,listen-queue:state

This is the status of the worker that marks each namespace. It is a string that stores the time when the event was generated.

127.0.0.1:6379> type demo:worker:Mars.local:3820-3:JAVA_DYNAMIC_QUEUES,demoqueue:started
string
127.0.0.1:6379> get demo:worker:Mars.local:3820-3:JAVA_DYNAMIC_QUEUES,demoqueue:started
"2017-11-18T15:35:24.913+0800"

Add job

127.0.0.1:6379> keys *
1) "demo:worker:Mars.local:3820-3:JAVA_DYNAMIC_QUEUES,demoqueue:started"
2) "demo:queue:demoqueue"
3) "demo:worker:Mars.local:3820-1:JAVA_DYNAMIC_QUEUES,demoqueue:started"
4) "demo:worker:Mars.local:3820-0:JAVA_DYNAMIC_QUEUES,demoqueue:started"
5) "demo:queues"
6) "demo:workers"
7) "demo:worker:Mars.local:3820-2:JAVA_DYNAMIC_QUEUES,demoqueue:started"
8) "demo:worker:Mars.local:3820-4:JAVA_DYNAMIC_QUEUES,demoqueue:started"

It can be found that several queue-related objects have been added.
This is a lock message.

namespace:queues

Is a set structure that stores queue information

127.0.0.1:6379> smembers demo:queues
1) "demoqueue"

Finish processing job

127.0.0.1:6379> keys *
1) "demo:worker:Mars.local:3820-1:JAVA_DYNAMIC_QUEUES,demoqueue:started"
2) "demo:worker:Mars.local:3820-0:JAVA_DYNAMIC_QUEUES,demoqueue:started"
3) "demo:queues"
4) "demo:stat:processed"
5) "demo:stat:processed:Mars.local:3820-0:JAVA_DYNAMIC_QUEUES,demoqueue"
6) "demo:worker:Mars.local:3820-3:JAVA_DYNAMIC_QUEUES,demoqueue:started"
7) "demo:workers"
8) "demo:worker:Mars.local:3820-4:JAVA_DYNAMIC_QUEUES,demoqueue:started"
9) "demo:worker:Mars.local:3820-2:JAVA_DYNAMIC_QUEUES,demoqueue:started"

You can find that two stat-related objects have been added

namespace:stat:processed

Is a string that counts the number of jobs processed

127.0.0.1:6379> type demo:stat:processed
string
127.0.0.1:6379> get demo:stat:processed
"1"

namespace:stat:processed:host:queueType,listen-queue

Stores the number of each queue processed by each host

127.0.0.1:6379> type demo:stat:processed:Mars.local:3820-0:JAVA_DYNAMIC_QUEUES,demoqueue
string
127.0.0.1:6379> get demo:stat:processed:Mars.local:3820-0:JAVA_DYNAMIC_QUEUES,demoqueue
"1"

When you close the worker

127.0.0.1:6379> keys *
1) "demo:queues"
2) "demo:stat:processed"

There are only two messages left.

When job execution fails

127.0.0.1:6379> keys *
 1) "demo:stat:failed"
 2) "demo:failed"
 3) "demo:queues"
 4) "demo:stat:processed"
 5) "demo:worker:Mars.local:3947-2:JAVA_DYNAMIC_QUEUES,demoqueue:started"
 6) "demo:worker:Mars.local:3947-3:JAVA_DYNAMIC_QUEUES,demoqueue:started"
 7) "demo:worker:Mars.local:3947-1:JAVA_DYNAMIC_QUEUES,demoqueue:started"
 8) "demo:worker:Mars.local:3947-4:JAVA_DYNAMIC_QUEUES,demoqueue:started"
 9) "demo:worker:Mars.local:3947-0:JAVA_DYNAMIC_QUEUES,demoqueue:started"
10) "demo:workers"
11) "demo:stat:failed:Mars.local:3947-0:JAVA_DYNAMIC_QUEUES,demoqueue"

Three more failed related objects can be found.

namespace:failed

Is a list type

127.0.0.1:6379> type demo:failed
list
127.0.0.1:6379> lrange demo:failed 0 -1
1) "{\"worker\":\"Mars.local:3947-0:JAVA_DYNAMIC_QUEUES,demoqueue\",\"queue\":\"demoqueue\",\"payload\":{\"class\":\"com.example.demo.job.DemoJob\",\"args\":[\"111\",1510991413785],\"vars\":null,\"jobId\":\"c4c0289e-5d13-4bc3-8499-f3e35c5956a6\"},\"backtrace\":[\"\\tat com.example.demo.job.DemoJob.run(DemoJob.java:30)\",\"\\tat cn.codecraft.jesque.component.RedisPooledWorkerImpl.execute(RedisPooledWorkerImpl.java:656)\",\"\\tat cn.codecraft.jesque.component.RedisPooledWorkerImpl.process(RedisPooledWorkerImpl.java:611)\",\"\\tat cn.codecraft.jesque.component.RedisPooledWorkerImpl.poll(RedisPooledWorkerImpl.java:420)\",\"\\tat cn.codecraft.jesque.component.RedisPooledWorkerImpl.run(RedisPooledWorkerImpl.java:171)\",\"\\tat java.lang.Thread.run(Thread.java:745)\"],\"error\":\"demo ex\",\"exception\":\"java.lang.RuntimeException\",\"failed_at\":\"2017-11-18T07:50:33.921+0000\",\"retried_at\":null}"

Specific job information and exceptions are stored

namespace:stat:failed

Count of failed jobs stored

127.0.0.1:6379> type demo:stat:failed
string
127.0.0.1:6379> get demo:stat:failed
"1"

namespace:stat:failed:host:queueType,listen-queue

Stores the number of processing failures per host per queue

127.0.0.1:6379> type demo:stat:failed:Mars.local:3947-0:JAVA_DYNAMIC_QUEUES,demoqueue
string
127.0.0.1:6379> get demo:stat:failed:Mars.local:3947-0:JAVA_DYNAMIC_QUEUES,demoqueue
"1"