@@ -40,6 +40,11 @@ func Register() {
40
40
41
41
// New creates a new Redis client given a list of endpoints and optional tls config.
42
42
func New (endpoints []string , options * store.Config ) (store.Store , error ) {
43
+ return NewWithCodec (endpoints , options , & RawCodec {})
44
+ }
45
+
46
+ // NewWithCodec creates a new Redis client with codec config.
47
+ func NewWithCodec (endpoints []string , options * store.Config , codec Codec ) (store.Store , error ) {
43
48
if len (endpoints ) > 1 {
44
49
return nil , ErrMultipleEndpointsUnsupported
45
50
}
@@ -52,7 +57,7 @@ func New(endpoints []string, options *store.Config) (store.Store, error) {
52
57
password = options .Password
53
58
}
54
59
55
- return newRedis (context .Background (), endpoints , password , & RawCodec {} ), nil
60
+ return newRedis (context .Background (), endpoints , password , codec ), nil
56
61
}
57
62
58
63
func newRedis (ctx context.Context , endpoints []string , password string , codec Codec ) * Redis {
@@ -450,9 +455,14 @@ type pusher func(interface{})
450
455
func watchLoop (msgCh chan * redis.Message , _ <- chan struct {}, get getter , push pusher ) error {
451
456
// deliver the original data before we setup any events.
452
457
pair , err := get ()
453
- if err != nil {
458
+ if err != nil && ! errors . Is ( err , store . ErrKeyNotFound ) {
454
459
return err
455
460
}
461
+
462
+ if errors .Is (err , store .ErrKeyNotFound ) {
463
+ pair = & store.KVPair {}
464
+ }
465
+
456
466
push (pair )
457
467
458
468
for m := range msgCh {
@@ -463,11 +473,11 @@ func watchLoop(msgCh chan *redis.Message, _ <-chan struct{}, get getter, push pu
463
473
}
464
474
465
475
// in case of watching a key that has been expired or deleted return and empty KV.
466
- if errors .Is (err , store .ErrKeyNotFound ) && (m .Payload == "expire" || m .Payload == "del" ) {
467
- push (& store.KVPair {})
468
- } else {
469
- push (pair )
476
+ if errors .Is (err , store .ErrKeyNotFound ) && (m .Payload == "expired" || m .Payload == "del" ) {
477
+ pair = & store.KVPair {}
470
478
}
479
+
480
+ push (pair )
471
481
}
472
482
473
483
return nil
0 commit comments