LPush inserts the values at the head of the list stored in the bucket at given bucket,key and values.
(bucket string, key []byte, values ...[]byte)
| 146 | |
| 147 | // LPush inserts the values at the head of the list stored in the bucket at given bucket,key and values. |
| 148 | func (tx *Tx) LPush(bucket string, key []byte, values ...[]byte) error { |
| 149 | if err := tx.isKeyValid(bucket, key); err != nil { |
| 150 | return err |
| 151 | } |
| 152 | |
| 153 | if strings.Contains(string(key), SeparatorForListKey) { |
| 154 | return ErrSeparatorForListKey |
| 155 | } |
| 156 | |
| 157 | for _, value := range values { |
| 158 | l, err := tx.getListWithDefault(bucket) |
| 159 | if err != nil { |
| 160 | return err |
| 161 | } |
| 162 | newKey := l.GeneratePushKey(key, true) |
| 163 | err = tx.push(bucket, newKey, DataLPushFlag, value) |
| 164 | if err != nil { |
| 165 | return err |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | return nil |
| 170 | } |
| 171 | |
| 172 | func (tx *Tx) isKeyValid(bucket string, key []byte) error { |
| 173 | if err := tx.checkTxIsClosed(); err != nil { |