From 4ced28e2b6b542256a300befebc278c711132355 Mon Sep 17 00:00:00 2001 From: Jeremy Woertink Date: Mon, 19 Sep 2022 13:30:53 -0700 Subject: [PATCH 1/2] Adding HINCRBY command --- spec/redis_spec.cr | 9 +++++++++ src/commands/hash.cr | 4 ++++ 2 files changed, 13 insertions(+) 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..b5e505a 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 : Int32) + run({"hincrby", key, field, increment}) + 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) From 2cabc7fdadfc3e98ac85adaf9ba1c8fda9021903 Mon Sep 17 00:00:00 2001 From: Jeremy Woertink Date: Mon, 19 Sep 2022 15:01:54 -0700 Subject: [PATCH 2/2] Update src/commands/hash.cr Co-authored-by: Jamie Gaskins --- src/commands/hash.cr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/hash.cr b/src/commands/hash.cr index b5e505a..b8d9013 100644 --- a/src/commands/hash.cr +++ b/src/commands/hash.cr @@ -35,8 +35,8 @@ module Redis::Commands::Hash run command end - def hincrby(key : String, field : String, increment : Int32) - run({"hincrby", key, field, increment}) + 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/")]