diff options
author | Valery Piashchynski <[email protected]> | 2020-12-17 18:23:19 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2020-12-17 18:23:19 +0300 |
commit | fbd5adde5abae6f7adb7fcdafc226bcd3480d498 (patch) | |
tree | 59ce0499568e0d4fd889d43de9a5eb1b17907a8e /plugins/redis | |
parent | 7884349f27ed750825a0f4dea59af8964e182651 (diff) |
Move config interface to the interfaces folder. Initial redis plugin
structure
Diffstat (limited to 'plugins/redis')
-rw-r--r-- | plugins/redis/config.go | 18 | ||||
-rw-r--r-- | plugins/redis/plugin.go | 55 | ||||
-rw-r--r-- | plugins/redis/tests/configs/.rr-redis.yaml | 25 |
3 files changed, 98 insertions, 0 deletions
diff --git a/plugins/redis/config.go b/plugins/redis/config.go new file mode 100644 index 00000000..b39fcd00 --- /dev/null +++ b/plugins/redis/config.go @@ -0,0 +1,18 @@ +package redis + +type Config struct { + // Addr is address to use. If len > 1, cluster client will be used + Addr []string + // database number to use, 0 is used by default + DB int + // Master name for failover client, empty by default + Master string + // Redis password, empty by default + Password string +} + +// InitDefaults initializing fill config with default values +func (s *Config) InitDefaults() error { + s.Addr = []string{"localhost:6379"} // default addr is pointing to local storage + return nil +} diff --git a/plugins/redis/plugin.go b/plugins/redis/plugin.go index 65a229e1..64b6024e 100644 --- a/plugins/redis/plugin.go +++ b/plugins/redis/plugin.go @@ -1 +1,56 @@ package redis + +import ( + "github.com/go-redis/redis/v8" + "github.com/spiral/roadrunner/v2/interfaces/config" + "github.com/spiral/roadrunner/v2/interfaces/log" +) + +const PluginName = "redis" + +type Plugin struct { + // config for RR integration + cfg *Config + // redis client + universalClient *redis.UniversalClient + clusterClient *redis.ClusterClient + client *redis.Client + sentinelClient *redis.SentinelClient +} + +func (s *Plugin) GetClient() *redis.Client { + return s.client +} + +func (s *Plugin) GetUniversalClient() *redis.UniversalClient { + return s.universalClient +} + +func (s *Plugin) GetClusterClient() *redis.ClusterClient { + return s.clusterClient +} + +func (s *Plugin) GetSentinelClient() *redis.SentinelClient { + return s.sentinelClient +} + +func (s *Plugin) Init(cfg config.Configurer, log log.Logger) error { + _ = cfg + _ = log + _ = s.cfg + return nil +} + +func (s *Plugin) Serve() chan error { + errCh := make(chan error, 1) + + return errCh +} + +func (s Plugin) Stop() error { + return nil +} + +func (s *Plugin) Name() string { + return PluginName +} diff --git a/plugins/redis/tests/configs/.rr-redis.yaml b/plugins/redis/tests/configs/.rr-redis.yaml new file mode 100644 index 00000000..52198a35 --- /dev/null +++ b/plugins/redis/tests/configs/.rr-redis.yaml @@ -0,0 +1,25 @@ +redis: + - cluster: + addr: + - 'localhost:6379' + db: 0 + master: null + password: '' + - universal: + addr: + - 'localhost:6379' + db: 0 + master: null + password: '' + - default: + addr: + - 'localhost:6379' + db: 0 + master: null + password: '' + - sentinel: + addr: + - 'localhost:6379' + db: 0 + master: null + password: ''
\ No newline at end of file |