IncrBy increments the integer value of a key by the given amount
(key string, amount int, ttl int64)
| 222 | |
| 223 | // IncrBy increments the integer value of a key by the given amount |
| 224 | func (s *StringStructure) IncrBy(key string, amount int, ttl int64) error { |
| 225 | // Get the old value |
| 226 | oldValue, err := s.Get(key) |
| 227 | if err != nil { |
| 228 | return err |
| 229 | } |
| 230 | |
| 231 | // Convert the old value to an integer |
| 232 | intValue, err := convertToInt(oldValue) |
| 233 | if err != nil { |
| 234 | return err |
| 235 | } |
| 236 | |
| 237 | newIntValue := intValue + amount |
| 238 | |
| 239 | newValue := strconv.Itoa(newIntValue) |
| 240 | |
| 241 | return s.Set(key, newValue, ttl) |
| 242 | } |
| 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 { |
nothing calls this directly
no test coverage detected