| 139 | } |
| 140 | |
| 141 | func (s *str) GetSet(ctx context.Context, req *gstring.GetSetRequest) (*gstring.GetSetResponse, error) { |
| 142 | var previousValue interface{} |
| 143 | var err error |
| 144 | |
| 145 | switch v := req.Value.(type) { |
| 146 | case *gstring.GetSetRequest_StringValue: |
| 147 | previousValue, err = s.dbs.GetSet(req.Key, v.StringValue, req.Expire*1000) |
| 148 | case *gstring.GetSetRequest_Int32Value: |
| 149 | previousValue, err = s.dbs.GetSet(req.Key, v.Int32Value, req.Expire*1000) |
| 150 | case *gstring.GetSetRequest_Int64Value: |
| 151 | previousValue, err = s.dbs.GetSet(req.Key, v.Int64Value, req.Expire*1000) |
| 152 | case *gstring.GetSetRequest_Float32Value: |
| 153 | previousValue, err = s.dbs.GetSet(req.Key, v.Float32Value, req.Expire*1000) |
| 154 | case *gstring.GetSetRequest_Float64Value: |
| 155 | previousValue, err = s.dbs.GetSet(req.Key, v.Float64Value, req.Expire*1000) |
| 156 | case *gstring.GetSetRequest_BoolValue: |
| 157 | previousValue, err = s.dbs.GetSet(req.Key, v.BoolValue, req.Expire*1000) |
| 158 | case *gstring.GetSetRequest_BytesValue: |
| 159 | previousValue, err = s.dbs.GetSet(req.Key, v.BytesValue, req.Expire*1000) |
| 160 | default: |
| 161 | return nil, fmt.Errorf("unknown value type") |
| 162 | } |
| 163 | if err != nil { |
| 164 | return &gstring.GetSetResponse{}, err |
| 165 | } |
| 166 | resp := &gstring.GetSetResponse{} |
| 167 | switch v := previousValue.(type) { |
| 168 | case string: |
| 169 | resp.Value = &gstring.GetSetResponse_StringValue{StringValue: v} |
| 170 | case int32: |
| 171 | resp.Value = &gstring.GetSetResponse_Int32Value{Int32Value: v} |
| 172 | case int64: |
| 173 | resp.Value = &gstring.GetSetResponse_Int64Value{Int64Value: v} |
| 174 | case float32: |
| 175 | resp.Value = &gstring.GetSetResponse_Float32Value{Float32Value: v} |
| 176 | case float64: |
| 177 | resp.Value = &gstring.GetSetResponse_Float64Value{Float64Value: v} |
| 178 | case bool: |
| 179 | resp.Value = &gstring.GetSetResponse_BoolValue{BoolValue: v} |
| 180 | case []byte: |
| 181 | resp.Value = &gstring.GetSetResponse_BytesValue{BytesValue: v} |
| 182 | } |
| 183 | |
| 184 | return resp, nil |
| 185 | } |
| 186 | |
| 187 | func (s *str) Append(ctx context.Context, req *gstring.AppendRequest) (*gstring.AppendResponse, error) { |
| 188 | err := s.dbs.Append(req.Key, req.Value, req.Expire*1000) |