Get gets a value by key from the db by client api
(key string)
| 44 | |
| 45 | // Get gets a value by key from the db by client api |
| 46 | func (c *Client) Get(key string) (interface{}, error) { |
| 47 | client, err := newGrpcClient(c.Addr) |
| 48 | if err != nil { |
| 49 | return nil, err |
| 50 | } |
| 51 | get, err := client.Get(context.Background(), &gstring.GetRequest{Key: key}) |
| 52 | if err != nil { |
| 53 | return nil, err |
| 54 | } |
| 55 | switch get.Value.(type) { |
| 56 | case *gstring.GetResponse_StringValue: |
| 57 | return get.Value.(*gstring.GetResponse_StringValue).StringValue, nil |
| 58 | case *gstring.GetResponse_Int32Value: |
| 59 | return get.Value.(*gstring.GetResponse_Int32Value).Int32Value, nil |
| 60 | case *gstring.GetResponse_Int64Value: |
| 61 | return get.Value.(*gstring.GetResponse_Int64Value).Int64Value, nil |
| 62 | case *gstring.GetResponse_Float32Value: |
| 63 | return get.Value.(*gstring.GetResponse_Float32Value).Float32Value, nil |
| 64 | case *gstring.GetResponse_Float64Value: |
| 65 | return get.Value.(*gstring.GetResponse_Float64Value).Float64Value, nil |
| 66 | case *gstring.GetResponse_BoolValue: |
| 67 | return get.Value.(*gstring.GetResponse_BoolValue).BoolValue, nil |
| 68 | case *gstring.GetResponse_BytesValue: |
| 69 | return get.Value.(*gstring.GetResponse_BytesValue).BytesValue, nil |
| 70 | default: |
| 71 | return nil, errors.New("get failed") |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | // Del deletes a key-value pair from the db by client api |
| 76 | func (c *Client) Del(key string) error { |
nothing calls this directly
no test coverage detected