redis hash命令操作

/*********redis hash命令操作 **********/
1.删除一个或多个hash域
HDEL key field [field ...]
summary: Delete one or more hash fields
since: 2.0.0
127.0.0.1:6379> HDEL hash1 name
(integer) 1

2.判断一个域是否存在
HEXISTS key field
summary: Determine if a hash field exists
since: 2.0.0
127.0.0.1:6379> HEXISTS hash1 name
(integer) 0 #不存在返回0
127.0.0.1:6379> HEXISTS hash1 name2
(integer) 1 #存在返回1

3.获取一个hash域
HGET key field
summary: Get the value of a hash field
since: 2.0.0
127.0.0.1:6379> HGET hash1 name2
"name22"

4.获取hash中所有的域和值
HGETALL key
summary: Get all the fields and values in a hash
since: 2.0.0
127.0.0.1:6379> HGETALL hash1
1) "name"  #field名
2) "jing"  #value值
3) "name2" #field名
4) "jing2" #value值
5) "name3" #field名
6) "jing3" #value值

5.增加域的值(如果是int型),增加increment
HINCRBY key field increment
summary: Increment the integer value of a hash field by the given number
since: 2.0.0

6.增加域的值(float型),增加increment
HINCRBYFLOAT key field increment
summary: Increment the float value of a hash field by the given amount
since: 2.6.0
127.0.0.1:6379> HSET hash1 num1 10
(integer) 1
127.0.0.1:6379> HINCRBY hash1 num1 2
(integer) 12

7.获取hash的所有域
HKEYS key
summary: Get all the fields in a hash
since: 2.0.0
127.0.0.1:6379> HKEYS hash1
1) "name2"
2) "name3"
3) "num1"

8.获取hash中域的数据
HLEN key
summary: Get the number of fields in a hash
since: 2.0.0
127.0.0.1:6379> HLEN hash1
(integer) 3

9.获取所有给定域的值
HMGET key field [field ...]
summary: Get the values of all the given hash fields
since: 2.0.0
127.0.0.1:6379> HMGET hash1 name2 num1
1) "name22"
2) "12"

10.设置多个hash域对应多个hash值
HMSET key field value [field value ...]
summary: Set multiple hash fields to multiple values
since: 2.0.0
127.0.0.1:6379> HMSET hash1 num2 12 name4 jing4 num3 33
OK
127.0.0.1:6379> HGETALL hash1
 1) "name2"
 2) "name22"
 3) "name3"
 4) "name33"
 5) "num1"
 6) "12"
 7) "num2"
 8) "12"
 9) "name4"
10) "jing4"
11) "num3"
12) "33"

11.设置hash域的字符串值
HSET key field value
summary: Set the string value of a hash field
since: 2.0.0

12.只有当该域不存在时,设置hash的域的值
HSETNX key field value
summary: Set the value of a hash field, only if the field does not exist
since: 2.0.0

13.获取hash的所有值
HVALS key
summary: Get all the values in a hash
since: 2.0.0

127.0.0.1:6379> HVALS hash1
1) "name22"
2) "name33"
3) "12"
4) "12"
5) "jing4"
6) "33"

时间: 2024-10-02 08:13:26

redis hash命令操作的相关文章

Redis——常用命令操作

 一,启动   Centos6       进入到redis安装目录: cd redis-2.8.17     进入src目录: cd src     启动server:  ./redis-server    使用配置文件启动: ./redis-serverredis.conf      Ubuntu 启动server:redis-server 启动客户端:redis-cli    Windows   redis-cli.exe-h 127.0.0.1 -p 6379 二,使用命令对Redis基

redis sorted_set 命令操作

score 是set排序的值,越大越在前 1.添加 成员到sorted_set中,并设置score ZADD key score member [score member ...] summary: Add one or more members to a sorted set, or update its score if it already exists since: 1.2.0 127.0.0.1:6379> zadd sset1 2 val4 (integer) 1 2. 查询sort

redis set命令操作

1.添加一个或多个成员到set SADD key member [member ...] summary: Add one or more members to a set since: 1.0.0 127.0.0.1:6379> sadd set1 val1 val2 val3 (integer) 3 2.获取一个set的成员数量 SCARD key summary: Get the number of members in a set since: 1.0.0 127.0.0.1:6379>

redis list命令操作

1.将值追加到列表 RPUSH key value [value ...] summary: Append one or multiple values to a list since: 1.0.0 127.0.0.1:6379> RPUSH mylist value1 value2 value3 (integer) 3 2.获取列表的长度 LLEN key summary: Get the length of a list since: 1.0.0 127.0.0.1:6379> llen

redis transaction和connection命令操作

/*********** redis transaction命令操作 **********/ 1. DISCARD - summary: Discard all commands issued after MULTI since: 2.0.0 EXEC - summary: Execute all commands issued after MULTI since: 1.2.0 MULTI - summary: Mark the start of a transaction block sinc

redis server和scripting 命令操作

/********* redis server命令操作 *************/ BGREWRITEAOF - summary: Asynchronously rewrite the append-only file since: 1.0.0 BGSAVE - summary: Asynchronously save the dataset to disk since: 1.0.0 CLIENT GETNAME - summary: Get the current connection na

redis命令操作之generic和string.java

redis是键值对的内存数据库,属于Nosql范畴 登录redis自带的客户端 #redis-cli 127.0.0.1:6379> 1.设置redis 键值对 > set foo bar  #设置键foo的值为"bar" OK #设置成功 2.获得redis 键值对 > get foo #根据键获得值 "bar" #返回的结果 3.删除键值对  127.0.0.1:6379> del foo foo2 foo3 #删除键值对,可删除多个 (

第2讲 Redis常用命令与高级应用

目录 一.redis数据类型 5. sorted sets类型和操作 二.Redis常用命令 1.键值相关命令 2.服务器相关命令 三. redis高级应用 1. 给redis服务器设置密码 2.持久化 3.主从备份 一.redis数据类型 5. sorted sets类型和操作 sorted set是set的一个升级版本,它给集合中每个元素都定义一个分数,集合中的元素按照其分数排序. 1) zadd 键 分数1 值1 [分数2 值2-] 该命令添加指定的成员到key对应的有序集合中,每个成员都

redis常用命令、常见错误、配置技巧等分享_Redis

1. redis查看当前所有的key 复制代码 代码如下: KEYS * 2. 查看当前redis的配置信息 复制代码 代码如下: CONFIG GET * 3. MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis