HVALS

作者: NotFoundW | 来源:发表于2020-04-15 16:27 被阅读0次

HVALS

  1. 如果hash表有字段,则返回所有字段对应的值
  2. 如果key不存在,则返回空列表

Command

$ redis-cli.exe -h 127.0.0.1 -p 6379
127.0.0.1:6379> hset snake name kobe
(integer) 1
127.0.0.1:6379> hset snake number 24
(integer) 1
127.0.0.1:6379> hvals snake
1) "kobe"
2) "24"
127.0.0.1:6379> del snake
(integer) 1
127.0.0.1:6379> hvals snake
(empty list or set)

Code

func Hvals(c redis.Conn) {
    // If hash table is existing and has field(s), will return the values of all the fields.
    c.Do("HSET", "snake", "name", "kobe")
    c.Do("HSET", "snake", "number", "24")
    fields, err := redis.Strings(c.Do("HVALS", "snake"))
    if err != nil {
        colorlog.Error(err.Error())
        return
    }
    for i, v := range fields {
        fmt.Println("value of field", i, "is:", v)
    }
    //  If key doesn't exist, will return an empty list.
    c.Do("DEL", "snake")
    fields, err = redis.Strings(c.Do("HVALS", "snake"))
    if err != nil {
        colorlog.Error(err.Error())
        return
    }
    fmt.Println("If key doesn't exist, will return an empty list. List's length is:", len(fields))
}

Output

$ go run main.go
value of field 0 is: kobe
value of field 1 is: 24
If key doesn't exist, will return an empty list. List's length is: 0

相关文章

  • HVALS

    HVALS 如果hash表有字段,则返回所有字段对应的值 如果key不存在,则返回空列表 Command Code...

  • Redis hash表

    hash表 练习命令使用,具体如下: hset hmset hgetall hkeys hvals hget hm...

  • rides学习练习笔记

    HMSET 批量新增哈希表的字段HMGET 批量查询哈希表的字段HKEYS 获取哈希表所有的字段名HVALS 获取...

网友评论

      本文标题:HVALS

      本文链接:https://www.haomeiwen.com/subject/kkocvhtx.html