package redis import ( redisdb "github.com/gomodule/redigo/redis" ) /* * 存值 * key 域 * value 值 * 2021/08/31 */ func SAdd(key string, value interface{}) (int64, error) { c := GetConn() reply, err := c.Do("SADD", key, value) CloseConn(c) if err != nil { return 0, err } else { return redisdb.Int64(reply, nil) } } /* * 删除hash值 */ func SRem(key, value interface{}) (int64, error) { c := GetConn() reply, err := c.Do("SREM", key, value) CloseConn(c) if err != nil { return 0, err } else { return redisdb.Int64(reply, nil) } } /** * 集合键是否存在 * key 域 * field 名 */ func SIsmember(key, value interface{}) (int64, error) { c := GetConn() reply, err := c.Do("SISMEMBER", key, value) CloseConn(c) if err != nil { return 0, err } else { return redisdb.Int64(reply, nil) } } /** * 集合成员数量 */ func SCard(key interface{}) (int64, error) { c := GetConn() reply, err := c.Do("SCard", key) CloseConn(c) if err != nil { return 0, err } else { return redisdb.Int64(reply, nil) } } //hash取值,返回[]byte func SMembers(key string) ([]byte, error) { c := GetConn() ret, err := c.Do("SMEMBERS", key) reply := make([]byte, 0) if err == nil { reply, err = redisdb.Bytes(ret, err) } CloseConn(c) return reply, err }