Skip to content

Commit

Permalink
Merge pull request #22 from cep-ter/add-hexists-command
Browse files Browse the repository at this point in the history
Add redis hexists command
  • Loading branch information
rezkam committed Dec 17, 2020
2 parents a912473 + bd57430 commit 1e925f9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions commander/commander.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,3 +519,8 @@ func (c *Commander) Exists(result *int, keys ...string) *Commander {
}
return c.Command(result, "EXISTS", iKeys...)
}

// HExists returns if field is an existing field in the hash stored at key.
func (c *Commander) HExists(result *bool, key, field string) *Commander {
return c.Command(result, "HEXISTS", key, field)
}
24 changes: 24 additions & 0 deletions commander/commander_bdd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,30 @@ var _ = Describe("Commander", func() {
})
})

Describe("HEXISTS", func() {
It("should return the real results of a valid HEXISTS", func() {
key1 := "SomeKey1"
value1 := faker.Word()
conn := getConn()
var setResult int
var existsResult bool
errSend := conn.Send("HSET", key1, "value1", value1)
results, errResult := redis.Values(conn.Do(""))
_, errScan := redis.Scan(results, &setResult)
conn = getConn()
commander := New(conn)
errCmd := commander.HExists(&existsResult, "SomeKey1", "value1").Commit()

Expect(errSend).To(BeNil())
Expect(errScan).To(BeNil())
Expect(errResult).To(BeNil())
Expect(errCmd).To(BeNil())
Expect(setResult).To(Equal(1))
Expect(existsResult).To(Equal(true))
})

})

Describe("Integration test command and commit", func() {
It("should return the error of resuing closed connection", func() {
pool, errpool := bluto.GetPool(getCorrectConfig())
Expand Down

0 comments on commit 1e925f9

Please sign in to comment.