MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / LSet

Method LSet

structure/list.go:331–355  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

329// If the index is out of range, an error is returned.
330// If the list is empty, an error is returned.
331func (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.

Callers

nothing calls this directly

Calls 2

getListFromDBMethod · 0.95
setListToDBMethod · 0.95

Tested by

no test coverage detected