@@ -25,51 +25,66 @@ export type RedisScripts = {
25
25
} ;
26
26
27
27
const recordResult : RecordResultScript = defineScript ( {
28
- NUMBER_OF_KEYS : 4 ,
28
+ NUMBER_OF_KEYS : 2 ,
29
29
SCRIPT : `
30
- local measurementId = KEYS[1]
31
- local testId = KEYS[2]
32
- local data = KEYS[3]
33
- local date = KEYS[4]
34
- local key = 'gp:m:'..measurementId..':results'
35
- local awaitingKey = 'gp:m:'..measurementId..':probes_awaiting'
30
+ local keyMeasurementResults = KEYS[1]
31
+ local keyMeasurementAwaiting = KEYS[2]
32
+ local testId = ARGV[1]
33
+ local data = ARGV[2]
34
+ local date = ARGV[3]
36
35
37
- local probesAwaiting = redis.call('GET', awaitingKey )
36
+ local probesAwaiting = redis.call('GET', keyMeasurementAwaiting )
38
37
if not probesAwaiting then
39
38
return
40
39
end
41
40
42
- probesAwaiting = redis.call('DECR', awaitingKey )
43
- redis.call('JSON.SET', key , '$.results['..testId..'].result', data)
44
- redis.call('JSON.SET', key , '$.updatedAt', date)
41
+ probesAwaiting = redis.call('DECR', keyMeasurementAwaiting )
42
+ redis.call('JSON.SET', keyMeasurementResults , '$.results['..testId..'].result', data)
43
+ redis.call('JSON.SET', keyMeasurementResults , '$.updatedAt', date)
45
44
46
45
if probesAwaiting ~= 0 then
47
46
return
48
47
end
49
48
50
- return redis.call('JSON.GET', key )
49
+ return redis.call('JSON.GET', keyMeasurementResults )
51
50
` ,
52
51
transformArguments ( measurementId , testId , data ) {
53
- return [ measurementId , testId , JSON . stringify ( data ) , `"${ new Date ( ) . toISOString ( ) } "` ] ;
52
+ return [
53
+ // keys
54
+ `gp:m:${ measurementId } :results` ,
55
+ `gp:m:${ measurementId } :probes_awaiting` ,
56
+ // values
57
+ testId ,
58
+ JSON . stringify ( data ) ,
59
+ `"${ new Date ( ) . toISOString ( ) } "` ,
60
+ ] ;
54
61
} ,
55
62
transformReply ( reply ) {
56
63
return JSON . parse ( reply ) as MeasurementRecord | null ;
57
64
} ,
58
65
} ) ;
59
66
60
67
const markFinished : MarkFinishedScript = defineScript ( {
61
- NUMBER_OF_KEYS : 1 ,
68
+ NUMBER_OF_KEYS : 3 ,
62
69
SCRIPT : `
63
- local measurementId = KEYS[1]
64
- local key = 'gp:m:'..measurementId..':results'
65
- local awaitingKey = 'gp:m:'..measurementId..':probes_awaiting'
70
+ local keyInProgress = KEYS[1]
71
+ local keyMeasurementResults = KEYS[2]
72
+ local keyMeasurementAwaiting = KEYS[3]
73
+ local measurementId = ARGV[1]
66
74
67
- redis.call('HDEL', 'gp:in-progress' , measurementId)
68
- redis.call('DEL', awaitingKey )
69
- redis.call('JSON.SET', key , '$.status', '"finished"')
75
+ redis.call('HDEL', keyInProgress , measurementId)
76
+ redis.call('DEL', keyMeasurementAwaiting )
77
+ redis.call('JSON.SET', keyMeasurementResults , '$.status', '"finished"')
70
78
` ,
71
79
transformArguments ( measurementId ) {
72
- return [ measurementId ] ;
80
+ return [
81
+ // keys
82
+ 'gp:in-progress' ,
83
+ `gp:m:${ measurementId } :results` ,
84
+ `gp:m:${ measurementId } :probes_awaiting` ,
85
+ // values
86
+ measurementId ,
87
+ ] ;
73
88
} ,
74
89
transformReply ( ) {
75
90
return null ;
0 commit comments