Skip to content

Commit

Permalink
Merge branch 'unstable' into update-glog-0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PragmaTwice authored Nov 18, 2024
2 parents 11b22cc + 7611d73 commit 5e21349
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/types/redis_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ rocksdb::Status String::IncrBy(engine::Context &ctx, const std::string &user_key
if (!s.ok() && !s.IsNotFound()) return s;
if (s.IsNotFound()) {
Metadata metadata(kRedisString, false);
raw_value.clear();
metadata.Encode(&raw_value);
}

Expand Down Expand Up @@ -367,6 +368,7 @@ rocksdb::Status String::IncrByFloat(engine::Context &ctx, const std::string &use

if (s.IsNotFound()) {
Metadata metadata(kRedisString, false);
raw_value.clear();
metadata.Encode(&raw_value);
}
size_t offset = Metadata::GetOffsetAfterExpire(raw_value[0]);
Expand Down
15 changes: 15 additions & 0 deletions tests/gocase/unit/type/incr/incr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package incr
import (
"context"
"testing"
"time"

"github.com/apache/kvrocks/tests/gocase/util"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -75,6 +76,14 @@ func testIncr(t *testing.T, configs util.KvrocksServerConfigs) {
require.EqualValues(t, 34359738368, rdb.IncrBy(ctx, "novar", 17179869184).Val())
})

t.Run("INCR over an expired key", func(t *testing.T) {
require.NoError(t, rdb.SetEx(ctx, "expired-foo", "1024", 2*time.Second).Err())
require.NoError(t, rdb.SetEx(ctx, "expired-str", "value", 2*time.Second).Err())
time.Sleep(3 * time.Second)
require.EqualValues(t, 1, rdb.IncrBy(ctx, "expired-foo", 1).Val())
require.EqualValues(t, 1, rdb.IncrBy(ctx, "expired-str", 1).Val())
})

t.Run("INCR fails against key with spaces (left)", func(t *testing.T) {
require.NoError(t, rdb.Set(ctx, "novar", " 11", 0).Err())
util.ErrorRegexp(t, rdb.Incr(ctx, "novar").Err(), "ERR.*")
Expand Down Expand Up @@ -133,6 +142,12 @@ func testIncr(t *testing.T, configs util.KvrocksServerConfigs) {
require.EqualValues(t, 34359738368, rdb.IncrByFloat(ctx, "novar", 17179869184).Val())
})

t.Run("INCRBYFLOAT over an expired key", func(t *testing.T) {
require.NoError(t, rdb.SetEx(ctx, "expired-foo", "10.24", 2*time.Second).Err())
time.Sleep(3 * time.Second)
require.EqualValues(t, 1, rdb.IncrBy(ctx, "expired-foo", 1.0).Val())
})

t.Run("INCRBYFLOAT fails against key with spaces (left)", func(t *testing.T) {
require.NoError(t, rdb.Set(ctx, "novar", " 11", 0).Err())
util.ErrorRegexp(t, rdb.IncrByFloat(ctx, "novar", 1.0).Err(), "ERR.*valid.*")
Expand Down

0 comments on commit 5e21349

Please sign in to comment.