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

Method findHashMeta

structure/hash.go:1362–1402  ·  view source on GitHub ↗

findHashMeta finds the hash metadata by the given key.

(key string, dataType DataStructure)

Source from the content-addressed store, hash-verified

1360
1361// findHashMeta finds the hash metadata by the given key.
1362func (hs *HashStructure) findHashMeta(key string, dataType DataStructure) (*HashMetadata, error) {
1363 // Convert the parameters to bytes
1364 k := stringToBytesWithKey(key)
1365
1366 // Find the hash metadata by the given key
1367 meta, err := hs.db.Get(k)
1368 if err != nil && err != _const.ErrKeyNotFound {
1369 return nil, err
1370 }
1371
1372 var hashMeta *HashMetadata
1373 var exist = true
1374 // If the hash metadata is not found, create a new one
1375 if err == _const.ErrKeyNotFound {
1376 exist = false
1377 } else {
1378 // Decode the hash metadata
1379 hashMeta = decodeHashMeta(meta)
1380
1381 // Check the data type
1382 if hashMeta.dataType != dataType {
1383 return nil, ErrInvalidType
1384 }
1385
1386 }
1387
1388 // If the hash metadata is not found, create a new one
1389 if !exist {
1390 hashMeta = &HashMetadata{
1391 dataType: dataType,
1392 dataSize: 0,
1393 expire: 0,
1394 version: time.Now().UnixNano(),
1395 counter: 0,
1396 createdTime: time.Now().UnixNano(),
1397 lastUpdatedTime: time.Now().UnixNano(),
1398 }
1399 }
1400
1401 return hashMeta, nil
1402}
1403
1404func (hs *HashStructure) Stop() error {
1405 err := hs.db.Close()

Callers 15

HSetMethod · 0.95
HGetMethod · 0.95
HMGetMethod · 0.95
HDelMethod · 0.95
HDelAllMethod · 0.95
HExpireMethod · 0.95
HExistsMethod · 0.95
HLenMethod · 0.95
HUpdateMethod · 0.95
HIncrByMethod · 0.95
HIncrByFloatMethod · 0.95
HDecrByMethod · 0.95

Calls 3

stringToBytesWithKeyFunction · 0.85
decodeHashMetaFunction · 0.85
GetMethod · 0.65

Tested by

no test coverage detected