getExpireFromDB retrieves data from the database.
(key string, isKeyCanNotExist bool)
| 138 | |
| 139 | // getExpireFromDB retrieves data from the database. |
| 140 | func (ek *ExpireStructure) getExpireFromDB(key string, isKeyCanNotExist bool) (int64, error) { |
| 141 | // Get data corresponding to the key from the database |
| 142 | dbData, err := ek.db.Get([]byte(key)) |
| 143 | |
| 144 | // Since the key might not exist, we need to handle ErrKeyNotFound separately as it is a valid case |
| 145 | if err != nil && err != _const.ErrKeyNotFound { |
| 146 | return 0, err |
| 147 | } |
| 148 | |
| 149 | // Deserialize the data into a list |
| 150 | deadtime, err := ek.decodeExpire(dbData) |
| 151 | if err != nil { |
| 152 | if len(dbData) != 0 { |
| 153 | return 0, err |
| 154 | } else { |
| 155 | deadtime = -2 |
| 156 | } |
| 157 | } |
| 158 | return deadtime, nil |
| 159 | } |
| 160 | |
| 161 | // setExpireToDB stores the data into the database. |
| 162 | func (ek *ExpireStructure) setExpireToDB(key string, deadtime int64) error { |
no test coverage detected