LPop returns and removes the leftmost value of a list associated with a key. If the key does not exist, an error is returned. If the list is empty, an error is returned.
(key string)
| 171 | // If the key does not exist, an error is returned. |
| 172 | // If the list is empty, an error is returned. |
| 173 | func (l *ListStructure) LPop(key string) (interface{}, error) { |
| 174 | // Get the list |
| 175 | lst, _, err := l.getListFromDB(key, false) |
| 176 | if err != nil { |
| 177 | return nil, err |
| 178 | } |
| 179 | // Return error if the list is empty |
| 180 | if lst.Length == 0 { |
| 181 | return nil, ErrListEmpty |
| 182 | } |
| 183 | |
| 184 | popValue := lst.Head.Value |
| 185 | lst.Head = lst.Head.Next |
| 186 | lst.Length-- |
| 187 | |
| 188 | // Store in the database |
| 189 | return popValue, l.setListToDB(key, lst, 0) |
| 190 | } |
| 191 | |
| 192 | // RPop returns and removes the rightmost value of a list associated with a key. |
| 193 | // If the key does not exist, an error is returned. |
nothing calls this directly
no test coverage detected