-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
3,645 additions
and
3,555 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
testdata/* | ||
.idea/ | ||
.DS_Store | ||
*.tar.gz | ||
*.dic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package redis | ||
|
||
import "context" | ||
|
||
type ACLCmdable interface { | ||
ACLDryRun(ctx context.Context, username string, command ...interface{}) *StringCmd | ||
ACLLog(ctx context.Context, count int64) *ACLLogCmd | ||
ACLLogReset(ctx context.Context) *StatusCmd | ||
} | ||
|
||
func (c cmdable) ACLDryRun(ctx context.Context, username string, command ...interface{}) *StringCmd { | ||
args := make([]interface{}, 0, 3+len(command)) | ||
args = append(args, "acl", "dryrun", username) | ||
args = append(args, command...) | ||
cmd := NewStringCmd(ctx, args...) | ||
_ = c(ctx, cmd) | ||
return cmd | ||
} | ||
|
||
func (c cmdable) ACLLog(ctx context.Context, count int64) *ACLLogCmd { | ||
args := make([]interface{}, 0, 3) | ||
args = append(args, "acl", "log") | ||
if count > 0 { | ||
args = append(args, count) | ||
} | ||
cmd := NewACLLogCmd(ctx, args...) | ||
_ = c(ctx, cmd) | ||
return cmd | ||
} | ||
|
||
func (c cmdable) ACLLogReset(ctx context.Context) *StatusCmd { | ||
cmd := NewStatusCmd(ctx, "acl", "log", "reset") | ||
_ = c(ctx, cmd) | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package redis | ||
|
||
import "context" | ||
|
||
type BitMapCmdable interface { | ||
GetBit(ctx context.Context, key string, offset int64) *IntCmd | ||
SetBit(ctx context.Context, key string, offset int64, value int) *IntCmd | ||
BitCount(ctx context.Context, key string, bitCount *BitCount) *IntCmd | ||
BitOpAnd(ctx context.Context, destKey string, keys ...string) *IntCmd | ||
BitOpOr(ctx context.Context, destKey string, keys ...string) *IntCmd | ||
BitOpXor(ctx context.Context, destKey string, keys ...string) *IntCmd | ||
BitOpNot(ctx context.Context, destKey string, key string) *IntCmd | ||
BitPos(ctx context.Context, key string, bit int64, pos ...int64) *IntCmd | ||
BitPosSpan(ctx context.Context, key string, bit int8, start, end int64, span string) *IntCmd | ||
BitField(ctx context.Context, key string, args ...interface{}) *IntSliceCmd | ||
} | ||
|
||
func (c cmdable) GetBit(ctx context.Context, key string, offset int64) *IntCmd { | ||
cmd := NewIntCmd(ctx, "getbit", key, offset) | ||
_ = c(ctx, cmd) | ||
return cmd | ||
} | ||
|
||
func (c cmdable) SetBit(ctx context.Context, key string, offset int64, value int) *IntCmd { | ||
cmd := NewIntCmd( | ||
ctx, | ||
"setbit", | ||
key, | ||
offset, | ||
value, | ||
) | ||
_ = c(ctx, cmd) | ||
return cmd | ||
} | ||
|
||
type BitCount struct { | ||
Start, End int64 | ||
} | ||
|
||
func (c cmdable) BitCount(ctx context.Context, key string, bitCount *BitCount) *IntCmd { | ||
args := []interface{}{"bitcount", key} | ||
if bitCount != nil { | ||
args = append( | ||
args, | ||
bitCount.Start, | ||
bitCount.End, | ||
) | ||
} | ||
cmd := NewIntCmd(ctx, args...) | ||
_ = c(ctx, cmd) | ||
return cmd | ||
} | ||
|
||
func (c cmdable) bitOp(ctx context.Context, op, destKey string, keys ...string) *IntCmd { | ||
args := make([]interface{}, 3+len(keys)) | ||
args[0] = "bitop" | ||
args[1] = op | ||
args[2] = destKey | ||
for i, key := range keys { | ||
args[3+i] = key | ||
} | ||
cmd := NewIntCmd(ctx, args...) | ||
_ = c(ctx, cmd) | ||
return cmd | ||
} | ||
|
||
func (c cmdable) BitOpAnd(ctx context.Context, destKey string, keys ...string) *IntCmd { | ||
return c.bitOp(ctx, "and", destKey, keys...) | ||
} | ||
|
||
func (c cmdable) BitOpOr(ctx context.Context, destKey string, keys ...string) *IntCmd { | ||
return c.bitOp(ctx, "or", destKey, keys...) | ||
} | ||
|
||
func (c cmdable) BitOpXor(ctx context.Context, destKey string, keys ...string) *IntCmd { | ||
return c.bitOp(ctx, "xor", destKey, keys...) | ||
} | ||
|
||
func (c cmdable) BitOpNot(ctx context.Context, destKey string, key string) *IntCmd { | ||
return c.bitOp(ctx, "not", destKey, key) | ||
} | ||
|
||
// BitPos is an API before Redis version 7.0, cmd: bitpos key bit start end | ||
// if you need the `byte | bit` parameter, please use `BitPosSpan`. | ||
func (c cmdable) BitPos(ctx context.Context, key string, bit int64, pos ...int64) *IntCmd { | ||
args := make([]interface{}, 3+len(pos)) | ||
args[0] = "bitpos" | ||
args[1] = key | ||
args[2] = bit | ||
switch len(pos) { | ||
case 0: | ||
case 1: | ||
args[3] = pos[0] | ||
case 2: | ||
args[3] = pos[0] | ||
args[4] = pos[1] | ||
default: | ||
panic("too many arguments") | ||
} | ||
cmd := NewIntCmd(ctx, args...) | ||
_ = c(ctx, cmd) | ||
return cmd | ||
} | ||
|
||
// BitPosSpan supports the `byte | bit` parameters in redis version 7.0, | ||
// the bitpos command defaults to using byte type for the `start-end` range, | ||
// which means it counts in bytes from start to end. you can set the value | ||
// of "span" to determine the type of `start-end`. | ||
// span = "bit", cmd: bitpos key bit start end bit | ||
// span = "byte", cmd: bitpos key bit start end byte | ||
func (c cmdable) BitPosSpan(ctx context.Context, key string, bit int8, start, end int64, span string) *IntCmd { | ||
cmd := NewIntCmd(ctx, "bitpos", key, bit, start, end, span) | ||
_ = c(ctx, cmd) | ||
return cmd | ||
} | ||
|
||
func (c cmdable) BitField(ctx context.Context, key string, args ...interface{}) *IntSliceCmd { | ||
a := make([]interface{}, 0, 2+len(args)) | ||
a = append(a, "bitfield") | ||
a = append(a, key) | ||
a = append(a, args...) | ||
cmd := NewIntSliceCmd(ctx, a...) | ||
_ = c(ctx, cmd) | ||
return cmd | ||
} |
Oops, something went wrong.