user
name | lisi |
age | 30 |
height | 175 |
public class User { private String name; private int age; private int height; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public int getHeight() { return height; } public void setHeight(int height) { this.height = height; } }
key就相当于类名,field就相当于类中的成员变量,value就是set进去的值
hset key field value 作用: 把key中 filed域的值设为value 注:如果没有field域,直接添加,如果有,则覆盖原field域的值127.0.0.1:6379> hset user1 name lisi(integer) 1127.0.0.1:6379> hset user1 age 28(integer) 1127.0.0.1:6379> hset user1 height 175(integer) 1
hmset key field1 value1 [field2 value2 field3 value3 ......fieldn valuen] 作用: 设置field1->N 个域, 对应的值是value1->N (对应PHP理解为 $key = array(file1=>value1, field2=>value2 ....fieldN=>valueN))\127.0.0.1:6379> hmset user2 name wangwu age 23 height 160OK
hget key field 作用: 返回key中field域的值127.0.0.1:6379> hget user1 name"lisi"
hmget key field1 field2 fieldN 作用: 返回key中field1 field2 fieldN域的值127.0.0.1:6379> hmget user1 name age1) "lisi"2) "28"
hgetall key 作用:返回key中,所有域与其值127.0.0.1:6379> hgetall user11) "name"2) "lisi"3) "age"4) "28"5) "height"6) "175"
hdel key field 作用: 删除key中 field域127.0.0.1:6379> hgetall user11) "name"2) "lisi"3) "age"4) "28"5) "height"6) "175"127.0.0.1:6379> hdel user1 age(integer) 1127.0.0.1:6379> hgetall user11) "name"2) "lisi"3) "height"4) "175"
hlen key 作用: 返回key中元素的数量127.0.0.1:6379> hlen user1(integer) 2127.0.0.1:6379> hlen user2(integer) 3
hexists key field 作用: 判断key中有没有field域127.0.0.1:6379> hexists user1 age(integer) 0127.0.0.1:6379> hexists user1 name(integer) 1
hincrby key field value 作用: 是把key中的field域的值增长整型值value127.0.0.1:6379> hincrby user2 age 10(integer) 33127.0.0.1:6379> hget user2 age"33"
hincrbyfloat key field value 作用: 是把key中的field域的值增长浮点值value
127.0.0.1:6379> hincrbyfloat user2 age 0.5
"33.5"
hkeys key 作用: 返回key中所有的field127.0.0.1:6379> hkeys user21) "name"2) "age"3) "height"
kvals key 作用: 返回key中所有的value127.0.0.1:6379> hvals user21) "wangwu"2) "33"3) "160"