chore: refactor code (#1699)

This commit is contained in:
Kevin Wan
2022-03-23 18:24:44 +08:00
committed by GitHub
parent bbac994c8a
commit ec271db7a0
5 changed files with 33 additions and 32 deletions

View File

@@ -24,6 +24,7 @@ type (
Expire(key string, seconds int) error
Expireat(key string, expireTime int64) error
Get(key string) (string, error)
GetSet(key, value string) (string, error)
Hdel(key, field string) (bool, error)
Hexists(key, field string) (bool, error)
Hget(key, field string) (string, error)
@@ -54,7 +55,6 @@ type (
Setex(key, value string, seconds int) error
Setnx(key, value string) (bool, error)
SetnxEx(key, value string, seconds int) (bool, error)
Getset(key, value string) (string, error)
Sismember(key string, value interface{}) (bool, error)
Smembers(key string) ([]string, error)
Spop(key string) (string, error)
@@ -460,7 +460,7 @@ func (cs clusterStore) SetnxEx(key, value string, seconds int) (bool, error) {
return node.SetnxEx(key, value, seconds)
}
func (cs clusterStore) Getset(key, value string) (string, error) {
func (cs clusterStore) GetSet(key, value string) (string, error) {
node, err := cs.getRedis(key)
if err != nil {
return "", err

View File

@@ -492,17 +492,17 @@ func TestRedis_SetExNx(t *testing.T) {
func TestRedis_Getset(t *testing.T) {
store := clusterStore{dispatcher: hash.NewConsistentHash()}
_, err := store.Getset("hello", "world")
_, err := store.GetSet("hello", "world")
assert.NotNil(t, err)
runOnCluster(t, func(client Store) {
val, err := client.Getset("hello", "world")
val, err := client.GetSet("hello", "world")
assert.Nil(t, err)
assert.Equal(t, "", val)
val, err = client.Get("hello")
assert.Nil(t, err)
assert.Equal(t, "world", val)
val, err = client.Getset("hello", "newworld")
val, err = client.GetSet("hello", "newworld")
assert.Nil(t, err)
assert.Equal(t, "world", val)
val, err = client.Get("hello")