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

Method getListFromDB

structure/list.go:574–609  ·  view source on GitHub ↗

getListFromDB retrieves data from the database. When isKeyCanNotExist is true, it returns an empty slice if the key doesn't exist instead of an error.

(key string, isKeyCanNotExist bool)

Source from the content-addressed store, hash-verified

572
573// getListFromDB retrieves data from the database. When isKeyCanNotExist is true, it returns an empty slice if the key doesn't exist instead of an error.
574func (l *ListStructure) getListFromDB(key string, isKeyCanNotExist bool) (*list, int64, error) {
575 if isKeyCanNotExist {
576 // Get data corresponding to the key from the database
577 dbData, err := l.db.Get([]byte(key))
578
579 // Since the key might not exist, we need to handle ErrKeyNotFound separately as it is a valid case
580 if err != nil && err != _const.ErrKeyNotFound {
581 return nil, 0, err
582 }
583
584 // Deserialize the data into a DecodedList
585 decodedList, err := l.decodeList(dbData)
586 if err != nil {
587 if len(dbData) != 0 {
588 return nil, 0, err
589 } else {
590 decodedList = &DecodedList{List: &list{nil, 0}, Expiration: 0}
591 }
592 }
593 return decodedList.List, decodedList.Expiration, nil
594 } else {
595 // Get data corresponding to the key from the database
596 dbData, err := l.db.Get([]byte(key))
597 if err != nil {
598 return nil, 0, err
599 }
600
601 // Deserialize the data into a DecodedList
602 decodedList, err := l.decodeList(dbData)
603 if err != nil {
604 return nil, 0, err
605 }
606
607 return decodedList.List, decodedList.Expiration, nil
608 }
609}
610
611// setListToDB stores the data into the database.
612func (l *ListStructure) setListToDB(key string, lst *list, ttl time.Duration) error {

Callers 15

LPushMethod · 0.95
LPushsMethod · 0.95
RPushMethod · 0.95
RPushsMethod · 0.95
LPopMethod · 0.95
RPopMethod · 0.95
LRangeMethod · 0.95
LLenMethod · 0.95
LRemMethod · 0.95
LSetMethod · 0.95
LTrimMethod · 0.95
LIndexMethod · 0.95

Calls 2

decodeListMethod · 0.95
GetMethod · 0.65

Tested by

no test coverage detected