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

Method Set

structure/string.go:48–71  ·  view source on GitHub ↗

Set sets the value of a key If the key does not exist, it will be created If the key exists, it will be overwritten If the key is expired, it will be deleted If the key is not expired, it will be updated func (s *StringStructure) Set(key, value []byte, ttl time.Duration) error {

(k string, v interface{}, ttl int64)

Source from the content-addressed store, hash-verified

46// If the key is not expired, it will be updated
47// func (s *StringStructure) Set(key, value []byte, ttl time.Duration) error {
48func (s *StringStructure) Set(k string, v interface{}, ttl int64) error {
49 key := stringToBytesWithKey(k)
50 value, err, valueType := interfaceToBytes(v)
51
52 if err != nil {
53 return err
54 }
55
56 // Set the value type
57 s.valueType = valueType
58
59 if value == nil {
60 return nil
61 }
62
63 // Encode the value
64 encValue, err := encodeStringValue(value, integerToDuration(ttl))
65 if err != nil {
66 return err
67 }
68
69 // Set the value
70 return s.db.Put(key, encValue)
71}
72
73// Get gets the value of a key
74// If the key does not exist, it will return nil

Callers 11

GetSetMethod · 0.95
AppendMethod · 0.95
IncrMethod · 0.95
IncrByMethod · 0.95
IncrByFloatMethod · 0.95
DecrMethod · 0.95
DecrByMethod · 0.95
ExpireMethod · 0.95
PersistMethod · 0.95
MSetMethod · 0.95
MSetNXMethod · 0.95

Calls 5

stringToBytesWithKeyFunction · 0.85
interfaceToBytesFunction · 0.85
encodeStringValueFunction · 0.85
integerToDurationFunction · 0.85
PutMethod · 0.65

Tested by

no test coverage detected