37 lines
872 B
Go
37 lines
872 B
Go
// Package diagram provide diagram data structure and operation
|
|
package diagram
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/redis/go-redis/v9"
|
|
)
|
|
|
|
// RedisClient define struct to accessing redis data that does not require the use of distributed locks
|
|
type RedisClient struct {
|
|
Client *redis.Client
|
|
}
|
|
|
|
// NewRedisClient define func of new redis client instance
|
|
func NewRedisClient() *RedisClient {
|
|
return &RedisClient{
|
|
Client: GetRedisClientInstance(),
|
|
}
|
|
}
|
|
|
|
// QueryByZRangeByLex define func to query real time data from redis zset
|
|
func (rc *RedisClient) QueryByZRangeByLex(ctx context.Context, key string, size int64) ([]redis.Z, error) {
|
|
client := rc.Client
|
|
args := redis.ZRangeArgs{
|
|
Key: key,
|
|
Start: 0,
|
|
Stop: size,
|
|
ByScore: false,
|
|
ByLex: false,
|
|
Rev: false,
|
|
Offset: 0,
|
|
Count: 0,
|
|
}
|
|
return client.ZRangeArgsWithScores(ctx, args).Result()
|
|
}
|