MCPcopy
hub / github.com/apache/answer / Get

Method Get

plugin/kv_storage.go:139–171  ·  view source on GitHub ↗

Get retrieves a value from KV storage by group and key. Returns the value as a string or an error if the key is not found.

(ctx context.Context, params KVParams)

Source from the content-addressed store, hash-verified

137// Get retrieves a value from KV storage by group and key.
138// Returns the value as a string or an error if the key is not found.
139func (kv *KVOperator) Get(ctx context.Context, params KVParams) (string, error) {
140 if params.Key == "" {
141 return "", ErrKVKeyEmpty
142 }
143
144 if value, exist, err := kv.getCache(ctx, params); err == nil && exist {
145 return value, nil
146 }
147
148 // query
149 data := entity.PluginKVStorage{}
150 query, cleanup := kv.getSession(ctx)
151 defer cleanup()
152
153 query.Where(builder.Eq{
154 "plugin_slug_name": kv.pluginSlugName,
155 "`group`": params.Group,
156 "`key`": params.Key,
157 })
158
159 has, err := query.Get(&data)
160 if err != nil {
161 return "", err
162 }
163 if !has {
164 return "", ErrKVKeyNotFound
165 }
166
167 params.Value = data.Value
168 kv.setCache(ctx, params)
169
170 return data.Value, nil
171}
172
173// Set stores a value in KV storage with the specified group and key.
174// Updates the value if it already exists.

Callers 4

mustGetFunction · 0.45
assertNotFoundFunction · 0.45
TestConcurrencyFunction · 0.45
GetPicByUrlFunction · 0.45

Calls 3

getCacheMethod · 0.95
getSessionMethod · 0.95
setCacheMethod · 0.95

Tested by 3

mustGetFunction · 0.36
assertNotFoundFunction · 0.36
TestConcurrencyFunction · 0.36