Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding HINCRBY command #26

Merged
merged 2 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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