IncrByFloat increments the float value of a key by the given amount
(key string, amount float64, ttl int64)
| 243 | |
| 244 | // IncrByFloat increments the float value of a key by the given amount |
| 245 | func (s *StringStructure) IncrByFloat(key string, amount float64, ttl int64) error { |
| 246 | // Get the old value |
| 247 | oldValue, err := s.Get(key) |
| 248 | if err != nil { |
| 249 | return err |
| 250 | } |
| 251 | |
| 252 | // Convert the old value to a byte slice |
| 253 | floatValue, err := convertToFloat(oldValue) |
| 254 | if err != nil { |
| 255 | return err |
| 256 | } |
| 257 | |
| 258 | // Increment the float value |
| 259 | newFloatValue := floatValue + amount |
| 260 | |
| 261 | // Convert the new float value to a byte slice |
| 262 | newValue := strconv.FormatFloat(newFloatValue, 'f', -1, 64) |
| 263 | |
| 264 | // Set the value |
| 265 | return s.Set(key, newValue, ttl) |
| 266 | } |
| 267 | |
| 268 | // Decr decrements the integer value of a key by 1 |
| 269 | func (s *StringStructure) Decr(key string, ttl int64) error { |
nothing calls this directly
no test coverage detected