diff --git a/spec/redis_spec.cr b/spec/redis_spec.cr index ba2492a..b202879 100644 --- a/spec/redis_spec.cr +++ b/spec/redis_spec.cr @@ -231,6 +231,15 @@ describe Redis::Client do end end + describe "hash" do + test "hincrby increments the number stored at field in the hash" do + redis.hset(key, {"field" => "5"}) + redis.hincrby(key, "field", 1).should eq(6) + redis.hincrby(key, "field", -1).should eq(5) + redis.hincrby(key, "field", -10).should eq(-5) + end + end + it "can pipeline commands" do key = random_key diff --git a/src/commands/hash.cr b/src/commands/hash.cr index 3dc039a..b8d9013 100644 --- a/src/commands/hash.cr +++ b/src/commands/hash.cr @@ -35,6 +35,10 @@ module Redis::Commands::Hash run command end + def hincrby(key : String, field : String, increment : Int | String) + run({"hincrby", key, field, increment.to_s}) + end + @[Deprecated("The Redis HMSET command is deprecated. Use HSET instead. This method will be removed in v1.0.0 of this shard. See https://redis.io/commands/hmset/")] def hmset(key : String, data : ::Hash(String, String)) command = Array(String).new(initial_capacity: 2 + data.size)