** Copyright (C) 2001-2025 Zabbix SIA
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
** 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 Affero General Public License for more details.
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
"github.com/memcachier/mc/v3"
"golang.zabbix.com/sdk/log"
"golang.zabbix.com/sdk/uri"
"golang.zabbix.com/sdk/zbxerr"
type MCClient interface {
Stats(key string) (mc.McStats, error)
StatsFunc func(key string) (mc.McStats, error)
func (c *stubConn) Stats(key string) (mc.McStats, error) {
func (c *stubConn) NoOp() error {
// Stats wraps the mc.Client.StatsWithKey function.
func (conn *MCConn) Stats(key string) (stats mc.McStats, err error) {
res, err := conn.client.StatsWithKey(key)
return nil, zbxerr.ErrorEmptyResult
panic("unexpected result")
// get the only entry of stats
for _, stats = range res {
// NoOp wraps the mc.Client.NoOp function.
func (conn *MCConn) NoOp() error {
return conn.client.NoOp()
// updateAccessTime updates the last time a connection was accessed.
func (conn *MCConn) updateAccessTime() {
conn.lastTimeAccess = time.Now()
// ConnManager is thread-safe structure for manage connections.
type ConnManager struct {
connections map[uri.URI]*MCConn