Skip to content

Commit

Permalink
Merge pull request #26 from jwoertink/add_hincrby
Browse files Browse the repository at this point in the history
Adding HINCRBY command
  • Loading branch information
jgaskins authored Sep 19, 2022
2 parents 4be302a + 2cabc7f commit 4abfe14
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions spec/redis_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions src/commands/hash.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4abfe14

Please sign in to comment.