MCPcopy Index your code
hub / github.com/ByteStorage/FlyDB / getSetFromDB

Method getSetFromDB

structure/set.go:375–401  ·  view source on GitHub ↗

GetSetFromDB retrieves a set from database given a key. If createIfNotExist is true, a new set will be created if the key is not found. It returns the file sets and any write error encountered.

(key []byte, createIfNotExist bool)

Source from the content-addressed store, hash-verified

373// GetSetFromDB retrieves a set from database given a key. If createIfNotExist is true,
374// a new set will be created if the key is not found. It returns the file sets and any write error encountered.
375func (s *SetStructure) getSetFromDB(key []byte, createIfNotExist bool) (*FSets, int64, error) {
376 if s.db == nil {
377 return nil, 0, ErrSetNotInitialized
378 }
379 var zSetValueWithTTL FSetWithTTL
380 dbData, err := s.db.Get(key)
381
382 // If key is not found, return nil for both; otherwise return the error.
383 if err != nil {
384 if errors.Is(err, _const.ErrKeyNotFound) && createIfNotExist {
385 return &FSets{}, 0, nil
386 }
387 return nil, 0, err
388 } else {
389 err = encoding.NewMessagePackDecoder(dbData).Decode(&zSetValueWithTTL) // Decode the value along with TTL
390 if err != nil {
391 return nil, 0, err
392 }
393
394 expiration := zSetValueWithTTL.TTL
395 if expiration != 0 && expiration < time.Now().UnixNano() {
396 return nil, -1, _const.ErrKeyIsExpired
397 }
398
399 return zSetValueWithTTL.ZSet, zSetValueWithTTL.TTL, nil // Return the zSetValue and TTL
400 }
401}
402
403type FSetWithTTL struct {
404 ZSet *FSets

Callers 3

checkAndGetSetMethod · 0.95
existsMethod · 0.95
TTLMethod · 0.95

Calls 3

NewMessagePackDecoderFunction · 0.92
GetMethod · 0.65
DecodeMethod · 0.45

Tested by

no test coverage detected