** Copyright (C) 2001-2023 Zabbix SIA
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"git.zabbix.com/ap/plugin-support/metric"
"git.zabbix.com/ap/plugin-support/plugin"
"git.zabbix.com/ap/plugin-support/uri"
"git.zabbix.com/ap/plugin-support/zbxerr"
const pluginName = "Redis"
// Plugin inherits plugin.Base and store plugin-specific data.
// impl is the pointer to the plugin implementation.
// Export implements the Exporter interface.
func (p *Plugin) Export(key string, rawParams []string, ctx plugin.ContextProvider) (result interface{}, err error) {
params, _, hc, err := metrics[key].EvalParams(rawParams, p.options.Sessions)
err = metric.SetDefaults(params, hc, p.options.Default)
uri, err := uri.NewWithCreds(params["URI"], "zabbix", params["Password"], uriDefaults)
handleMetric := getHandlerFunc(key)
return nil, zbxerr.ErrorUnsupportedMetric
conn, err := p.connMgr.GetConnection(*uri)
// Special logic of processing connection errors is used if redis.ping is requested
// because it must return pingFailed if any error occurred.
result, err = handleMetric(conn, params)
// Start implements the Runner interface and performs initialization when plugin is activated.
func (p *Plugin) Start() {
p.connMgr = NewConnManager(
time.Duration(p.options.KeepAlive)*time.Second,
time.Duration(p.options.Timeout)*time.Second,