Incr increments the integer value by the given amount the old value must be integer
(delta int64)
| 152 | // Incr increments the integer value by the given amount |
| 153 | // the old value must be integer |
| 154 | func (s *String) Incr(delta int64) (int64, error) { |
| 155 | value := s.Meta.Value |
| 156 | if value != nil { |
| 157 | v, err := strconv.ParseInt(string(value), 10, 64) |
| 158 | if err != nil { |
| 159 | return 0, ErrInteger |
| 160 | } |
| 161 | delta = v + delta |
| 162 | } |
| 163 | |
| 164 | vs := strconv.FormatInt(delta, 10) |
| 165 | if err := s.Set([]byte(vs)); err != nil { |
| 166 | return 0, err |
| 167 | } |
| 168 | return delta, nil |
| 169 | |
| 170 | } |
| 171 | |
| 172 | // Incrf increments the float value by the given amount |
| 173 | // the old value must be float |