EchoVault / SugarDB

Embeddable and distributed in-memory alternative to Redis.
https://sugardb.io
Apache License 2.0
409 stars 21 forks source link

Implement HEXPIRE command #113

Open kelvinmwinuka opened 1 month ago

kelvinmwinuka commented 1 month ago

Sets the expiration, in seconds, of a field in a hash. Reference: https://redis.io/docs/latest/commands/hexpire/

Client-Server Spec:

Command File: ./internal/modules/hash/commands.go Test File: ./internal/modules/hash/commands_test.go

Command: hexpire Module: constants.HashModule Categories: contants.HashCategory, constants.WriteCategory, constants.FastCategory Description: (HEXPIRE key seconds [NX | XX | GT | LT] FIELDS numfields field [field ...]) Sets the expiration, in seconds, of a field in a hash. Sync: true

NOTE: You may need to change the internal representation of the hash to hold a more complex data type that includes the field's value and expiry time instead of just the value. If the representation is already changed from a previous implementation, use the current one.

Embedded Spec:

Command File: ./echovault/api_hash.go Test File: ./echovault/api_hash_test.go

Documentation

Add documentation to ./docs/docs/commands/hash/HEXPIRE.mdx

osteensco commented 2 weeks ago

I'll work on this next.

osteensco commented 2 weeks ago

Based on our current implementation of expiration elsewhere, I think updating hash to use a struct for the value would be the cleanest approach. When I was looking over the codebase thinking through other options, trying to track expiration elsewhere felt inconsistent and hacky. So I'm thinking something like this -

type HashValue struct {
    Value    interface{}
    ExpireAt time.Time
}

type Hash map[string]HashValue
kelvinmwinuka commented 2 weeks ago

@osteensco I agree. This is the approach I had in mind as well.