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)
| 46 | // If the key is not expired, it will be updated |
| 47 | // func (s *StringStructure) Set(key, value []byte, ttl time.Duration) error { |
| 48 | func (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 |
no test coverage detected