ZAdds adds a value with its given score and member to a sorted set (ZSet), associated with the provided key. It is a method on the ZSetStructure type. Parameters: values: ...ZSetValue multiple values of ZSetValue.
(key string, vals ...ZSetValue)
| 494 | // |
| 495 | // values: ...ZSetValue multiple values of ZSetValue. |
| 496 | func (zs *ZSetStructure) ZAdds(key string, vals ...ZSetValue) error { |
| 497 | if err := checkKey(key); err != nil { |
| 498 | return err |
| 499 | } |
| 500 | zSet, err := zs.getOrCreateZSet(key) |
| 501 | if err != nil { |
| 502 | return fmt.Errorf("failed to get or create ZSet from DB with key '%v': %w", key, err) |
| 503 | } |
| 504 | |
| 505 | for _, val := range vals { |
| 506 | // if values didn't change, do nothing |
| 507 | if zs.valuesDidntChange(zSet, val.score, val.member, val.value) { |
| 508 | continue |
| 509 | } |
| 510 | if err := zs.updateZSet(zSet, key, val.score, val.member, val.value); err != nil { |
| 511 | return fmt.Errorf("failed to set ZSet to DB with key '%v': %w", key, err) |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | return zs.setZSetToDB(stringToBytesWithKey(key), zSet) |
| 516 | } |
| 517 | |
| 518 | // Keys returns all keys of the ZSetStructure. |
| 519 | // |
no test coverage detected