mirror of
https://github.com/grassrootseconomics/eth-tracker.git
synced 2025-02-23 08:02:16 +01:00
commit05d142664d
Author: Mohamed Sohail 天明 <sohailsameja@gmail.com> Date: Mon Oct 7 15:12:58 2024 +0300 feat: handle contract creation (#43) * feat: add contract creation handler * fix: process contract creations * fix: redis keys name commit4b2ad3daf9
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon Oct 7 15:12:15 2024 +0300 build(deps): bump github.com/knadh/koanf/providers/env (#37) Bumps [github.com/knadh/koanf/providers/env](https://github.com/knadh/koanf) from 0.1.0 to 1.0.0. - [Release notes](https://github.com/knadh/koanf/releases) - [Commits](https://github.com/knadh/koanf/compare/v0.1.0...v1.0.0) --- updated-dependencies: - dependency-name: github.com/knadh/koanf/providers/env dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> commitf1086fcdc1
Author: Mohamed Sohail 天明 <sohailsameja@gmail.com> Date: Mon Oct 7 10:07:11 2024 +0300 feat: optimize exists to check multiple keys in one call (#40) * closes #32 commitfd59d286f5
Author: Mohammed Sohail <sohailsameja@gmail.com> Date: Mon Oct 7 09:49:01 2024 +0300 feat: add custodial registration proxy handler
57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
package cache
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/redis/rueidis"
|
|
)
|
|
|
|
type (
|
|
redisOpts struct {
|
|
DSN string
|
|
}
|
|
|
|
redisCache struct {
|
|
client rueidis.Client
|
|
}
|
|
)
|
|
|
|
func NewRedisCache(o redisOpts) (Cache, error) {
|
|
client, err := rueidis.NewClient(rueidis.ClientOption{
|
|
InitAddress: []string{o.DSN},
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &redisCache{
|
|
client: client,
|
|
}, nil
|
|
}
|
|
|
|
func (c *redisCache) Add(ctx context.Context, key string) error {
|
|
// Without NX it will overwrite any existing KEY
|
|
cmd := c.client.B().Set().Key(key).Value("true").Build()
|
|
return c.client.Do(ctx, cmd).Error()
|
|
}
|
|
|
|
func (c *redisCache) Remove(ctx context.Context, key string) error {
|
|
cmd := c.client.B().Del().Key(key).Build()
|
|
return c.client.Do(ctx, cmd).Error()
|
|
}
|
|
|
|
func (c *redisCache) Exists(ctx context.Context, keys ...string) (bool, error) {
|
|
cmd := c.client.B().Exists().Key(keys...).Build()
|
|
res, err := c.client.Do(ctx, cmd).AsBool()
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
func (c *redisCache) Size(ctx context.Context) (int64, error) {
|
|
cmd := c.client.B().Dbsize().Build()
|
|
return c.client.Do(ctx, cmd).AsInt64()
|
|
}
|