Skip to content

Commit

Permalink
make go 1.17 the minimum version
Browse files Browse the repository at this point in the history
There are too many small workarounds.
  • Loading branch information
alicebob committed Mar 23, 2024
1 parent 9ac631e commit 4bfd049
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.14', '1.20', '1.21', '1.22' ]
go: [ '1.17', '1.20', '1.21', '1.22' ]
name: Go ${{ matrix.go }}
steps:
- uses: actions/checkout@v4
Expand Down
5 changes: 1 addition & 4 deletions cmd_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ func inSeconds(t time.Time) int {
}

func inMilliSeconds(t time.Time) int {
// Time.UnixMilli() was added in go 1.17
// return int(t.UnixNano() / 1000000) is limited to dates between year 1678 and 2262
// by using following calculation we extend this time without too much complexity
return int(t.Unix())*1000 + t.Nanosecond()/1000000
return int(t.UnixMilli())
}

// commandsGeneric handles EXPIRE, TTL, PERSIST, &c.
Expand Down
7 changes: 1 addition & 6 deletions cmd_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,7 @@ func (m *Miniredis) cmdXclaim(c *server.Peer, cmd string, args []string) {
c.WriteError("ERR Invalid TIME option argument for XCLAIM")
return
}
opts.newLastDelivery = unixMilli(timeMs)
opts.newLastDelivery = time.UnixMilli(timeMs)
args = args[2:]
case "RETRYCOUNT":
retryCount, err := strconv.Atoi(args[1])
Expand Down Expand Up @@ -1806,8 +1806,3 @@ func parseBlock(cmd string, args []string, block *bool, timeout *time.Duration)
(*timeout) = time.Millisecond * time.Duration(ms)
return nil
}

// taken from Go's time package. Can be dropped if miniredis supports >= 1.17
func unixMilli(msec int64) time.Time {
return time.Unix(msec/1e3, (msec%1e3)*1e6)
}
12 changes: 3 additions & 9 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@ package miniredis
import (
"errors"
"fmt"
"math"
"math/big"
"sort"
"strconv"
"time"
)

const (
intSize = 32 << (^uint(0) >> 63) // 32 or 64

maxInt = 1<<(intSize-1) - 1 // [math.MaxInt] was added in go 1.17
minInt = -1 << (intSize - 1) // [math.MinInt] was added in go 1.17
)

var (
errInvalidEntryID = errors.New("stream ID is invalid")
)
Expand Down Expand Up @@ -189,11 +183,11 @@ func (db *RedisDB) stringIncr(k string, delta int) (int, error) {
}

if delta > 0 {
if maxInt-delta < v {
if math.MaxInt-delta < v {
return 0, ErrIntValueOverflowError
}
} else {
if minInt-delta > v {
if math.MinInt-delta > v {
return 0, ErrIntValueOverflowError
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ require (
github.com/yuin/gopher-lua v1.1.1
)

go 1.14
go 1.17

0 comments on commit 4bfd049

Please sign in to comment.