diff options
Diffstat (limited to 'plugins/redis/tests/plugin1.go')
-rw-r--r-- | plugins/redis/tests/plugin1.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/plugins/redis/tests/plugin1.go b/plugins/redis/tests/plugin1.go new file mode 100644 index 00000000..e19ca90a --- /dev/null +++ b/plugins/redis/tests/plugin1.go @@ -0,0 +1,43 @@ +package tests + +import ( + "context" + "time" + + "github.com/go-redis/redis/v8" + "github.com/spiral/errors" + redisPlugin "github.com/spiral/roadrunner/v2/interfaces/redis" +) + +type Plugin1 struct { + redisClient redis.UniversalClient +} + +func (p *Plugin1) Init(redis redisPlugin.Redis) error { + p.redisClient = redis.GetClient() + return nil +} + +func (p *Plugin1) Serve() chan error { + const op = errors.Op("plugin1 serve") + errCh := make(chan error, 1) + p.redisClient.Set(context.Background(), "foo", "bar", time.Minute) + + stringCmd := p.redisClient.Get(context.Background(), "foo") + data, err := stringCmd.Result() + if err != nil { + errCh <- errors.E(op, err) + return errCh + } + + if data != "bar" { + errCh <- errors.E(op, errors.Str("no such key")) + return errCh + } + + return errCh +} + +func (p *Plugin1) Stop() error { + return p.redisClient.Close() +} |