Skip to content

Commit b1aeec4

Browse files
committed
Merge branch 'master' into feat/redis_pubsub
2 parents d5767ef + cdb0098 commit b1aeec4

File tree

4 files changed

+53
-3
lines changed

4 files changed

+53
-3
lines changed

core/stores/redis/redis.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,28 @@ func (s *Redis) GetBitCtx(ctx context.Context, key string, offset int64) (int, e
618618
return int(v), nil
619619
}
620620

621+
// GetDel is the implementation of redis getdel command.
622+
// Available since: redis version 6.2.0
623+
func (s *Redis) GetDel(key string) (string, error) {
624+
return s.GetDelCtx(context.Background(), key)
625+
}
626+
627+
// GetDelCtx is the implementation of redis getdel command.
628+
// Available since: redis version 6.2.0
629+
func (s *Redis) GetDelCtx(ctx context.Context, key string) (string, error) {
630+
conn, err := getRedis(s)
631+
if err != nil {
632+
return "", err
633+
}
634+
635+
val, err := conn.GetDel(ctx, key).Result()
636+
if errors.Is(err, red.Nil) {
637+
return "", nil
638+
}
639+
640+
return val, err
641+
}
642+
621643
// GetSet is the implementation of redis getset command.
622644
func (s *Redis) GetSet(key, value string) (string, error) {
623645
return s.GetSetCtx(context.Background(), key, value)

core/stores/redis/redis_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,34 @@ func TestRedis_Set(t *testing.T) {
10711071
})
10721072
}
10731073

1074+
func TestRedis_GetDel(t *testing.T) {
1075+
t.Run("get_del", func(t *testing.T) {
1076+
runOnRedis(t, func(client *Redis) {
1077+
val, err := newRedis(client.Addr).GetDel("hello")
1078+
assert.Equal(t, "", val)
1079+
assert.Nil(t, err)
1080+
err = client.Set("hello", "world")
1081+
assert.Nil(t, err)
1082+
val, err = client.Get("hello")
1083+
assert.Nil(t, err)
1084+
assert.Equal(t, "world", val)
1085+
val, err = client.GetDel("hello")
1086+
assert.Nil(t, err)
1087+
assert.Equal(t, "world", val)
1088+
val, err = client.Get("hello")
1089+
assert.Nil(t, err)
1090+
assert.Equal(t, "", val)
1091+
})
1092+
})
1093+
1094+
t.Run("get_del_with_error", func(t *testing.T) {
1095+
runOnRedisWithError(t, func(client *Redis) {
1096+
_, err := newRedis(client.Addr, badType()).GetDel("hello")
1097+
assert.Error(t, err)
1098+
})
1099+
})
1100+
}
1101+
10741102
func TestRedis_GetSet(t *testing.T) {
10751103
t.Run("set_get", func(t *testing.T) {
10761104
runOnRedis(t, func(client *Redis) {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require (
1717
github.com/olekukonko/tablewriter v0.0.5
1818
github.com/pelletier/go-toml/v2 v2.2.2
1919
github.com/prometheus/client_golang v1.21.1
20-
github.com/redis/go-redis/v9 v9.7.1
20+
github.com/redis/go-redis/v9 v9.7.3
2121
github.com/spaolacci/murmur3 v1.1.0
2222
github.com/stretchr/testify v1.10.0
2323
go.etcd.io/etcd/api/v3 v3.5.15

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ github.com/prometheus/common v0.62.0 h1:xasJaQlnWAeyHdUBeGjXmutelfJHWMRr+Fg4QszZ
159159
github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I=
160160
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
161161
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
162-
github.com/redis/go-redis/v9 v9.7.1 h1:4LhKRCIduqXqtvCUlaq9c8bdHOkICjDMrr1+Zb3osAc=
163-
github.com/redis/go-redis/v9 v9.7.1/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw=
162+
github.com/redis/go-redis/v9 v9.7.3 h1:YpPyAayJV+XErNsatSElgRZZVCwXX9QzkKYNvO7x0wM=
163+
github.com/redis/go-redis/v9 v9.7.3/go.mod h1:bGUrSggJ9X9GUmZpZNEOQKaANxSGgOEBRltRTZHSvrA=
164164
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
165165
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
166166
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=

0 commit comments

Comments
 (0)