mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-04 00:10:25 +08:00
feat: 新增pgsql数据操作&redis集群操作
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
package rediscli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/go-redis/redis"
|
||||
"github.com/go-redis/redis/v8"
|
||||
)
|
||||
|
||||
var cli *redis.Client
|
||||
@@ -19,7 +20,7 @@ func GetCli() *redis.Client {
|
||||
|
||||
// get key value
|
||||
func Get(key string) string {
|
||||
val, err := cli.Get(key).Result()
|
||||
val, err := cli.Get(context.TODO(), key).Result()
|
||||
switch {
|
||||
case err == redis.Nil:
|
||||
fmt.Println("key does not exist")
|
||||
@@ -33,32 +34,32 @@ func Get(key string) string {
|
||||
|
||||
// set key value
|
||||
func Set(key string, val string, expiration time.Duration) {
|
||||
cli.Set(key, val, expiration)
|
||||
cli.Set(context.TODO(), key, val, expiration)
|
||||
}
|
||||
|
||||
func HSet(key string, field string, val interface{}) {
|
||||
cli.HSet(key, field, val)
|
||||
cli.HSet(context.TODO(), key, field, val)
|
||||
}
|
||||
|
||||
// hget
|
||||
func HGet(key string, field string) string {
|
||||
val, _ := cli.HGet(key, field).Result()
|
||||
val, _ := cli.HGet(context.TODO(), key, field).Result()
|
||||
return val
|
||||
}
|
||||
|
||||
// hget
|
||||
func HExist(key string, field string) bool {
|
||||
val, _ := cli.HExists(key, field).Result()
|
||||
val, _ := cli.HExists(context.TODO(), key, field).Result()
|
||||
return val
|
||||
}
|
||||
|
||||
// hgetall
|
||||
func HGetAll(key string) map[string]string {
|
||||
vals, _ := cli.HGetAll(key).Result()
|
||||
vals, _ := cli.HGetAll(context.TODO(), key).Result()
|
||||
return vals
|
||||
}
|
||||
|
||||
// hdel
|
||||
func HDel(key string, fields ...string) int {
|
||||
return int(cli.HDel(key, fields...).Val())
|
||||
return int(cli.HDel(context.TODO(), key, fields...).Val())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user