MCPcopy
hub / github.com/mochi-mqtt/server / setKv

Method setKv

hooks/storage/bolt/bolt.go:457–472  ·  view source on GitHub ↗

setKv stores a key-value pair in the database.

(k string, v storage.Serializable)

Source from the content-addressed store, hash-verified

455
456// setKv stores a key-value pair in the database.
457func (h *Hook) setKv(k string, v storage.Serializable) error {
458 err := h.db.Update(func(tx *bbolt.Tx) error {
459
460 bucket := tx.Bucket([]byte(h.config.Bucket))
461 data, _ := v.MarshalBinary()
462 err := bucket.Put([]byte(k), data)
463 if err != nil {
464 return err
465 }
466 return nil
467 })
468 if err != nil {
469 h.Log.Error("failed to upsert data", "error", err, "key", k)
470 }
471 return err
472}
473
474// delKv deletes a key-value pair from the database.
475func (h *Hook) delKv(k string) error {

Callers 14

updateClientMethod · 0.95
OnSubscribedMethod · 0.95
OnRetainMessageMethod · 0.95
OnQosPublishMethod · 0.95
OnSysInfoTickMethod · 0.95
TestOnClientExpiredFunction · 0.45
TestOnRetainedExpiredFunction · 0.45
TestStoredClientsFunction · 0.45
TestStoredSubscriptionsFunction · 0.45
TestStoredSysInfoFunction · 0.45

Implementers 1

HookBasehooks.go

Calls 4

UpdateMethod · 0.80
ErrorMethod · 0.80
MarshalBinaryMethod · 0.65
PutMethod · 0.65

Tested by 9

TestOnClientExpiredFunction · 0.36
TestOnRetainedExpiredFunction · 0.36
TestStoredClientsFunction · 0.36
TestStoredSubscriptionsFunction · 0.36
TestStoredSysInfoFunction · 0.36
TestGetSetDelKvFunction · 0.36
TestIterKvFunction · 0.36