Skip to content

format code by running make fmt #3011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 57 additions & 56 deletions acl_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,68 +9,69 @@ import (
. "github.com/bsm/gomega"
)

var TestUserName string = "goredis"
var _ = Describe("ACL", func() {
var client *redis.Client
var ctx context.Context

BeforeEach(func() {
ctx = context.Background()
opt := redisOptions()
client = redis.NewClient(opt)
})

It("should ACL LOG", Label("NonRedisEnterprise"), func() {
Expect(client.ACLLogReset(ctx).Err()).NotTo(HaveOccurred())
err := client.Do(ctx, "acl", "setuser", "test", ">test", "on", "allkeys", "+get").Err()
Expect(err).NotTo(HaveOccurred())
var (
TestUserName string = "goredis"
_ = Describe("ACL", func() {
var client *redis.Client
var ctx context.Context

BeforeEach(func() {
ctx = context.Background()
opt := redisOptions()
client = redis.NewClient(opt)
})

It("should ACL LOG", Label("NonRedisEnterprise"), func() {
Expect(client.ACLLogReset(ctx).Err()).NotTo(HaveOccurred())
err := client.Do(ctx, "acl", "setuser", "test", ">test", "on", "allkeys", "+get").Err()
Expect(err).NotTo(HaveOccurred())

clientAcl := redis.NewClient(redisOptions())
clientAcl.Options().Username = "test"
clientAcl.Options().Password = "test"
clientAcl.Options().DB = 0
_ = clientAcl.Set(ctx, "mystring", "foo", 0).Err()
_ = clientAcl.HSet(ctx, "myhash", "foo", "bar").Err()
_ = clientAcl.SAdd(ctx, "myset", "foo", "bar").Err()
clientAcl := redis.NewClient(redisOptions())
clientAcl.Options().Username = "test"
clientAcl.Options().Password = "test"
clientAcl.Options().DB = 0
_ = clientAcl.Set(ctx, "mystring", "foo", 0).Err()
_ = clientAcl.HSet(ctx, "myhash", "foo", "bar").Err()
_ = clientAcl.SAdd(ctx, "myset", "foo", "bar").Err()

logEntries, err := client.ACLLog(ctx, 10).Result()
Expect(err).NotTo(HaveOccurred())
Expect(len(logEntries)).To(Equal(4))

for _, entry := range logEntries {
Expect(entry.Reason).To(Equal("command"))
Expect(entry.Context).To(Equal("toplevel"))
Expect(entry.Object).NotTo(BeEmpty())
Expect(entry.Username).To(Equal("test"))
Expect(entry.AgeSeconds).To(BeNumerically(">=", 0))
Expect(entry.ClientInfo).NotTo(BeNil())
Expect(entry.EntryID).To(BeNumerically(">=", 0))
Expect(entry.TimestampCreated).To(BeNumerically(">=", 0))
Expect(entry.TimestampLastUpdated).To(BeNumerically(">=", 0))
}

limitedLogEntries, err := client.ACLLog(ctx, 2).Result()
Expect(err).NotTo(HaveOccurred())
Expect(len(limitedLogEntries)).To(Equal(2))
logEntries, err := client.ACLLog(ctx, 10).Result()
Expect(err).NotTo(HaveOccurred())
Expect(len(logEntries)).To(Equal(4))

for _, entry := range logEntries {
Expect(entry.Reason).To(Equal("command"))
Expect(entry.Context).To(Equal("toplevel"))
Expect(entry.Object).NotTo(BeEmpty())
Expect(entry.Username).To(Equal("test"))
Expect(entry.AgeSeconds).To(BeNumerically(">=", 0))
Expect(entry.ClientInfo).NotTo(BeNil())
Expect(entry.EntryID).To(BeNumerically(">=", 0))
Expect(entry.TimestampCreated).To(BeNumerically(">=", 0))
Expect(entry.TimestampLastUpdated).To(BeNumerically(">=", 0))
}

limitedLogEntries, err := client.ACLLog(ctx, 2).Result()
Expect(err).NotTo(HaveOccurred())
Expect(len(limitedLogEntries)).To(Equal(2))

// cleanup after creating the user
err = client.Do(ctx, "acl", "deluser", "test").Err()
Expect(err).NotTo(HaveOccurred())
})
// cleanup after creating the user
err = client.Do(ctx, "acl", "deluser", "test").Err()
Expect(err).NotTo(HaveOccurred())
})

It("should ACL LOG RESET", Label("NonRedisEnterprise"), func() {
// Call ACL LOG RESET
resetCmd := client.ACLLogReset(ctx)
Expect(resetCmd.Err()).NotTo(HaveOccurred())
Expect(resetCmd.Val()).To(Equal("OK"))
It("should ACL LOG RESET", Label("NonRedisEnterprise"), func() {
// Call ACL LOG RESET
resetCmd := client.ACLLogReset(ctx)
Expect(resetCmd.Err()).NotTo(HaveOccurred())
Expect(resetCmd.Val()).To(Equal("OK"))

// Verify that the log is empty after the reset
logEntries, err := client.ACLLog(ctx, 10).Result()
Expect(err).NotTo(HaveOccurred())
Expect(len(logEntries)).To(Equal(0))
// Verify that the log is empty after the reset
logEntries, err := client.ACLLog(ctx, 10).Result()
Expect(err).NotTo(HaveOccurred())
Expect(len(logEntries)).To(Equal(0))
})
})

})
)
var _ = Describe("ACL user commands", Label("NonRedisEnterprise"), func() {
var client *redis.Client
var ctx context.Context
Expand Down
10 changes: 6 additions & 4 deletions bitmap_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type BitMapCmdable interface {
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
BitOpNot(ctx context.Context, destKey, 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, values ...interface{}) *IntSliceCmd
Expand Down Expand Up @@ -42,8 +42,10 @@ type BitCount struct {
Unit string // BYTE(default) | BIT
}

const BitCountIndexByte string = "BYTE"
const BitCountIndexBit string = "BIT"
const (
BitCountIndexByte string = "BYTE"
BitCountIndexBit string = "BIT"
)

func (c cmdable) BitCount(ctx context.Context, key string, bitCount *BitCount) *IntCmd {
args := make([]any, 2, 5)
Expand Down Expand Up @@ -90,7 +92,7 @@ func (c cmdable) BitOpXor(ctx context.Context, destKey string, keys ...string) *
return c.bitOp(ctx, "xor", destKey, keys...)
}

func (c cmdable) BitOpNot(ctx context.Context, destKey string, key string) *IntCmd {
func (c cmdable) BitOpNot(ctx context.Context, destKey, key string) *IntCmd {
return c.bitOp(ctx, "not", destKey, key)
}

Expand Down
7 changes: 4 additions & 3 deletions bitmap_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package redis_test
import (
. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"

"github.com/redis/go-redis/v9"
)

Expand Down Expand Up @@ -31,7 +32,7 @@ var _ = Describe("BitCountBite", func() {
})

It("bit count bite", func() {
var expected = []bitCountExpected{
expected := []bitCountExpected{
{0, 0, 0},
{0, 1, 1},
{0, 2, 1},
Expand Down Expand Up @@ -71,7 +72,7 @@ var _ = Describe("BitCountByte", func() {
})

It("bit count byte", func() {
var expected = []bitCountExpected{
expected := []bitCountExpected{
{0, 0, 1},
{0, 1, 3},
}
Expand All @@ -84,7 +85,7 @@ var _ = Describe("BitCountByte", func() {
})

It("bit count byte with no unit specified", func() {
var expected = []bitCountExpected{
expected := []bitCountExpected{
{0, 0, 1},
{0, 1, 3},
}
Expand Down
4 changes: 2 additions & 2 deletions cluster_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type ClusterCmdable interface {
ClusterResetHard(ctx context.Context) *StatusCmd
ClusterInfo(ctx context.Context) *StringCmd
ClusterKeySlot(ctx context.Context, key string) *IntCmd
ClusterGetKeysInSlot(ctx context.Context, slot int, count int) *StringSliceCmd
ClusterGetKeysInSlot(ctx context.Context, slot, count int) *StringSliceCmd
ClusterCountFailureReports(ctx context.Context, nodeID string) *IntCmd
ClusterCountKeysInSlot(ctx context.Context, slot int) *IntCmd
ClusterDelSlots(ctx context.Context, slots ...int) *StatusCmd
Expand Down Expand Up @@ -108,7 +108,7 @@ func (c cmdable) ClusterKeySlot(ctx context.Context, key string) *IntCmd {
return cmd
}

func (c cmdable) ClusterGetKeysInSlot(ctx context.Context, slot int, count int) *StringSliceCmd {
func (c cmdable) ClusterGetKeysInSlot(ctx context.Context, slot, count int) *StringSliceCmd {
cmd := NewStringSliceCmd(ctx, "cluster", "getkeysinslot", slot, count)
_ = c(ctx, cmd)
return cmd
Expand Down
2 changes: 1 addition & 1 deletion command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2020,7 +2020,7 @@ type XInfoConsumer struct {

var _ Cmder = (*XInfoConsumersCmd)(nil)

func NewXInfoConsumersCmd(ctx context.Context, stream string, group string) *XInfoConsumersCmd {
func NewXInfoConsumersCmd(ctx context.Context, stream, group string) *XInfoConsumersCmd {
return &XInfoConsumersCmd{
baseCmd: baseCmd{
ctx: ctx,
Expand Down
3 changes: 1 addition & 2 deletions commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ var _ = Describe("Commands", func() {
defer client2.Close()
clientInfo = client2.ClientInfo(ctx).Val()
Expect(clientInfo.LibName).To(ContainSubstring("go-redis(suffix,"))

})

It("should ConfigGet", func() {
Expand Down Expand Up @@ -460,7 +459,7 @@ var _ = Describe("Commands", func() {
}

// read the defaults to set them back later
for setting, _ := range expected {
for setting := range expected {
val, err := client.ConfigGet(ctx, setting).Result()
Expect(err).NotTo(HaveOccurred())
defaults[setting] = val[setting]
Expand Down
5 changes: 0 additions & 5 deletions doctests/bf_tutorial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,20 @@ func ExampleClient_bloom() {

// STEP_START bloom
res1, err := rdb.BFReserve(ctx, "bikes:models", 0.01, 1000).Result()

if err != nil {
panic(err)
}

fmt.Println(res1) // >>> OK

res2, err := rdb.BFAdd(ctx, "bikes:models", "Smoky Mountain Striker").Result()

if err != nil {
panic(err)
}

fmt.Println(res2) // >>> true

res3, err := rdb.BFExists(ctx, "bikes:models", "Smoky Mountain Striker").Result()

if err != nil {
panic(err)
}
Expand All @@ -56,7 +53,6 @@ func ExampleClient_bloom() {
"Cloudy City Cruiser",
"Windy City Wippet",
).Result()

if err != nil {
panic(err)
}
Expand All @@ -68,7 +64,6 @@ func ExampleClient_bloom() {
"Cloudy City Cruiser",
"Windy City Wippet",
).Result()

if err != nil {
panic(err)
}
Expand Down
4 changes: 0 additions & 4 deletions doctests/bitfield_tutorial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func ExampleClient_bf() {
res1, err := rdb.BitField(ctx, "bike:1:stats",
"set", "u32", "#0", "1000",
).Result()

if err != nil {
panic(err)
}
Expand All @@ -42,7 +41,6 @@ func ExampleClient_bf() {
"incrby", "u32", "#0", "-50",
"incrby", "u32", "#1", "1",
).Result()

if err != nil {
panic(err)
}
Expand All @@ -54,7 +52,6 @@ func ExampleClient_bf() {
"incrby", "u32", "#0", "500",
"incrby", "u32", "#1", "1",
).Result()

if err != nil {
panic(err)
}
Expand All @@ -65,7 +62,6 @@ func ExampleClient_bf() {
"get", "u32", "#0",
"get", "u32", "#1",
).Result()

if err != nil {
panic(err)
}
Expand Down
5 changes: 0 additions & 5 deletions doctests/bitmap_tutorial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,20 @@ func ExampleClient_ping() {

// STEP_START ping
res1, err := rdb.SetBit(ctx, "pings:2024-01-01-00:00", 123, 1).Result()

if err != nil {
panic(err)
}

fmt.Println(res1) // >>> 0

res2, err := rdb.GetBit(ctx, "pings:2024-01-01-00:00", 123).Result()

if err != nil {
panic(err)
}

fmt.Println(res2) // >>> 1

res3, err := rdb.GetBit(ctx, "pings:2024-01-01-00:00", 456).Result()

if err != nil {
panic(err)
}
Expand All @@ -71,7 +68,6 @@ func ExampleClient_bitcount() {
// start with fresh database
rdb.FlushDB(ctx)
_, err := rdb.SetBit(ctx, "pings:2024-01-01-00:00", 123, 1).Result()

if err != nil {
panic(err)
}
Expand All @@ -83,7 +79,6 @@ func ExampleClient_bitcount() {
Start: 0,
End: 456,
}).Result()

if err != nil {
panic(err)
}
Expand Down
Loading
Loading