LSet sets the value of an element in a list associated with a key based on the index. If the index is out of range, an error is returned. If the list is empty, an error is returned.
(key string, index int, value interface{}, ttl int64)
| 329 | // If the index is out of range, an error is returned. |
| 330 | // If the list is empty, an error is returned. |
| 331 | func (l *ListStructure) LSet(key string, index int, value interface{}, ttl int64) error { |
| 332 | // Get the list |
| 333 | lst, _, err := l.getListFromDB(key, false) |
| 334 | if err != nil { |
| 335 | return err |
| 336 | } |
| 337 | var expirationTime time.Duration |
| 338 | // Check if the index is out of range |
| 339 | if index < 0 || index >= lst.Length { |
| 340 | return ErrIndexOutOfRange |
| 341 | } |
| 342 | |
| 343 | nowNode := lst.Head |
| 344 | |
| 345 | for i := 0; i < index; i++ { |
| 346 | nowNode = nowNode.Next |
| 347 | } |
| 348 | |
| 349 | nowNode.Value = value |
| 350 | if ttl > 0 { |
| 351 | expirationTime = time.Duration(ttl) * time.Second |
| 352 | } |
| 353 | // Store in the database |
| 354 | return l.setListToDB(key, lst, expirationTime) |
| 355 | } |
| 356 | |
| 357 | // LTrim retains a range of elements in a list associated with a key. |
| 358 | // The range is inclusive, including both the start and stop indices. |
nothing calls this directly
no test coverage detected