Skip to content

Commit

Permalink
fix issue #2331
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn committed Feb 8, 2023
1 parent 21ebf48 commit 83fb3ae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions contrib/nosql/redis/redis_z_unit_gcache_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func Test_AdapterRedis_SetIfNotExistFunc(t *testing.T) {
return 11, nil
}, 0)
t.AssertNil(err)
t.Assert(exist, false)
t.Assert(exist, true)
})
}

Expand All @@ -257,7 +257,7 @@ func Test_AdapterRedis_SetIfNotExistFuncLock(t *testing.T) {
return 11, nil
}, 0)
t.AssertNil(err)
t.Assert(exist, false)
t.Assert(exist, true)
})
}

Expand Down
8 changes: 4 additions & 4 deletions os/gcache/gcache_adapter_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ func (c *AdapterRedis) SetIfNotExist(ctx context.Context, key interface{}, value
}
ok, err = c.redis.SetNX(ctx, redisKey, value)
if err != nil {
return false, err
return ok, err
}
if ok && duration > 0 {
// Set the expiration.
_, err = c.redis.Expire(ctx, redisKey, int64(duration.Seconds()))
if err != nil {
return false, err
return ok, err
}
return true, err
return ok, err
}
return false, err
return ok, err
}

// SetIfNotExistFunc sets `key` with result of function `f` and returns true
Expand Down

0 comments on commit 83fb3ae

Please sign in to comment.