首页 > 其他分享 >数据类型

数据类型

时间:2022-12-14 21:44:55浏览次数:28  
标签:set name since 数据类型 summary user key

字符串

列表

集合

有序集合

哈希

bit

  1. string

    修改操作 示例 解释
    set SET name wangendao
    SET name wangendao ex 30 30s 后删除
    SET name wangendao px 30000 30000ms 后删除
    SET name "lisi" NX 如果key 不存在,则执行赋值操作
    SET name "wangwu" XX 如果key 存在,则执行赋值操作
    setnx SETNX name "wangendao" 如果key 不存在,则执行赋值操作。功能等同 SET name "lisi" NX
    setex SETEX name 30 wangendao 设置key 超时时间。功能等同 SET name wangendao ex 30
    psetex PSETEX name wangendao px 30000 设置key 超时时间。功能等同SET name wangendao px 30000
    append APPEND name 123 追加内容Append a value to a key
    mset MSET {p}age 30 {p}name wangendao 设置多个k-v。如果是reids cluster 需要使用 {p} 其中p是所有key的公共部分用于hash
    msetnx MSETNX {p}age 30 {p}name wangendao 设置多个k-v。如果key不存在
    setrange SETRANGE name 2 wangendao 从指定位置开始,用新值覆盖
    incr INCR age 整数自增Increment
    decr decr age 整数自减Decrement
    incrby incrby age 100 整数自增,指定步长
    decrby decrby age 100 整数自减,指定步长
    incrbyfloat decrbyfloat age 100.1
    del del name
    取值操作 示例 解释
    get
    getset getset name lisi 返回旧值,并设置新值。功能等同于 get name set name lisi
    mget MGET {p}name {p}age 获取多个k-v。如果是reids cluster 需要使用 {p} 其中p是所有key的公共部分用于hash
    getrange GETRANGE name 0 1 切片取值
    strlen STRLEN name 取字符串长度
    substr SUBSTR name 0 -1 截取字符串,应该被getrange 替代了
  2. list

     BLPOP key [key ...] timeout
      summary: Remove and get the first element in a list, or block until one is available
      since: 2.0.0
    
      BRPOP key [key ...] timeout
      summary: Remove and get the last element in a list, or block until one is available
      since: 2.0.0
    
      BRPOPLPUSH source destination timeout
      summary: Pop a value from a list, push it to another list and return it; or block until one is available
      since: 2.2.0
    
      LINDEX key index
      summary: Get an element from a list by its index
      since: 1.0.0
    
      LINSERT key BEFORE|AFTER pivot value
      summary: Insert an element before or after another element in a list
      since: 2.2.0
    
      LLEN key
      summary: Get the length of a list
      since: 1.0.0
    
      LPOP key
      summary: Remove and get the first element in a list
      since: 1.0.0
    
      LPUSH key value [value ...]
      summary: Prepend one or multiple values to a list
      since: 1.0.0
    
      LPUSHX key value
      summary: Prepend a value to a list, only if the list exists
      since: 2.2.0
    
      LRANGE key start stop
      summary: Get a range of elements from a list
      since: 1.0.0
    
      LREM key count value
      summary: Remove elements from a list
      since: 1.0.0
    
      LSET key index value
      summary: Set the value of an element in a list by its index
      since: 1.0.0
    
      LTRIM key start stop
      summary: Trim a list to the specified range
      since: 1.0.0
    
      RPOP key
      summary: Remove and get the last element in a list
      since: 1.0.0
    
      RPOPLPUSH source destination
      summary: Remove the last element in a list, prepend it to another list and return it
      since: 1.2.0
    
      RPUSH key value [value ...]
      summary: Append one or multiple values to a list
      since: 1.0.0
    
      RPUSHX key value
      summary: Append a value to a list, only if the list exists
      since: 2.2.0
    
    
    修改操作 示例 解释
    lpush LPUSH user user01 user02 user03 在列表user左侧加入值
    rpush RPUSH user user01 user02 user03
    lpushx LPUSHX user user05 列表需要提前存在
    rpushx `RPUSHX user user05
    lpop LPOP user 左侧取值并从列表删除
    rpop RPOP user
    rpoplpush RPOPLPUSH user user01 Remove the last element in a list, prepend it to another list and return it
    brpop BRPOP user 5 阻塞等待列表数据
    blpop BLPOP user 5
    取值操作 示例 解释
    lindex LINDEX user 0
    llen LLEN user 返回长度
    LRANGE LRANGE user 0 -1 获取列表内容
    lpop LPOP user 先进后出
    rpop RPOP user 先进先出
    lrem LREM user 2 user02 删除列表user中的2个 user02 元素
    LREM user 0 user01 删除列表user中所有的 user01
    LREM user -1 user04 删除列表user中 最右侧的user04
    lset LSET user 0 wangendao 修改0号索引位置的值
    lindex LINDEX user 0 获取user 列表0号索引的值
  3. set

    127.0.0.1:6380> help @set
    
      SADD key member [member ...]
      summary: Add one or more members to a set
      since: 1.0.0
    
      SCARD key
      summary: Get the number of members in a set
      since: 1.0.0
    
      SDIFF key [key ...]
      summary: Subtract multiple sets
      since: 1.0.0
    
      SDIFFSTORE destination key [key ...]
      summary: Subtract multiple sets and store the resulting set in a key
      since: 1.0.0
    
      SINTER key [key ...]
      summary: Intersect multiple sets
      since: 1.0.0
    
      SINTERSTORE destination key [key ...]
      summary: Intersect multiple sets and store the resulting set in a key
      since: 1.0.0
    
      SISMEMBER key member
      summary: Determine if a given value is a member of a set
      since: 1.0.0
    
      SMEMBERS key
      summary: Get all the members in a set
      since: 1.0.0
    
      SMOVE source destination member
      summary: Move a member from one set to another
      since: 1.0.0
    
      SPOP key [count]
      summary: Remove and return one or multiple random members from a set
      since: 1.0.0
    
      SRANDMEMBER key [count]
      summary: Get one or multiple random members from a set
      since: 1.0.0
    
      SREM key member [member ...]
      summary: Remove one or more members from a set
      since: 1.0.0
    
      SSCAN key cursor [MATCH pattern] [COUNT count]
      summary: Incrementally iterate Set elements
      since: 2.8.0
    
      SUNION key [key ...]
      summary: Add multiple sets
      since: 1.0.0
    
      SUNIONSTORE destination key [key ...]
      summary: Add multiple sets and store the resulting set in a key
      since: 1.0.0
    
    页面uv
    127.0.0.1:6379[1]> SADD pg:uv user01 user02 user03 
    (integer) 3
    127.0.0.1:6379[1]> SCARD pg:uv
    (integer) 3
    
  4. zset

    127.0.0.1:6380> help @sorted_set
    
      ZADD key [NX|XX] [CH] [INCR] 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
    
      ZCARD key
      summary: Get the number of members in a sorted set
      since: 1.2.0
    
      ZCOUNT key min max
      summary: Count the members in a sorted set with scores within the given values
      since: 2.0.0
    
      ZINCRBY key increment member
      summary: Increment the score of a member in a sorted set
      since: 1.2.0
    
      ZINTERSTORE destination numkeys key [key ...] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX]
      summary: Intersect multiple sorted sets and store the resulting sorted set in a new key
      since: 2.0.0
    
      ZLEXCOUNT key min max
      summary: Count the number of members in a sorted set between a given lexicographical range
      since: 2.8.9
    
      ZRANGE key start stop [WITHSCORES]
      summary: Return a range of members in a sorted set, by index
      since: 1.2.0
    
      ZRANGEBYLEX key min max [LIMIT offset count]
      summary: Return a range of members in a sorted set, by lexicographical range
      since: 2.8.9
    
      ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]
      summary: Return a range of members in a sorted set, by score
      since: 1.0.5
    
      ZRANK key member
      summary: Determine the index of a member in a sorted set
      since: 2.0.0
    
      ZREM key member [member ...]
      summary: Remove one or more members from a sorted set
      since: 1.2.0
    
      ZREMRANGEBYLEX key min max
      summary: Remove all members in a sorted set between the given lexicographical range
      since: 2.8.9
    
      ZREMRANGEBYRANK key start stop
      summary: Remove all members in a sorted set within the given indexes
      since: 2.0.0
    
      ZREMRANGEBYSCORE key min max
      summary: Remove all members in a sorted set within the given scores
      since: 1.2.0
    
      ZREVRANGE key start stop [WITHSCORES]
      summary: Return a range of members in a sorted set, by index, with scores ordered from high to low
      since: 1.2.0
    
      ZREVRANGEBYLEX key max min [LIMIT offset count]
      summary: Return a range of members in a sorted set, by lexicographical range, ordered from higher to lower strings.
      since: 2.8.9
    
      ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]
      summary: Return a range of members in a sorted set, by score, with scores ordered from high to low
      since: 2.2.0
    
      ZREVRANK key member
      summary: Determine the index of a member in a sorted set, with scores ordered from high to low
      since: 2.0.0
    
      ZSCAN key cursor [MATCH pattern] [COUNT count]
      summary: Incrementally iterate sorted sets elements and associated scores
      since: 2.8.0
    
      ZSCORE key member
      summary: Get the score associated with the given member in a sorted set
      since: 1.2.0
    
      ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX]
      summary: Add multiple sorted sets and store the resulting sorted set in a new key
      since: 2.0.0
    
    127.0.0.1:6379> ZADD salary 400 user01
    (integer) 1
    127.0.0.1:6379> ZADD salary 600 user02
    (integer) 1
    
    127.0.0.1:6379> ZRANGE salary 0 100 withscores
    1) "user01"
    2) "400"
    3) "user02"
    4) "600"
    

    MULTI开启一个事务

    EXEC执行事务

    127.0.0.1:6379> MULTI
    OK
    127.0.0.1:6379> ZINCRBY salary 100 user01
    QUEUED
    127.0.0.1:6379> ZINCRBY salary -100 user02
    QUEUED
    127.0.0.1:6379> EXEC
    1) "500"
    2) "500
    
    127.0.0.1:6379> ZRANGE salary 0 100 withscores
    1) "user01"
    2) "500"
    3) "user02"
    4) "500"
    
  5. hash

      HDEL key field [field ...]
      summary: Delete one or more hash fields
      since: 2.0.0
    
      HEXISTS key field
      summary: Determine if a hash field exists
      since: 2.0.0
    
      HGET key field
      summary: Get the value of a hash field
      since: 2.0.0
    
      HGETALL key
      summary: Get all the fields and values in a hash
      since: 2.0.0
    
      HINCRBY key field increment
      summary: Increment the integer value of a hash field by the given number
      since: 2.0.0
    
      HINCRBYFLOAT key field increment
      summary: Increment the float value of a hash field by the given amount
      since: 2.6.0
    
      HKEYS key
      summary: Get all the fields in a hash
      since: 2.0.0
    
      HLEN key
      summary: Get the number of fields in a hash
      since: 2.0.0
    
      HMGET key field [field ...]
      summary: Get the values of all the given hash fields
      since: 2.0.0
    
      HMSET key field value [field value ...]
      summary: Set multiple hash fields to multiple values
      since: 2.0.0
    
      HSCAN key cursor [MATCH pattern] [COUNT count]
      summary: Incrementally iterate hash fields and associated values
      since: 2.8.0
    
      HSET key field value
      summary: Set the string value of a hash field
      since: 2.0.0
    
      HSETNX key field value
      summary: Set the value of a hash field, only if the field does not exist
      since: 2.0.0
    
      HSTRLEN key field
      summary: Get the length of the value of a hash field
      since: 3.2.0
    
      HVALS key
      summary: Get all the values in a hash
      since: 2.0.0
    
    hash-max-ziplist-entries 512
    hash-max-ziplist-value 64
    

    hset

    127.0.0.1:6379> hset user:1 name wangendao
    127.0.0.1:6379> hset user:1 age 30
    127.0.0.1:6379> hset user:1 mail XXXX.qq.com
    

    hget

    127.0.0.1:6379> hget user:1 name
    "wangendao"
    127.0.0.1:6379> hget user:1 age
    "30"
    127.0.0.1:6379> hget user:1 mail
    "XXXX.qq.com"
    127.0.0.1:6379
    

    hgetall

    127.0.0.1:6379> HGETALL user:1
    1) "name"
    2) "wangendao"
    3) "age"
    4) "30"
    5) "mail"
    6) "XXXX.qq.com"
    

    hmset

    127.0.0.1:6379> hmset user:1 name wangendao age 30 mail xxx.qq.com
    OK
    127.0.0.1:6379> HMGET user:1 name age mail
    1) "wangendao"
    2) "30"
    3) "xxx.qq.com"
    

    HEXISTS

    127.0.0.1:6379> EXISTS user:1
    (integer) 1
    127.0.0.1:6379> HEXISTS user:1 name
    (integer) 1
    127.0.0.1:6379> HEXISTS user:1 name1
    (integer) 0
    
  6. bitmap

标签:set,name,since,数据类型,summary,user,key
From: https://www.cnblogs.com/wangend/p/16983671.html

相关文章

  • python学习笔记整理01(变量、数据类型、容器、输入和输出、运算符)
    一、变量二、数据类型三、容器1介绍2字符串3列表4元组5字典6容器的通用方法四、输入和输出五、运算符 一、变量1.介绍①含......
  • JavaScript的数据类型详解
    数据类型JavaScript中有5种简单数据类型(也称为基本数据类型):Undefined、Null、Boolean、Number和String。还有1种复杂数据类型——Object,Object本质上是由一组无序的名值对......
  • C++基础篇之什么是数据类型
       ......
  • #yyds干货盘点#JS数据类型判断几种方式
     一般JS检测数据类型有4种方法:typeof、constructor、instanceof和Object.prototype.toString,相信大家也对这几种判断很熟悉,下面我再罗列两种,供各位使用。​typeof:检测基......
  • C# 反序列化,支持基本数据类型处理
    C#反序列化,支持基本数据类型处理代码///<summary>///优化对基本数据的支持///</summary>///<paramname="obj"></param>......
  • 第六天 数据类型
    开篇注意点python的编码规范(PEP8)1.单行注释如果跟在代码后面 警号跟代码空两格注释内容与警号空一格2.符号左右两边如果有数据/变量 两边都应该空一格3.先看赋值......
  • js判断数据类型的五种方法
    1.typeof可以判断数据类型,它返回表示数据类型的字符串(返回结果只能包括number,boolean,string,function,object,undefined);可以使用typeof判断变量是否存在(如if(typeofa!......
  • [转]MySQL 中 Blob 和 Text 数据类型详解
    原文地址:https://mp.weixin.qq.com/s/SjaCSkcjT0rcO1n41RuEcA前言:前面文章我们介绍过一些常用数据类型的用法,比如int、char、varchar等。一直没详细介绍过blob及te......
  • 这次我把Redis数据类型写出了花✿❀?~~~
    1.String字符串是Redis最基本的数据类型,不仅所有key都是字符串类型,其它几种数据类型构成的元素也是字符串。注意字符串的长度不能超过512M。1.1编码方式(encoding)......
  • 这次我把Redis数据类型写出了花✿❀
    1.String字符串是Redis最基本的数据类型,不仅所有key都是字符串类型,其它几种数据类型构成的元素也是字符串。注意字符串的长度不能超过512M。1.1编码方式(encoding)......