Skip to content

Commit 8d1c502

Browse files
committed
docs: fix comments
Signed-off-by: Rueian <[email protected]>
1 parent a2b28cf commit 8d1c502

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+259
-258
lines changed

binary.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"unsafe"
88
)
99

10-
// BinaryString convert the provided []byte into a string without copy. It does what strings.Builder.String() does.
11-
// Redis Strings are binary safe, this means that it is safe to store any []byte into Redis directly.
10+
// BinaryString convert the provided []byte into a string without a copy. It does what strings.Builder.String() does.
11+
// Redis Strings are binary safe; this means that it is safe to store any []byte into Redis directly.
1212
// Users can use this BinaryString helper to insert a []byte as the part of redis command. For example:
1313
//
1414
// client.B().Set().Key(rueidis.BinaryString([]byte{0})).Value(rueidis.BinaryString([]byte{0})).Build()

cache.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type CacheStoreOption struct {
2020
// More detailed interface requirement can be found in cache_test.go
2121
type CacheStore interface {
2222
// Flight is called when DoCache and DoMultiCache, with the requested client side ttl and the current time.
23-
// It should look up the store in single-flight manner and return one of the following three combinations:
23+
// It should look up the store in a single-flight manner and return one of the following three combinations:
2424
// Case 1: (empty RedisMessage, nil CacheEntry) <- when cache missed, and rueidis will send the request to redis.
2525
// Case 2: (empty RedisMessage, non-nil CacheEntry) <- when cache missed, and rueidis will use CacheEntry.Wait to wait for response.
2626
// Case 3: (non-empty RedisMessage, nil CacheEntry) <- when cache hit
@@ -33,15 +33,15 @@ type CacheStore interface {
3333
// It should not only deliver the error to all CacheEntry.Wait but also remove the CacheEntry from the store.
3434
Cancel(key, cmd string, err error)
3535
// Delete is called when receiving invalidation notifications from redis.
36-
// If the keys is nil then it should delete all non-pending cached entries under all keys.
37-
// If the keys is not nil then it should delete all non-pending cached entries under those keys.
36+
// If the keys are nil, then it should delete all non-pending cached entries under all keys.
37+
// If the keys are not nil, then it should delete all non-pending cached entries under those keys.
3838
Delete(keys []RedisMessage)
39-
// Close is called when connection between redis is broken.
39+
// Close is called when the connection between redis is broken.
4040
// It should flush all cached entries and deliver the error to all pending CacheEntry.Wait.
4141
Close(err error)
4242
}
4343

44-
// CacheEntry should be used to wait for single-flight response when cache missed.
44+
// CacheEntry should be used to wait for a single-flight response when cache missed.
4545
type CacheEntry interface {
4646
Wait(ctx context.Context) (RedisMessage, error)
4747
}

client.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ retry:
5959
}
6060
}
6161
}
62-
if resp.NonRedisError() == nil { // not recycle cmds if error, since cmds may be used later in pipe. consider recycle them by pipe
62+
if resp.NonRedisError() == nil { // not recycle cmds if error, since cmds may be used later in the pipe.
6363
cmds.PutCompleted(cmd)
6464
}
6565
return resp
@@ -93,7 +93,7 @@ retry:
9393
var ml []Completed
9494
recover:
9595
ml = ml[:0]
96-
var txIdx int // check transaction block, if zero then not in transaction
96+
var txIdx int // check transaction block, if zero, then not in transaction
9797
for i, resp := range resps {
9898
if resp.NonRedisError() == errConnExpired {
9999
if txIdx > 0 {
@@ -103,7 +103,7 @@ retry:
103103
}
104104
break
105105
}
106-
// if no error then check if transaction block
106+
// if no error, then check if transaction block
107107
if isMulti(multi[i]) {
108108
txIdx = i
109109
} else if isExec(multi[i]) {

cluster.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/redis/rueidis/internal/util"
1515
)
1616

17-
// ErrNoSlot indicates that there is no redis node owns the key slot.
17+
// ErrNoSlot indicates that there is no redis node owning the key slot.
1818
var ErrNoSlot = errors.New("the slot has no redis node")
1919
var ErrReplicaOnlyConflict = errors.New("ReplicaOnly conflicts with SendToReplicas option")
2020
var ErrInvalidShardsRefreshInterval = errors.New("ShardsRefreshInterval must be greater than or equal to 0")
@@ -117,7 +117,7 @@ func (c *clusterClient) init() error {
117117
if err := cc.Dial(); err == nil {
118118
c.mu.Lock()
119119
if _, ok := c.conns[addr]; ok {
120-
go cc.Close() // abort the new connection instead of closing the old one which may already been used
120+
go cc.Close() // abort the new connection instead of closing the old one, which may already been used
121121
} else {
122122
c.conns[addr] = connrole{
123123
conn: cc,
@@ -502,7 +502,7 @@ func (c *clusterClient) B() Builder {
502502
}
503503

504504
func (c *clusterClient) Do(ctx context.Context, cmd Completed) (resp RedisResult) {
505-
if resp = c.do(ctx, cmd); resp.NonRedisError() == nil { // not recycle cmds if error, since cmds may be used later in pipe. consider recycle them by pipe
505+
if resp = c.do(ctx, cmd); resp.NonRedisError() == nil { // not recycle cmds if error, since cmds may be used later in the pipe.
506506
cmds.PutCompleted(cmd)
507507
}
508508
return resp
@@ -600,7 +600,7 @@ func (c *clusterClient) _pickMulti(multi []Completed) (retries *connretry, init
600600
} else {
601601
cc = c.pslots[cmd.Slot()]
602602
}
603-
if cc == nil { // check cc == nil again in case of non-deterministic SendToReplicas.
603+
if cc == nil { // check cc == nil again in the case of non-deterministic SendToReplicas.
604604
return nil, false
605605
}
606606
re := retries.m[cc]
@@ -774,7 +774,7 @@ func (c *clusterClient) doretry(
774774
var ml []Completed
775775
recover:
776776
ml = ml[:0]
777-
var txIdx int // check transaction block, if zero then not in transaction
777+
var txIdx int // check transaction block, if zero, then not in transaction
778778
for i, resp := range resps.s {
779779
if resp.NonRedisError() == errConnExpired {
780780
if txIdx > 0 {
@@ -784,7 +784,7 @@ func (c *clusterClient) doretry(
784784
}
785785
break
786786
}
787-
// if no error then check if transaction block
787+
// if no error, then check if transaction block
788788
if isMulti(re.commands[i]) {
789789
txIdx = i
790790
} else if isExec(re.commands[i]) {
@@ -830,7 +830,7 @@ func (c *clusterClient) DoMulti(ctx context.Context, multi ...Completed) []Redis
830830
attempts := 1
831831

832832
retry:
833-
retries.RetryDelay = -1 // Assume no retry. Because client retry flag can be set to false.
833+
retries.RetryDelay = -1 // Assume no retry. Because a client retry flag can be set to false.
834834

835835
var cc1 conn
836836
var re1 *retry
@@ -1184,7 +1184,7 @@ func (c *clusterClient) DoMultiCache(ctx context.Context, multi ...CacheableTTL)
11841184
attempts := 1
11851185

11861186
retry:
1187-
retries.RetryDelay = -1 // Assume no retry. Because client retry flag can be set to false.
1187+
retries.RetryDelay = -1 // Assume no retry. Because a client retry flag can be set to false.
11881188

11891189
var cc1 conn
11901190
var re1 *retrycache

cmds.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "github.com/redis/rueidis/internal/cmds"
55
// Builder represents a command builder. It should only be created from the client.B() method.
66
type Builder = cmds.Builder
77

8-
// Incomplete represents an incomplete Redis command. It should then be completed by calling the Build().
8+
// Incomplete represents an incomplete Redis command. It should then be completed by calling Build().
99
type Incomplete = cmds.Incomplete
1010

1111
// Completed represents a completed Redis command. It should only be created from the Build() of a command builder.

helper.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
intl "github.com/redis/rueidis/internal/cmds"
99
)
1010

11-
// MGetCache is a helper that consults the client-side caches with multiple keys by grouping keys within same slot into multiple GETs
11+
// MGetCache is a helper that consults the client-side caches with multiple keys by grouping keys within the same slot into multiple GETs
1212
func MGetCache(client Client, ctx context.Context, ttl time.Duration, keys []string) (ret map[string]RedisMessage, err error) {
1313
if len(keys) == 0 {
1414
return make(map[string]RedisMessage), nil
@@ -38,7 +38,7 @@ func isCacheDisabled(client Client) bool {
3838
return false
3939
}
4040

41-
// MGet is a helper that consults the redis directly with multiple keys by grouping keys within same slot into MGET or multiple GETs
41+
// MGet is a helper that consults the redis directly with multiple keys by grouping keys within the same slot into MGET or multiple GETs
4242
func MGet(client Client, ctx context.Context, keys []string) (ret map[string]RedisMessage, err error) {
4343
if len(keys) == 0 {
4444
return make(map[string]RedisMessage), nil
@@ -57,7 +57,7 @@ func MGet(client Client, ctx context.Context, keys []string) (ret map[string]Red
5757
return doMultiGet(client, ctx, cmds.s, keys)
5858
}
5959

60-
// MSet is a helper that consults the redis directly with multiple keys by grouping keys within same slot into MSETs or multiple SETs
60+
// MSet is a helper that consults the redis directly with multiple keys by grouping keys within the same slot into MSETs or multiple SETs
6161
func MSet(client Client, ctx context.Context, kvs map[string]string) map[string]error {
6262
if len(kvs) == 0 {
6363
return make(map[string]error)
@@ -76,7 +76,7 @@ func MSet(client Client, ctx context.Context, kvs map[string]string) map[string]
7676
return doMultiSet(client, ctx, cmds.s)
7777
}
7878

79-
// MDel is a helper that consults the redis directly with multiple keys by grouping keys within same slot into DELs
79+
// MDel is a helper that consults the redis directly with multiple keys by grouping keys within the same slot into DELs
8080
func MDel(client Client, ctx context.Context, keys []string) map[string]error {
8181
if len(keys) == 0 {
8282
return make(map[string]error)
@@ -95,7 +95,7 @@ func MDel(client Client, ctx context.Context, keys []string) map[string]error {
9595
return doMultiSet(client, ctx, cmds.s)
9696
}
9797

98-
// MSetNX is a helper that consults the redis directly with multiple keys by grouping keys within same slot into MSETNXs or multiple SETNXs
98+
// MSetNX is a helper that consults the redis directly with multiple keys by grouping keys within the same slot into MSETNXs or multiple SETNXs
9999
func MSetNX(client Client, ctx context.Context, kvs map[string]string) map[string]error {
100100
if len(kvs) == 0 {
101101
return make(map[string]error)
@@ -114,7 +114,7 @@ func MSetNX(client Client, ctx context.Context, kvs map[string]string) map[strin
114114
return doMultiSet(client, ctx, cmds.s)
115115
}
116116

117-
// JsonMGetCache is a helper that consults the client-side caches with multiple keys by grouping keys within same slot into multiple JSON.GETs
117+
// JsonMGetCache is a helper that consults the client-side caches with multiple keys by grouping keys within the same slot into multiple JSON.GETs
118118
func JsonMGetCache(client Client, ctx context.Context, ttl time.Duration, keys []string, path string) (ret map[string]RedisMessage, err error) {
119119
if len(keys) == 0 {
120120
return make(map[string]RedisMessage), nil
@@ -127,7 +127,7 @@ func JsonMGetCache(client Client, ctx context.Context, ttl time.Duration, keys [
127127
return doMultiCache(client, ctx, cmds.s, keys)
128128
}
129129

130-
// JsonMGet is a helper that consults redis directly with multiple keys by grouping keys within same slot into JSON.MGETs or multiple JSON.GETs
130+
// JsonMGet is a helper that consults redis directly with multiple keys by grouping keys within the same slot into JSON.MGETs or multiple JSON.GETs
131131
func JsonMGet(client Client, ctx context.Context, keys []string, path string) (ret map[string]RedisMessage, err error) {
132132
if len(keys) == 0 {
133133
return make(map[string]RedisMessage), nil
@@ -146,7 +146,7 @@ func JsonMGet(client Client, ctx context.Context, keys []string, path string) (r
146146
return doMultiGet(client, ctx, cmds.s, keys)
147147
}
148148

149-
// JsonMSet is a helper that consults redis directly with multiple keys by grouping keys within same slot into JSON.MSETs or multiple JOSN.SETs
149+
// JsonMSet is a helper that consults redis directly with multiple keys by grouping keys within the same slot into JSON.MSETs or multiple JOSN.SETs
150150
func JsonMSet(client Client, ctx context.Context, kvs map[string]string, path string) map[string]error {
151151
if len(kvs) == 0 {
152152
return make(map[string]error)
@@ -165,7 +165,7 @@ func JsonMSet(client Client, ctx context.Context, kvs map[string]string, path st
165165
return doMultiSet(client, ctx, cmds.s)
166166
}
167167

168-
// DecodeSliceOfJSON is a helper that struct-scans each RedisMessage into dest, which must be a slice of pointer.
168+
// DecodeSliceOfJSON is a helper that struct-scans each RedisMessage into dest, which must be a slice of the pointer.
169169
func DecodeSliceOfJSON[T any](result RedisResult, dest *[]T) error {
170170
values, err := result.ToArray()
171171
if err != nil {

internal/cmds/cmds.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func ToBlock(c *Completed) {
9797
c.cf |= blockTag
9898
}
9999

100-
// Incomplete represents an incomplete Redis command. It should then be completed by calling the Build().
100+
// Incomplete represents an incomplete Redis command. It should then be completed by calling Build().
101101
type Incomplete struct {
102102
cs *CommandSlice
103103
cf int16 // use int16 instead of uint16 to make a difference with Completed

lua.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ func NewLuaScriptReadOnly(script string) *Lua {
2222

2323
// NewLuaScriptNoSha creates a Lua instance whose Lua.Exec uses EVAL.
2424
// Sha1 is not calculated, SCRIPT LOAD is not used, no EVALSHA is used.
25-
// The main motivation is to be FIPS compliant, also avoid tiny chance of SHA-1 collisions.
25+
// The main motivation is to be FIPS compliant, also avoid the tiny chance of SHA-1 collisions.
2626
// This comes with a performance cost as the script is sent to a server every time.
2727
func NewLuaScriptNoSha(script string) *Lua {
2828
return newLuaScript(script, false, true)
2929
}
3030

3131
// NewLuaScriptReadOnlyNoSha creates a Lua instance whose Lua.Exec uses EVAL_RO.
3232
// Sha1 is not calculated, SCRIPT LOAD is not used, no EVALSHA_RO is used.
33-
// The main motivation is to be FIPS compliant, also avoid tiny chance of SHA-1 collisions.
33+
// The main motivation is to be FIPS compliant, also avoid the tiny chance of SHA-1 collisions.
3434
// This comes with a performance cost as the script is sent to a server every time.
3535
func NewLuaScriptReadOnlyNoSha(script string) *Lua {
3636
return newLuaScript(script, true, true)
@@ -62,9 +62,9 @@ type Lua struct {
6262
}
6363

6464
// Exec the script to the given Client.
65-
// It will first try with the EVALSHA/EVALSHA_RO and then EVAL/EVAL_RO if first try failed.
66-
// If Lua is initialized with disabled SHA1, it will use EVAL/EVAL_RO without EVALSHA/EVALSHA_RO attempt.
67-
// Cross slot keys are prohibited if the Client is a cluster client.
65+
// It will first try with the EVALSHA/EVALSHA_RO and then EVAL/EVAL_RO if the first try failed.
66+
// If Lua is initialized with disabled SHA1, it will use EVAL/EVAL_RO without the EVALSHA/EVALSHA_RO attempt.
67+
// Cross-slot keys are prohibited if the Client is a cluster client.
6868
func (s *Lua) Exec(ctx context.Context, c Client, keys, args []string) (resp RedisResult) {
6969
var isNoScript bool
7070
if !s.nosha1 {
@@ -95,7 +95,7 @@ type LuaExec struct {
9595
// ExecMulti exec the script multiple times by the provided LuaExec to the given Client.
9696
// It will first try SCRIPT LOAD the script to all redis nodes and then exec it with the EVALSHA/EVALSHA_RO.
9797
// If Lua is initialized with disabled SHA1, it will use EVAL/EVAL_RO and no script loading.
98-
// Cross slot keys within single LuaExec are prohibited if the Client is a cluster client.
98+
// Cross-slot keys within the single LuaExec are prohibited if the Client is a cluster client.
9999
func (s *Lua) ExecMulti(ctx context.Context, c Client, multi ...LuaExec) (resp []RedisResult) {
100100
if !s.nosha1 {
101101
var e atomic.Value

0 commit comments

Comments
 (0)