Setex is rewritten as setexat to avoid the exception of raft log playback
(m uhaha.Machine, args []string)
| 673 | } |
| 674 | |
| 675 | // cmdSET implements the Redis SET command. |
| 676 | // Syntax: SET key value [EX seconds | PX milliseconds | NX | XX | KEEPTTL] |
| 677 | // EXAT/PXAT are not implemented; any other option is a syntax error. |
| 678 | func cmdSET(m uhaha.Machine, args []string) (interface{}, error) { |
| 679 | if len(args) < 3 { |
| 680 | return nil, uhaha.ErrWrongNumArgs |
| 681 | } |
| 682 | |
| 683 | key := []byte(args[1]) |
| 684 | value := []byte(args[2]) |
| 685 | |
| 686 | var exSeconds, pxMilliseconds int64 |
| 687 | var nx, xx, keepttl bool |
| 688 | |
| 689 | for i := 3; i < len(args); i++ { |
| 690 | switch strings.ToUpper(args[i]) { |
| 691 | case "NX": |
| 692 | nx = true |
| 693 | case "XX": |
| 694 | xx = true |
| 695 | case "KEEPTTL": |
| 696 | keepttl = true |
| 697 | case "EX", "PX": |
| 698 | if i+1 >= len(args) { |
| 699 | return nil, uhaha.ErrWrongNumArgs |
| 700 | } |
| 701 | n, err := ledis.StrInt64([]byte(args[i+1]), nil) |
| 702 | if err != nil { |
| 703 | return nil, fmt.Errorf("ERR value is not an integer or out of range") |
| 704 | } |
| 705 | if n <= 0 { |
nothing calls this directly
no outgoing calls
no test coverage detected