MCPcopy Create free account
hub / github.com/devfeel/dotweb / TestRedisClient_HashOperations

Function TestRedisClient_HashOperations

framework/redis/redisutil_test.go:244–272  ·  view source on GitHub ↗

TestRedisClient_HashOperations tests HSet, HGet, HGetAll, HDel

(t *testing.T)

Source from the content-addressed store, hash-verified

242
243// TestRedisClient_HashOperations tests HSet, HGet, HGetAll, HDel
244func TestRedisClient_HashOperations(t *testing.T) {
245 skipIfNoRedis(t)
246 client := GetDefaultRedisClient("redis://localhost:6379/0")
247 key := "test_hash_key"
248 client.Del(key)
249 err := client.HSet(key, "field1", "value1")
250 if err != nil {
251 t.Errorf("HSet failed: %v", err)
252 }
253 val, err := client.HGet(key, "field1")
254 if err != nil {
255 t.Errorf("HGet failed: %v", err)
256 }
257 if val != "value1" {
258 t.Errorf("HGet returned wrong value: got %s, want value1", val)
259 }
260 all, err := client.HGetAll(key)
261 if err != nil {
262 t.Errorf("HGetAll failed: %v", err)
263 }
264 if all["field1"] != "value1" {
265 t.Errorf("HGetAll returned wrong value: got %s, want value1", all["field1"])
266 }
267 _, err = client.HDel(key, "field1")
268 if err != nil {
269 t.Errorf("HDel failed: %v", err)
270 }
271 client.Del(key)
272}
273
274// TestRedisClient_ListOperations tests LPush, RPush, LRange, LPop, RPop
275func TestRedisClient_ListOperations(t *testing.T) {

Callers

nothing calls this directly

Calls 7

skipIfNoRedisFunction · 0.85
GetDefaultRedisClientFunction · 0.85
DelMethod · 0.80
HSetMethod · 0.80
HGetMethod · 0.80
HGetAllMethod · 0.80
HDelMethod · 0.80

Tested by

no test coverage detected