LRange returns the specified elements of the list stored in the bucket at given bucket,key, start and end. The offsets start and stop are zero-based indexes 0 being the first element of the list (the head of the list), 1 being the next element and so on. Start and end can also be negative numbers in
(bucket string, key []byte, start, end int)
| 274 | // Start and end can also be negative numbers indicating offsets from the end of the list, |
| 275 | // where -1 is the last element of the list, -2 the penultimate element and so on. |
| 276 | func (tx *Tx) LRange(bucket string, key []byte, start, end int) ([][]byte, error) { |
| 277 | if err := tx.checkTxIsClosed(); err != nil { |
| 278 | return nil, err |
| 279 | } |
| 280 | |
| 281 | b, err := tx.db.bucketMgr.GetBucket(DataStructureList, bucket) |
| 282 | if err != nil { |
| 283 | return nil, err |
| 284 | } |
| 285 | var ( |
| 286 | bucketId = b.Id |
| 287 | l *data.List |
| 288 | exist bool |
| 289 | ) |
| 290 | |
| 291 | if l, exist = tx.db.Index.List.exist(bucketId); !exist { |
| 292 | return nil, ErrBucket |
| 293 | } |
| 294 | if tx.CheckExpire(bucket, key) { |
| 295 | return nil, ErrListNotFound |
| 296 | } |
| 297 | |
| 298 | records, err := l.LRange(string(key), start, end) |
| 299 | if err != nil { |
| 300 | return nil, err |
| 301 | } |
| 302 | |
| 303 | values := make([][]byte, len(records)) |
| 304 | |
| 305 | for i, r := range records { |
| 306 | value, err := tx.db.getValueByRecord(r) |
| 307 | if err != nil { |
| 308 | return nil, err |
| 309 | } |
| 310 | values[i] = value |
| 311 | } |
| 312 | |
| 313 | return values, nil |
| 314 | } |
| 315 | |
| 316 | // LRem removes the first count occurrences of elements equal to value from the list stored in the bucket at given bucket,key,count. |
| 317 | // The count argument influences the operation in the following ways: |