SREM

2020-04-16  本文已影响0人  NotFoundW

SREM

移除集合中一个或者多个元素,返回被移除的元素个数

Command

$ redis-cli.exe -h 127.0.0.1 -p 6379
127.0.0.1:6379> sadd s1 1 2 3 4
(integer) 4
127.0.0.1:6379> srem s1 3 4
(integer) 2
127.0.0.1:6379> smembers s1
1) "1"
2) "2"

Code

func srem(c redis.Conn) {
    defer c.Do("DEL", "s1")
    c.Do("SADD", "s1", 1, 2, 3, 4)
    removeCount, err := c.Do("SREM", "s1", 3, 4)
    if err != nil {
        colorlog.Error(err.Error())
        return
    }
    fmt.Println("The number of removed members is:", removeCount)
    remainingMembers, _ := redis.Strings(c.Do("SMEMBERS", "s1"))
    fmt.Println("The remaining members are as following:")
    for _, v := range remainingMembers {
        fmt.Println(v)
    }
}

Output

$ go run main.go 
The number of removed members is: 2
The remaining members are as following:
1
2
上一篇下一篇

猜你喜欢

热点阅读