(key, field string, value interface{})
| 300 | } |
| 301 | |
| 302 | func RedisHSetField(key, field string, value interface{}) error { |
| 303 | if DebugEnabled { |
| 304 | SysLog(fmt.Sprintf("Redis HSET field: key=%s, field=%s, value=%v", key, field, value)) |
| 305 | } |
| 306 | ttlCmd := RDB.TTL(context.Background(), key) |
| 307 | ttl, err := ttlCmd.Result() |
| 308 | if err != nil && !errors.Is(err, redis.Nil) { |
| 309 | return fmt.Errorf("failed to get TTL: %w", err) |
| 310 | } |
| 311 | |
| 312 | if ttl > 0 { |
| 313 | ctx := context.Background() |
| 314 | txn := RDB.TxPipeline() |
| 315 | |
| 316 | hsetCmd := txn.HSet(ctx, key, field, value) |
| 317 | if err := hsetCmd.Err(); err != nil { |
| 318 | return err |
| 319 | } |
| 320 | |
| 321 | txn.Expire(ctx, key, ttl) |
| 322 | |
| 323 | _, err = txn.Exec(ctx) |
| 324 | return err |
| 325 | } |
| 326 | return nil |
| 327 | } |
no test coverage detected