@@ -8,46 +8,32 @@ import (
88 "github.com/cschleiden/go-workflows/core"
99 "github.com/cschleiden/go-workflows/diag"
1010 "github.com/cschleiden/go-workflows/internal/log"
11- "github.com/valkey-io/valkey-glide/go/v2/constants"
12- "github.com/valkey-io/valkey-glide/go/v2/options"
1311)
1412
1513var _ diag.Backend = (* valkeyBackend )(nil )
1614
1715func (vb * valkeyBackend ) GetWorkflowInstances (ctx context.Context , afterInstanceID , afterExecutionID string , count int ) ([]* diag.WorkflowInstanceRef , error ) {
18- start := options .NewInclusiveScoreBoundary (0 )
19- end := options .NewInfiniteScoreBoundary (constants .PositiveInfinity )
20-
21- zrangeInput := & options.RangeByScore {
22- Start : start ,
23- End : end ,
24- Reverse : true ,
25- Limit : & options.Limit {
26- Offset : 0 ,
27- Count : int64 (count ),
28- },
29- }
16+ zrangeCmd := vb .client .B ().Zrange ().Key (vb .keys .instancesByCreation ()).Min ("0" ).Max ("-1" ).Rev ().Limit (0 , int64 (count ))
3017
3118 if afterInstanceID != "" {
3219 afterSegmentID := instanceSegment (core .NewWorkflowInstance (afterInstanceID , afterExecutionID ))
33- scores , err := vb .client .ZMScore (ctx , vb .keys .instancesByCreation (), [] string { afterSegmentID } )
20+ scores , err := vb .client .Do (ctx , vb .client . B (). Zscore (). Key ( vb . keys .instancesByCreation ()). Member ( afterSegmentID ). Build ()). AsFloat64 ( )
3421 if err != nil {
3522 return nil , fmt .Errorf ("getting instance score for %v: %w" , afterSegmentID , err )
3623 }
3724
38- if len ( scores ) == 0 {
25+ if scores == 0 {
3926 vb .Options ().Logger .Error ("could not find instance %v" ,
4027 log .NamespaceKey + ".valkey.afterInstanceID" , afterInstanceID ,
4128 log .NamespaceKey + ".valkey.afterExecutionID" , afterExecutionID ,
4229 )
4330 return nil , nil
4431 }
4532
46- end := options .NewScoreBoundary (scores [0 ].Value (), false )
47- zrangeInput .End = end
33+ zrangeCmd = vb .client .B ().Zrange ().Key (vb .keys .instancesByCreation ()).Min ("-inf" ).Max (fmt .Sprintf ("(%f" , scores )).Rev ().Limit (0 , int64 (count ))
4834 }
4935
50- instanceSegments , err := vb .client .ZRange (ctx , vb . keys . instancesByCreation (), zrangeInput )
36+ instanceSegments , err := vb .client .Do (ctx , zrangeCmd . Build ()). AsStrSlice ( )
5137 if err != nil {
5238 return nil , fmt .Errorf ("getting instances: %w" , err )
5339 }
@@ -61,19 +47,20 @@ func (vb *valkeyBackend) GetWorkflowInstances(ctx context.Context, afterInstance
6147 instanceKeys = append (instanceKeys , vb .keys .instanceKeyFromSegment (r ))
6248 }
6349
64- instances , err := vb .client .MGet (ctx , instanceKeys )
50+ cmd := vb .client .B ().Mget ().Key (instanceKeys ... )
51+ instances , err := vb .client .Do (ctx , cmd .Build ()).AsStrSlice ()
6552 if err != nil {
6653 return nil , fmt .Errorf ("getting instances: %w" , err )
6754 }
6855
6956 instanceRefs := make ([]* diag.WorkflowInstanceRef , 0 , len (instances ))
7057 for _ , instance := range instances {
71- if instance . IsNil () {
58+ if instance == "" {
7259 continue
7360 }
7461
7562 var state instanceState
76- if err := json .Unmarshal ([]byte (instance . Value () ), & state ); err != nil {
63+ if err := json .Unmarshal ([]byte (instance ), & state ); err != nil {
7764 return nil , fmt .Errorf ("unmarshaling instance state: %w" , err )
7865 }
7966
0 commit comments