MCPcopy Create free account
hub / github.com/distributedio/titan / Set

Method Set

db/string.go:69–87  ·  view source on GitHub ↗

Set set the string value of a key the num of expire slice is not zero and expire[0] is not zero ,the key add exprie queue otherwise the delete expire queue

(val []byte, expire ...int64)

Source from the content-addressed store, hash-verified

67// the num of expire slice is not zero and expire[0] is not zero ,the key add exprie queue
68// otherwise the delete expire queue
69func (s *String) Set(val []byte, expire ...int64) error {
70 timestamp := Now()
71 mkey := MetaKey(s.txn.db, s.key)
72 if len(expire) != 0 && expire[0] > 0 {
73 old := s.Meta.ExpireAt
74 s.Meta.ExpireAt = timestamp + expire[0]
75 if err := expireAt(s.txn.t, mkey, s.Meta.ID, s.Meta.Type, old, s.Meta.ExpireAt); err != nil {
76 return err
77 }
78 } else {
79 //maybe key is not expire queue,so unExpireAt will return err,but it is not relationship
80 if err := unExpireAt(s.txn.t, mkey, s.Meta.ExpireAt); err != nil {
81 zap.L().Error("add expire failed", zap.String("key", string(mkey)))
82 }
83 s.Meta.ExpireAt = 0
84 }
85 s.Meta.Value = val
86 return s.txn.t.Set(mkey, s.encode())
87}
88
89// Len value len
90func (s *String) Len() (int, error) {

Callers 9

SetFunction · 0.95
SetExFunction · 0.95
PSetExFunction · 0.95
GetSetMethod · 0.95
SetRangeMethod · 0.95
IncrMethod · 0.95
IncrfMethod · 0.95
SetBitMethod · 0.95
SetValFunction · 0.95

Calls 8

encodeMethod · 0.95
NowFunction · 0.85
MetaKeyFunction · 0.85
expireAtFunction · 0.85
unExpireAtFunction · 0.85
ErrorMethod · 0.65
SetMethod · 0.65
StringMethod · 0.45

Tested by 1

SetValFunction · 0.76