时间:2021-07-01 10:21:17 帮助过:3人阅读
2.hsetnx
设置hash field为指定值,如果key不存在,则先创建。如果存在返回0.
redis 127.0.0.1:6379> hsetnx user:001 name wangwu (integer) 0 redis 127.0.0.1:6379> hget user:001 name "lisi"
3,hmset
同时设置 hash的多个field
redis 127.0.0.1:6379> hmset myhash field1 hello field2 world OK redis 127.0.0.1:6379> hget myhash field1 "hello" redis 127.0.0.1:6379> hget myhash field2 "world" redis 127.0.0.1:6379>
4 hget
获取指定的hash field
5. hmget
获取全部指定的hash field
redis 127.0.0.1:6379> hmset myhash field1 hello field2 world OK redis 127.0.0.1:6379> hget myhash field1 "hello" redis 127.0.0.1:6379> hget myhash field2 "world" redis 127.0.0.1:6379> hmget myhash field1 field2 1) "hello" 2) "world"
6. hincrby
指定hash field加上给定值。
redis 127.0.0.1:6379> hset myhash age 1 (integer) 1 redis 127.0.0.1:6379> hget myhash age "1" redis 127.0.0.1:6379> hincrby myhash age 8 (integer) 9 redis 127.0.0.1:6379> hget myhash age "9"
7. hexists
测试指定的field是否存在。
redis 127.0.0.1:6379> hexists myhash age (integer) 1
8 hlen
返回指定hash的field数量
redis 127.0.0.1:6379> hlen myhash (integer) 3
9. hdel
删除指定hash的field
redis 127.0.0.1:6379> hdel myhash field1 (integer) 1
10. hkeys
返回hash的所有field
redis 127.0.0.1:6379> hkeys myhash 1) "field2" 2) "age"
11. hgetall
获取某个hash中全部的 field及value.
redis 127.0.0.1:6379> hgetall myhash 1) "field2" 2) "world" 3) "age" 4) "9"
深入浅出Redis03使用Redis数据库(hashes类型)
标签: