Skip to content

Commit

Permalink
perf: apply fieldalignment
Browse files Browse the repository at this point in the history
  • Loading branch information
rueian committed Dec 4, 2022
1 parent 0e02e52 commit d3b3668
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 222 deletions.
8 changes: 4 additions & 4 deletions lru.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ type cache interface {
}

type entry struct {
err error
ch chan struct{}
kc *keyCache
cmd string
val RedisMessage
err error
size int
}

Expand All @@ -53,11 +53,11 @@ func (e *entry) Wait(ctx context.Context) (RedisMessage, error) {
}

type keyCache struct {
hits uint64
miss uint64
ttl time.Time
cache map[string]*list.Element
key string
ttl time.Time
hits uint64
miss uint64
}

var _ cache = (*lru)(nil)
Expand Down
6 changes: 3 additions & 3 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,11 @@ func (r RedisResult) IsCacheHit() bool {

// RedisMessage is a redis response message, it may be a nil response
type RedisMessage struct {
typ byte
attrs *RedisMessage
string string
values []RedisMessage
attrs *RedisMessage
integer int64
typ byte
}

// IsNil check if message is a redis nil response
Expand Down Expand Up @@ -532,8 +532,8 @@ func (m *RedisMessage) AsFloatSlice() ([]float64, error) {

// XRangeEntry is the element type of both XRANGE and XREVRANGE command response array
type XRangeEntry struct {
ID string
FieldValues map[string]string
ID string
}

// AsXRangeEntry check if message is a redis array/set response of length 2, and convert to XRangeEntry
Expand Down
4 changes: 2 additions & 2 deletions mock/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ func RedisMap(kv map[string]rueidis.RedisMessage) rueidis.RedisMessage {
}

type message struct {
typ byte
attrs *rueidis.RedisMessage
string string
values []rueidis.RedisMessage
attrs *rueidis.RedisMessage
integer int64
typ byte
}
type result struct {
err error
Expand Down
6 changes: 3 additions & 3 deletions mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ var _ conn = (*mux)(nil)
type mux struct {
init wire
dead wire
wire []atomic.Value
sc []*singleconnect
mu []sync.Mutex
pool *pool
wireFn wireFn
dst string
wire []atomic.Value
sc []*singleconnect
mu []sync.Mutex
}

func makeMux(dst string, option *ClientOption, dialFn dialFn) *mux {
Expand Down
2 changes: 1 addition & 1 deletion om/cursor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (

type Book struct {
Key string `json:"key" redis:",key"`
Loc string `json:"loc" redis:",loc"`
Ver int64 `json:"ver" redis:",ver"`
ID int64 `json:"id" redis:",id"`
Count int64 `json:"count" redis:",count"`
Loc string `json:"loc" redis:",loc"`
}

func TestAggregateCursor(t *testing.T) {
Expand Down
52 changes: 24 additions & 28 deletions pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,31 @@ type wire interface {
var _ wire = (*pipe)(nil)

type pipe struct {
waits int32
state int32
version int32
blcksig int32
timeout time.Duration
pinggap time.Duration

r *bufio.Reader
w *bufio.Writer

conn net.Conn
cache cache
queue queue
once sync.Once

info map[string]RedisMessage
nsubs *subs
psubs *subs
ssubs *subs
pshks atomic.Value
clhks atomic.Value
error atomic.Value

conn net.Conn
error atomic.Value
clhks atomic.Value
pshks atomic.Value
queue queue
cache cache
r *bufio.Reader
w *bufio.Writer
onInvalidations func([]RedisMessage)

r2psFn func() (p *pipe, err error)
r2mu sync.Mutex
r2pipe *pipe
r2ps bool
r2psFn func() (p *pipe, err error)
r2pipe *pipe
ssubs *subs
nsubs *subs
psubs *subs
info map[string]RedisMessage
timeout time.Duration
pinggap time.Duration
once sync.Once
r2mu sync.Mutex
version int32
_ [12]int32
blcksig int32
state int32
waits int32
r2ps bool
}

func newPipe(connFn func() (net.Conn, error), option *ClientOption) (p *pipe, err error) {
Expand Down
4 changes: 2 additions & 2 deletions pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ func newSubs() *subs {
}

type subs struct {
mu sync.RWMutex
chs map[string]chs
sub map[uint64]*sub
cnt uint64
mu sync.RWMutex
}

type chs struct {
sub map[uint64]*sub
}

type sub struct {
cs []string
ch chan PubSubMessage
cs []string
}

func (s *subs) Publish(channel string, msg PubSubMessage) {
Expand Down
3 changes: 2 additions & 1 deletion ring.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ func newRing(factor int) *ring {
}

type ring struct {
store []node // store's size must be 2^N to work with the mask
_ [5]uint64
write uint64
_ [7]uint64
read1 uint64
read2 uint64
mask uint64
store []node // store's size must be 2^N to work with the mask
}

type node struct {
Expand Down
14 changes: 8 additions & 6 deletions rueidis.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ type ClientOption struct {
Dialer net.Dialer
TLSConfig *tls.Config

// OnInvalidations is a callback function in case of client-side caching invalidation received.
// Note that this function must be fast, otherwise other redis messages will be blocked.
OnInvalidations func([]RedisMessage)

// Sentinel options, including MasterSet and Auth options
Sentinel SentinelOption

Expand All @@ -70,6 +74,10 @@ type ClientOption struct {
// If ClientOption.Sentinel.MasterSet is set, then InitAddress will be used to connect sentinels
InitAddress []string

// ClientTrackingOptions will be appended to CLIENT TRACKING ON command when the connection is established.
// The default is []string{"OPTIN"}
ClientTrackingOptions []string

SelectDB int

// CacheSizeEachConn is redis client side cache size that bind to each TCP connection to a single redis instance.
Expand Down Expand Up @@ -108,12 +116,6 @@ type ClientOption struct {
DisableRetry bool
// DisableCache falls back Client.DoCache/Client.DoMultiCache to Client.Do/Client.DoMulti
DisableCache bool
// OnInvalidations is a callback function in case of client-side caching invalidation received.
// Note that this function must be fast, otherwise other redis messages will be blocked.
OnInvalidations func([]RedisMessage)
// ClientTrackingOptions will be appended to CLIENT TRACKING ON command when the connection is established.
// The default is []string{"OPTIN"}
ClientTrackingOptions []string
}

// SentinelOption contains MasterSet,
Expand Down
68 changes: 34 additions & 34 deletions rueidiscompat/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5668,29 +5668,29 @@ func testAdapter(resp3 bool) {
Describe("marshaling/unmarshaling", func() {
type convTest struct {
value interface{}
wanted string
dest interface{}
wanted string
}

convTests := []convTest{
// TODO
//{nil, "", nil},
{"hello", "hello", new(string)},
{[]byte("hello"), "hello", new([]byte)},
{int(1), "1", new(int)},
{int8(1), "1", new(int8)},
{int16(1), "1", new(int16)},
{int32(1), "1", new(int32)},
{int64(1), "1", new(int64)},
{uint(1), "1", new(uint)},
{uint8(1), "1", new(uint8)},
{uint16(1), "1", new(uint16)},
{uint32(1), "1", new(uint32)},
{uint64(1), "1", new(uint64)},
{float32(1.0), "1", new(float32)},
{float64(1.0), "1", new(float64)},
{true, "1", new(bool)},
{false, "0", new(bool)},
{"hello", new(string), "hello"},
{[]byte("hello"), new([]byte), "hello"},
{int(1), new(int), "1"},
{int8(1), new(int8), "1"},
{int16(1), new(int16), "1"},
{int32(1), new(int32), "1"},
{int64(1), new(int64), "1"},
{uint(1), new(uint), "1"},
{uint8(1), new(uint8), "1"},
{uint16(1), new(uint16), "1"},
{uint32(1), new(uint32), "1"},
{uint64(1), new(uint64), "1"},
{float32(1.0), new(float32), "1"},
{float64(1.0), new(float64), "1"},
{true, new(bool), "1"},
{false, new(bool), "0"},
}

It("should convert to string", func() {
Expand Down Expand Up @@ -7271,29 +7271,29 @@ func testAdapterCache(resp3 bool) {
Describe("marshaling/unmarshaling", func() {
type convTest struct {
value interface{}
wanted string
dest interface{}
wanted string
}

convTests := []convTest{
// TODO
//{nil, "", nil},
{"hello", "hello", new(string)},
{[]byte("hello"), "hello", new([]byte)},
{int(1), "1", new(int)},
{int8(1), "1", new(int8)},
{int16(1), "1", new(int16)},
{int32(1), "1", new(int32)},
{int64(1), "1", new(int64)},
{uint(1), "1", new(uint)},
{uint8(1), "1", new(uint8)},
{uint16(1), "1", new(uint16)},
{uint32(1), "1", new(uint32)},
{uint64(1), "1", new(uint64)},
{float32(1.0), "1", new(float32)},
{float64(1.0), "1", new(float64)},
{true, "1", new(bool)},
{false, "0", new(bool)},
{"hello", new(string), "hello"},
{[]byte("hello"), new([]byte), "hello"},
{int(1), new(int), "1"},
{int8(1), new(int8), "1"},
{int16(1), new(int16), "1"},
{int32(1), new(int32), "1"},
{int64(1), new(int64), "1"},
{uint(1), new(uint), "1"},
{uint8(1), new(uint8), "1"},
{uint16(1), new(uint16), "1"},
{uint32(1), new(uint32), "1"},
{uint64(1), new(uint64), "1"},
{float32(1.0), new(float32), "1"},
{float64(1.0), new(float64), "1"},
{true, new(bool), "1"},
{false, new(bool), "0"},
}

It("should convert to string", func() {
Expand Down
Loading

0 comments on commit d3b3668

Please sign in to comment.