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)
| 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 |
| 69 | func (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 |
| 90 | func (s *String) Len() (int, error) { |