MCPcopy
hub / github.com/redis/go-redis / register

Method register

redis.go:258–268  ·  view source on GitHub ↗

register adds or replaces the callback associated with id. Re-registering an existing id overwrites the previous callback in place; new ids are appended to the invocation order.

(id string, fn func() error)

Source from the content-addressed store, hash-verified

256// an existing id overwrites the previous callback in place; new ids are
257// appended to the invocation order.
258func (h *onCloseHooks) register(id string, fn func() error) {
259 h.mu.Lock()
260 defer h.mu.Unlock()
261 if h.hooks == nil {
262 h.hooks = make(map[string]func() error)
263 }
264 if _, exists := h.hooks[id]; !exists {
265 h.order = append(h.order, id)
266 }
267 h.hooks[id] = fn
268}
269
270// unregister removes the callback associated with id, if any. It is kept
271// for API symmetry with register so future callers (e.g. dynamic hook

Calls

no outgoing calls