MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / LSet

Method LSet

engine/grpc/client/list.go:356–395  ·  view source on GitHub ↗
(key string, index int, value interface{})

Source from the content-addressed store, hash-verified

354}
355
356func (c *Client) LSet(key string, index int, value interface{}) error {
357 client, err := newListGrpcClient(c.Addr)
358 if err != nil {
359 return errors.New("new grpc client error: " + err.Error())
360 }
361
362 req := &glist.GListLSetRequest{
363 Key: key,
364 Index: int32(index),
365 }
366
367 switch v := value.(type) {
368 case string:
369 req.Value = &glist.GListLSetRequest_StringValue{StringValue: v}
370 case int32:
371 req.Value = &glist.GListLSetRequest_Int32Value{Int32Value: v}
372 case int64:
373 req.Value = &glist.GListLSetRequest_Int64Value{Int64Value: v}
374 case float32:
375 req.Value = &glist.GListLSetRequest_Float32Value{Float32Value: v}
376 case float64:
377 req.Value = &glist.GListLSetRequest_Float64Value{Float64Value: v}
378 case bool:
379 req.Value = &glist.GListLSetRequest_BoolValue{BoolValue: v}
380 case []byte:
381 req.Value = &glist.GListLSetRequest_BytesValue{BytesValue: v}
382 default:
383 return errors.New("unknown value type")
384 }
385
386 resp, err := client.LSet(context.Background(), req)
387 if err != nil {
388 return errors.New("client LSet failed: " + err.Error())
389 }
390
391 if !resp.Ok {
392 return errors.New("LSet failed")
393 }
394 return nil
395}
396
397func (c *Client) LTrim(key string, start, stop int) error {
398 client, err := newListGrpcClient(c.Addr)

Callers

nothing calls this directly

Calls 2

newListGrpcClientFunction · 0.85
LSetMethod · 0.65

Tested by

no test coverage detected