【redis】map类型命令简述

全部命令如下:

复制代码
127.0.0.1:6379> help @string

  APPEND key value
  summary: Append a value to a key
  since: 2.0.0

  DECR key
  summary: Decrement the integer value of a key by one
  since: 1.0.0

  DECRBY key decrement
  summary: Decrement the integer value of a key by the given number
  since: 1.0.0

  GET key
  summary: Get the value of a key
  since: 1.0.0

  GETDEL key
  summary: Get the value of a key and delete the key
  since: 6.2.0

  GETEX key [EX seconds|PX milliseconds|EXAT unix-time-seconds|PXAT unix-time-milliseconds|PERSIST]
  summary: Get the value of a key and optionally set its expiration
  since: 6.2.0

  GETRANGE key start end
  summary: Get a substring of the string stored at a key
  since: 2.4.0

  GETSET key value
  summary: Set the string value of a key and return its old value
  since: 1.0.0

  INCR key
  summary: Increment the integer value of a key by one
  since: 1.0.0

  INCRBY key increment
  summary: Increment the integer value of a key by the given amount
  since: 1.0.0

  INCRBYFLOAT key increment
  summary: Increment the float value of a key by the given amount
  since: 2.6.0

  LCS key1 key2 [LEN] [IDX] [MINMATCHLEN len] [WITHMATCHLEN]
  summary: Find longest common substring
  since: 7.0.0

  MGET key [key ...]
  summary: Get the values of all the given keys
  since: 1.0.0

  MSET key value [key value ...]
  summary: Set multiple keys to multiple values
  since: 1.0.1

  MSETNX key value [key value ...]
  summary: Set multiple keys to multiple values, only if none of the keys exist
  since: 1.0.1

  PSETEX key milliseconds value
  summary: Set the value and expiration in milliseconds of a key
  since: 2.6.0

  SET key value [NX|XX] [GET] [EX seconds|PX milliseconds|EXAT unix-time-seconds|PXAT unix-time-milliseconds|KEEPTTL]
  summary: Set the string value of a key
  since: 1.0.0

  SETEX key seconds value
  summary: Set the value and expiration of a key
  since: 2.0.0

  SETNX key value
  summary: Set the value of a key, only if the key does not exist
  since: 1.0.0

  SETRANGE key offset value
  summary: Overwrite part of a string at key starting at the specified offset
  since: 2.2.0

  STRLEN key
  summary: Get the length of the value stored in a key
  since: 2.2.0

  SUBSTR key start end
  summary: Get a substring of the string stored at a key
  since: 1.0.0

示例如下:
hset :hset key field value,将field:value构成的键值对放入key对应的hash表中。
hmset :hmset key field1 value1 field2 value2...批量将键值对放入key对应的hash表中。
hget:hget key field,取出key对应的hash表中某个field对应的value。

复制代码
127.0.0.1:6379> hset jack name testJack
(integer) 1
127.0.0.1:6379> hmset jack salary 1000 city shanghai
OK
127.0.0.1:6379> hget jack name
"testJack"

hkeys :hkeys key,列出key对应的hash表中所有的fields。
hvals :hvals key,列出key对应的hash表中所有的value。
hgetall:hgetall key,列出key对应的hash表中所有的field和value

复制代码
127.0.0.1:6379> hkeys jack
1) "name"
2) "salary"
3) "city"
127.0.0.1:6379> hvals jack
1) "testJack"
2) "1000"
3) "shanghai"
127.0.0.1:6379> hgetall jack
1) "name"
2) "testJack"
3) "salary"
4) "1000"
5) "city"
6) "shanghai"

hincrbyfloat:hincrbyfloat key field value。将key对应的hash表中field对应的值与value进行浮点运算

复制代码
127.0.0.1:6379> HINCRBYFLOAT jack age -1.2
"19.3"
127.0.0.1:6379> hgetall jack
1) "name"
2) "testJack"
3) "salary"
4) "1000"
5) "city"
6) "shanghai"
7) "age"
8) "19.3"

redis中的hash表可以抽象为一个对象,通过hgetall可以取出该对象所有数据。

相关推荐
LiRuiJie19 分钟前
深入剖析MySQL锁机制,多事务并发场景锁竞争
数据库·mysql
2501_9153743528 分钟前
Faiss向量数据库全面解析:从原理到实战
数据库·faiss
睡觉待开机34 分钟前
0. MySQL在Centos 7环境安装
数据库·mysql·centos
2501_9153743534 分钟前
Faiss vs Milvus 深度对比:向量数据库技术选型指南
数据库·milvus·faiss
傻啦嘿哟1 小时前
Python 数据分析与可视化实战:从数据清洗到图表呈现
大数据·数据库·人工智能
cookqq2 小时前
mongodb源码分析session异步接受asyncSourceMessage()客户端流变Message对象
数据库·sql·mongodb·nosql
呼拉拉呼拉2 小时前
Redis故障转移
数据库·redis·缓存·高可用架构
什么都想学的阿超2 小时前
【Redis系列 04】Redis高可用架构实战:主从复制与哨兵模式从零到生产
数据库·redis·架构
pp-周子晗(努力赶上课程进度版)2 小时前
【MySQL】视图、用户管理、MySQL使用C\C++连接
数据库·mysql
斯特凡今天也很帅2 小时前
clickhouse常用语句汇总——持续更新中
数据库·sql·clickhouse