| 742 | ttl := keptTTL |
| 743 | switch { |
| 744 | case exSeconds > 0: |
| 745 | ttl = exSeconds |
| 746 | case pxMilliseconds > 0: |
| 747 | ttl = expireSecondsFromMillis(pxMilliseconds) |
| 748 | } |
| 749 | |
| 750 | // Validate the expiry before writing: a rejected expiration must not leave the |
| 751 | // value stored without a TTL while the client is told the command failed. |
| 752 | now := m.Now().Unix() |
| 753 | if ttl > 0 && ttl > math.MaxInt64-now { |
| 754 | return nil, fmt.Errorf("ERR invalid expire time in 'set' command") |
| 755 | } |
| 756 | |
| 757 | if err := ldb.Set(key, value); err != nil { |
| 758 | return nil, err |
| 759 | } |
| 760 | |
| 761 | if ttl > 0 { |
| 762 | if _, err := ldb.ExpireAt(key, now+ttl); err != nil { |
| 763 | return nil, err |
| 764 | } |
| 765 | } |