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

Method Set

plugin/kv_storage.go:175–208  ·  view source on GitHub ↗

Set stores a value in KV storage with the specified group and key. Updates the value if it already exists.

(ctx context.Context, params KVParams)

Source from the content-addressed store, hash-verified

173// Set stores a value in KV storage with the specified group and key.
174// Updates the value if it already exists.
175func (kv *KVOperator) Set(ctx context.Context, params KVParams) error {
176 if params.Key == "" {
177 return ErrKVKeyEmpty
178 }
179
180 query, cleanup := kv.getSession(ctx)
181 defer cleanup()
182
183 data := &entity.PluginKVStorage{
184 PluginSlugName: kv.pluginSlugName,
185 Group: params.Group,
186 Key: params.Key,
187 Value: params.Value,
188 }
189
190 kv.cleanCache(ctx, params)
191
192 affected, err := query.Where(builder.Eq{
193 "plugin_slug_name": kv.pluginSlugName,
194 "`group`": params.Group,
195 "`key`": params.Key,
196 }).Cols("value").Update(data)
197 if err != nil {
198 return err
199 }
200
201 if affected == 0 {
202 _, err = query.Insert(data)
203 if err != nil {
204 return err
205 }
206 }
207 return nil
208}
209
210// Del removes values from KV storage by group and/or key.
211// If both group and key are provided, only that specific entry is deleted.

Callers 13

mustSetFunction · 0.80
TestBasicOperationsFunction · 0.80
TestTransactionsFunction · 0.80
TestConcurrencyFunction · 0.80
ResizeFunction · 0.80
remoteVersionMethod · 0.80
SetShortIDFlagMethod · 0.80
AuthMethod · 0.80
AdminAuthMethod · 0.80

Calls 4

getSessionMethod · 0.95
cleanCacheMethod · 0.95
UpdateMethod · 0.80
InsertMethod · 0.80

Tested by 4

mustSetFunction · 0.64
TestBasicOperationsFunction · 0.64
TestTransactionsFunction · 0.64
TestConcurrencyFunction · 0.64