티스토리 뷰

 

업데이트 전, 즉 v9.6.0 이전 버전에서의 redis/go-redis 라이브러리를 사용한다면 개별 해시 키에 대한 만료 기간을 설정할 수 없었으며 이로 인해서 만료 기간을 설정하기 위해 Key의 형태를 Hash_Key=Value와 같이 값을 정의하고 관리했었어야 합니다.

 

하지만 2024년 7월 20일 공개된 v9.6.0 버전, 또는 그 이후 부터는 개별 해시 키에 대한 만료 기간을 설정할 수 있는 함수가 추가 또는 제공됩니다. 🥳

if err := rdb.HExpire(ctx, key, duration, hashKey).Err(); err != nil {
    log.Println("해시 키의 만료기간을 설정하는 과정에서 예외가 발생하였습니다.", err.Error())
    return err
}

다음과 같이 HExpire 함수를 호출하여 주어진 해시 키에 대한 만료 기간을 설정할 수 있도록 업데이트 되었습니다, 그 외에도 HExpireAt, HExpireAtWithArgs, HExpireTime, HExpireWithArgs와 같은 함수도 같이 추가되었습니다.

// HExpire - Sets the expiration time for specified fields in a hash in seconds.
// The command constructs an argument list starting with "HEXPIRE", followed by the key, duration, any conditional flags, and the specified fields.
// For more information - https://redis.io/commands/hexpire/
HExpire(ctx context.Context, key string, expiration time.Duration, fields ...string) *IntSliceCmd

 

자세한 내용은 아래 링크를 참고하세요.

 

Release 9.6.0 · redis/go-redis

Changes 🚀 New Features Support Hash-field expiration commands (#2991) Support Hash-field expiration commands in Pipeline & Fix HExpire HExpireWithArgs expiration (#3038) Support NOVALUES parameter...

github.com