Redis基本数据类型命令汇总

Stella981
• 阅读 546

前言

  前阶段写Redis客户端作为学习和了解Redis Protocol,基本上把Strintg,List,Hash,Set,SortedSet五种基础类型的命令都写完了,本篇进行总结,也相当于复习一遍了。

STRING 命令

  • SET KEY VALUE

    *3\r\n$3\r\nSET\r\n$6\r\nset_20\r\n$4\r\ntest\r\n

    +OK

  • GET KEY

    *2\r\n$3\r\nGET\r\n$6\r\nget_21\r\n

    $9 testValue

  • APPEND KEY VALUE

    *3\r\n$6\r\nAPPEND\r\n$9\r\nappend_29\r\n$3\r\n789\r\n

    :9

  • MSET KEY VALUE1 VALUE2

    *9\r\n$4\r\nMSET\r\n$4\r\nkey1\r\n$6\r\nvalue1\r\n$4\r\nkey2\r\n$6\r\nvalue2\r\n$4\r\nkey3\r\n$6\r\nvalue3\r\n$4\r\nkey4\r\n$6\r\nvalue4\r\n

    +OK

  • SETRANGE KEY OFFSET VALUE

    *4\r\n$8\r\nSETRANGE\r\n$11\r\nsetrange_30\r\n$1\r\n3\r\n$6\r\n123456\r\n

    :9

  • STRLEN KEY

    *2\r\n$6\r\nSTRLEN\r\n$9\r\nstrlen_31\r\n

    :6

  • MSETNX KEY VALUE1 VALUE2

    *9\r\n$6\r\nMSETNX\r\n$7\r\nkey1111\r\n$6\r\nvalue1\r\n$7\r\nkey2222\r\n$6\r\nvalue2\r\n$7\r\nkey3333\r\n$6\r\nvalue3\r\n$7\r\nkey4444\r\n$6\r\nvalue4\r\n

    :1

  • SETNX KEY VALUE

    *3\r\n$5\r\nSETNX\r\n$8\r\nsetNxKey\r\n$6\r\nvalue1\r\n

    :0

  • PSETEX KEY EXPIRE VALUE

    *4\r\n$6\r\nPSETEX\r\n$8\r\nsetex_32\r\n$4\r\n2000\r\n$4\r\ntest\r\n

    +OK

  • MGET KEY1 KEY2

    *4\r\n$4\r\nMGET\r\n$4\r\nkey1\r\n$4\r\nkey2\r\n$4\r\nkey3\r\n

    *3 $6 value1 $6 value2 $6 value3

  • SETBIT KEY INDEX VALUE

    *4\r\n$6\r\nSETBIT\r\n$9\r\nsetbit_33\r\n$1\r\n6\r\n$1\r\n1\r\n

    :0

  • GETBIT KEY INDEX

    *3\r\n$6\r\nGETBIT\r\n$9\r\ngetbit_34\r\n$1\r\n5\r\n

    :1

  • GETSET KEY VALUE

    *3\r\n$6\r\nGETSET\r\n$9\r\ngetset_35\r\n$7\r\nnewtest\r\n

    $4 test

  • GETRANGE KEY START END

    *4\r\n$8\r\nGETRANGE\r\n$11\r\ngetrange_36\r\n$1\r\n0\r\n$1\r\n5\r\n

    $6 test12

  • INCR KEY

    *2\r\n$4\r\nINCR\r\n$7\r\nincr_24\r\n

    :1

  • INCRBY KEY VALUE

    *3\r\n$6\r\nINCRBY\r\n$9\r\nincrby_25\r\n$2\r\n10\r\n

    :10

  • DECR KEY

    *2\r\n$4\r\nDECR\r\n$7\r\ndecr_26\r\n

    :-1

  • DECRBY KEY VALUE

    *3\r\n$6\r\nDECRBY\r\n$9\r\ndecrby_27\r\n$1\r\n1\r\n

    :-1

LIST 命令

  • LPUSH KEY VALUE1 VALUE2

    *5\r\n$5\r\nLPUSH\r\n$8\r\nlpush_53\r\n$5\r\npanzi\r\n$8\r\nxiaoming\r\n$8\r\nzhangsan\r\n

    :3

  • BLPOP KEY TIMEOUT

    *3\r\n$5\r\nBLPOP\r\n$8\r\nblpop_54\r\n$1\r\n2\r\n

    *2 $8 blpop_54 $6 value4

  • BRPOP KEY TIMEOUT

    *3\r\n$5\r\nBRPOP\r\n$8\r\nbrpop_55\r\n$1\r\n2\r\n

    *2 $8 brpop_55 $6 value1

  • LINDEX KEY INDEX

    *3\r\n$6\r\nLINDEX\r\n$9\r\nlindex_56\r\n$1\r\n2\r\n

    $6 value2

  • LLEN KEY

    *2\r\n$4\r\nLLEN\r\n$7\r\nllen_57\r\n

    :4

  • LPOP KEY

    *2\r\n$4\r\nLPOP\r\n$7\r\nlpop_58\r\n

    $6 value4

  • RPOP KEY

    *2\r\n$4\r\nRPOP\r\n$7\r\nrpop_59\r\n

    $6 value1

  • RPUSH KEY VALUE1 VALUE2

    *5\r\n$5\r\nRPUSH\r\n$8\r\nrpush_60\r\n$5\r\npanzi\r\n$8\r\nxiaoming\r\n$8\r\nzhangsan\r\n

    :3

  • RPUSHX KEY VALUE

    *3\r\n$6\r\nRPUSHX\r\n$9\r\nrpushx_61\r\n$5\r\ntest1\r\n

    :5

  • LPUSHX KEY VALUE

    *3\r\n$6\r\nLPUSHX\r\n$9\r\nlpushx_62\r\n$5\r\npanzi\r\n

    :0

  • LTRIM KEY START END

    *4\r\n$5\r\nLTRIM\r\n$8\r\nltrim_63\r\n$1\r\n0\r\n$1\r\n2\r\n

    +OK

  • LSET KEY INDEX VALUE

    *4\r\n$4\r\nLSET\r\n$7\r\nlset_64\r\n$1\r\n0\r\n$8\r\nvalueset\r\n

    +OK

  • LREM KEY COUNT VALUE

    *4\r\n$4\r\nLREM\r\n$7\r\nlrem_65\r\n$1\r\n1\r\n$6\r\nvalue4\r\n

    :1

  • LRANGE KEY START END

    *4\r\n$6\r\nLRANGE\r\n$9\r\nlrange_66\r\n$1\r\n0\r\n$1\r\n2\r\n

    *3 $6 value4 $6 value3 $6 value2

  • LINSERT KEY BEFORE/AFTER PIVOT VALUE

    *5\r\n$7\r\nLINSERT\r\n$10\r\nlinsert_67\r\n$6\r\nBEFORE\r\n$6\r\nvalue1\r\n$9\r\npreValue1\r\n

    :5

  • RPOPLPUSH KEY DESTINATION

    *3\r\n$9\r\nRPOPLPUSH\r\n$12\r\nrpoplpush_68\r\n$15\r\nrpoplpush_68des\r\n

    $6 value1

  • BRPOPLPUSH KEY DESTINATION TIMEOUT

    *4\r\n$10\r\nBRPOPLPUSH\r\n$13\r\nbrpoplpush_69\r\n$16\r\nbrpoplpush_69des\r\n$1\r\n2\r\n

    $6 value1

HASH 命令

  • HSETNX KEY FIELD VALUE

    *4\r\n$6\r\nHSETNX\r\n$8\r\nhsetnx_2\r\n$8\r\nhsetnx_1\r\n$2\r\nv1\r\n

    :1

  • HSET KEY FIELD VALUE

    *4\r\n$4\r\nHSET\r\n$5\r\nuser2\r\n$2\r\nf1\r\n$2\r\nv1\r\n

    :1

  • HLEN KEY

    *2\r\n$4\r\nHLEN\r\n$5\r\nuser2\r\n

    :3

  • HKEYS KEY

    *2\r\n$5\r\nHKEYS\r\n$5\r\nuser1\r\n

    *3 $2 f1 $2 f2 $2 f3

  • HMGET KEY FIELD1 FIELD2

    *4\r\n$5\r\nHMGET\r\n$5\r\nuser3\r\n$2\r\nf1\r\n$2\r\nf2\r\n

    *2 $2 v1 $2 v2

  • HMSET KEY FIELD1 VALUE1 FIELD2 VALUE2

    *10\r\n$5\r\nHMSET\r\n$5\r\nuser4\r\n$4\r\nkey1\r\n$6\r\nvalue1\r\n$4\r\nkey2\r\n$6\r\nvalue2\r\n$4\r\nkey3\r\n$6\r\nvalue3\r\n$4\r\nkey4\r\n$6\r\nvalue4\r\n

    +OK

  • HVALS KEY

    *2\r\n$5\r\nHVALS\r\n$5\r\nuser5\r\n

    *3 $2 v1 $2 v2 $2 v3

  • HEXISTS KEY FIELD

    *3\r\n$7\r\nHEXISTS\r\n$11\r\nhashexist_3\r\n$8\r\nexistkey\r\n

    :1

  • HDEL KEY FIELD

    *3\r\n$4\r\nHDEL\r\n$6\r\nhdel_4\r\n$6\r\ndelkey\r\n

    :1

  • HGET KEY FIELD

    *3\r\n$4\r\nHGET\r\n$9\r\nhashget_5\r\n$6\r\ngetkey\r\n

    $5 value

  • HGETALL

    *2\r\n$7\r\nHGETALL\r\n$9\r\nhgetall_7\r\n

    *6 $2 f1 $2 v1 $2 f2 $2 v2 $2 f3 $2 v3

  • HINCRBY KEY FIELD INCREMENT

    *4\r\n$7\r\nHINCRBY\r\n$9\r\nhincrby_8\r\n$2\r\nt1\r\n$1\r\n1\r\n

    :1

SET 命令

  • SADD KEY MEMBER1 MEMBER2

    *8\r\n$4\r\nSADD\r\n$10\r\nsinter2_41\r\n$1\r\n1\r\n$1\r\n2\r\n$1\r\n3\r\n$1\r\n4\r\n$1\r\n5\r\n$1\r\n6\r\n

    :6

  • SINTERSTORE DESTINATION KEY1 KEY2

    *4\r\n$11\r\nSINTERSTORE\r\n$10\r\nsinter3_42\r\n$10\r\nsinter2_41\r\n$10\r\nsinter1_40\r\n

    :4

  • SUNIONSTORE DESTINATION KEY1 KEY2

    *4\r\n$11\r\nSUNIONSTORE\r\n$10\r\nsunion2_45\r\n$9\r\nsunion_43\r\n$10\r\nsunion1_44\r\n

    :8

  • SSCAN KEY CURSOR MATCH COUNT

    7\r\n$5\r\nSSCAN\r\n$8\r\nsscan_46\r\n$1\r\n0\r\n$5\r\nMATCH\r\n$2\r\nh\r\n$5\r\nCOUNT\r\n$1\r\n1\r\n

    *2 $1 2 *1 $2 hi

  • SPOP KEY

    *2\r\n$4\r\nSPOP\r\n$7\r\nspop_47\r\n

    $-1

  • SISMEMBER KEY MEMBER

    *3\r\n$9\r\nSISMEMBER\r\n$12\r\nsismember_48\r\n$1\r\n1\r\n

    :1

  • SREM KEY MEMBER1 MEMBER2

    *3\r\n$4\r\nSREM\r\n$7\r\nsrem_49\r\n$1\r\n1\r\n

    :1

  • SINTER KEY1 KEY2

    *3\r\n$6\r\nSINTER\r\n$10\r\nsinter2_51\r\n$10\r\nsinter1_50\r\n

    *4 $1 1 $1 2 $1 3 $1 4

  • SUNION KEY1 KEY2

    *3\r\n$6\r\nSUNION\r\n$9\r\nsunion_52\r\n$10\r\nsunion1_53\r\n

    *8 $1 1 $1 2 $1 3 $1 4 $1 5 $1 6 $1 7 $1 8

  • SRANDMEMBER KEY COUNT

    *3\r\n$11\r\nSRANDMEMBER\r\n$15\r\nsrandmembers_54\r\n$1\r\n6\r\n

    *5 $1 1 $1 2 $1 3 $1 4 $1 5

  • SMEMBERS KEY

    *2\r\n$8\r\nSMEMBERS\r\n$11\r\nsmembers_55\r\n

    *3 $1 1 $1 2 $1 3

  • SCARD KEY

    *2\r\n$5\r\nSCARD\r\n$8\r\nscard_58\r\n

    :4

  • SDIFF KEY1 KEY2

    *3\r\n$5\r\nSDIFF\r\n$9\r\nsdiff2_60\r\n$9\r\nsdiff1_59\r\n

    *2 $1 5 $1 6

  • SMOVE SOURCE DESTINATION MEMBER

    *4\r\n$5\r\nSMOVE\r\n$8\r\nsmove_61\r\n$9\r\nsmove1_62\r\n$1\r\n1\r\n

    :1

  • SDIFFSTORE DESTINATION KEY1 KEY2

    *4\r\n$10\r\nSDIFFSTORE\r\n$9\r\nsdiff3_66\r\n$9\r\nsdiff2_65\r\n$9\r\nsdiff1_64\r\n

    :2

SORTED SET 命令

  • ZRANGEBYLEX

    *4\r\n$11\r\nZRANGEBYLEX\r\n$15\r\nzrangebylex_236\r\n$1\r\n-\r\n$7\r\n[value3\r\n

    *3 $6 value1 $6 value2 $6 value3

  • ZCOUNT

    *4\r\n$6\r\nZCOUNT\r\n$10\r\nzcount_238\r\n$1\r\n1\r\n$1\r\n5\r\n

    :5

  • ZRANGEBYSCORE

    *4\r\n$13\r\nZRANGEBYSCORE\r\n$17\r\nzrangebyscore_239\r\n$1\r\n1\r\n$1\r\n3\r\n

    *3 $6 value1 $6 value2 $6 value3

  • ZREVRANGEBYSCORE

    *8\r\n$16\r\nZREVRANGEBYSCORE\r\n$20\r\nzrevrangebyscore_241\r\n$1\r\n3\r\n$1\r\n1\r\n$10\r\nWITHSCORES\r\n$5\r\nLIMIT\r\n$1\r\n0\r\n$1\r\n2\r\n

    *4 $6 value3 $1 3 $6 value2 $1 2

  • ZRANK

    *3\r\n$5\r\nZRANK\r\n$9\r\nzrank_244\r\n$6\r\nvalue4\r\n

    $-1

  • ZREVRANGEBYSCORE

    *4\r\n$16\r\nZREVRANGEBYSCORE\r\n$17\r\nzrangebyscore_246\r\n$4\r\n+inf\r\n$4\r\n-inf\r\n

    *10 $7 value10 $6 value9 $6 value8 $6 value7 $6 value6 $6 value5 $6 value4 $6 value3 $6 value2 $6 value1

  • ZREVRANK

    *3\r\n$8\r\nZREVRANK\r\n$11\r\nzrevank_248\r\n$6\r\nvalue4\r\n

    :6

  • ZRANGEBYSCORE

    *8\r\n$13\r\nZRANGEBYSCORE\r\n$17\r\nzrangebyscore_250\r\n$3\r\n1.0\r\n$3\r\n3.0\r\n$10\r\nWITHSCORES\r\n$5\r\nLIMIT\r\n$1\r\n0\r\n$1\r\n2\r\n

    *4 $6 value1 $1 1 $6 value2 $1 2

  • ZREMRANGEBYSCORE

    *4\r\n$16\r\nZREMRANGEBYSCORE\r\n$20\r\nzremrangebyscore_251\r\n$3\r\n1.0\r\n$3\r\n3.0\r\n

    :3

  • ZREM

    *3\r\n$4\r\nZREM\r\n$8\r\nzrem_253\r\n$4\r\ntest\r\n

    :0

  • ZRANGEBYLEX

    *7\r\n$11\r\nZRANGEBYLEX\r\n$15\r\nzrangebylex_256\r\n$7\r\n(value1\r\n$7\r\n[value3\r\n$5\r\nLIMIT\r\n$1\r\n0\r\n$1\r\n1\r\n

    *1 $6 value2

  • ZREVRANGEBYSCORE

    *8\r\n$16\r\nZREVRANGEBYSCORE\r\n$20\r\nzrevrangebyscore_257\r\n$3\r\n3.0\r\n$3\r\n1.0\r\n$10\r\nWITHSCORES\r\n$5\r\nLIMIT\r\n$1\r\n0\r\n$1\r\n2\r\n

    *4 $6 value3 $1 3 $6 value2 $1 2

  • ZRANGEBYSCORE

    *8\r\n$13\r\nZRANGEBYSCORE\r\n$17\r\nzrangebyscore_258\r\n$3\r\n1.0\r\n$3\r\n3.0\r\n$10\r\nWITHSCORES\r\n$5\r\nLIMIT\r\n$1\r\n0\r\n$1\r\n2\r\n

    *4 $6 value1 $1 1 $6 value2 $1 2

  • ZINCRBY

    *4\r\n$7\r\nZINCRBY\r\n$10\r\nzcount_262\r\n$1\r\n1\r\n$6\r\nvalue1\r\n

    $1 2

  • ZSCORE

    *3\r\n$6\r\nZSCORE\r\n$10\r\nzscore_263\r\n$6\r\nvalue1\r\n

    $-1

  • ZCARD

    *2\r\n$5\r\nZCARD\r\n$9\r\nzcard_269\r\n

    :10

  • ZRANGE

    *5\r\n$6\r\nZRANGE\r\n$10\r\nzrange_272\r\n$1\r\n1\r\n$2\r\n-1\r\n$10\r\nWITHSCORES\r\n

    *18 $6 value2 $1 2 $6 value3 $1 3 $6 value4 $1 4 $6 value5 $1 5 $6 value6 $1 6 $6 value7 $1 7 $6 value8 $1 8 $6 value9 $1 9 $7 value10 $2 10

  • ZRANGEBYSCORE

    *4\r\n$13\r\nZRANGEBYSCORE\r\n$17\r\nzrangebyscore_275\r\n$1\r\n1\r\n$1\r\n3\r\n

    *3 $6 value1 $6 value2 $6 value3

  • ZLEXCOUNT

    *4\r\n$9\r\nZLEXCOUNT\r\n$13\r\nzlexcount_281\r\n$7\r\n[value1\r\n$7\r\n[value6\r\n

    :6

  • ZRANGEBYSCORE

    *8\r\n$13\r\nZRANGEBYSCORE\r\n$17\r\nzrangebyscore_283\r\n$1\r\n1\r\n$1\r\n3\r\n$10\r\nWITHSCORES\r\n$5\r\nLIMIT\r\n$1\r\n0\r\n$1\r\n2\r\n

    *4 $6 value1 $1 1 $6 value2 $1 2

  • ZREVRANGEBYSCORE

    *8\r\n$16\r\nZREVRANGEBYSCORE\r\n$20\r\nzrevrangebyscore_285\r\n$3\r\n3.0\r\n$3\r\n1.0\r\n$10\r\nWITHSCORES\r\n$5\r\nLIMIT\r\n$1\r\n0\r\n$1\r\n2\r\n

    *4 $6 value3 $1 3 $6 value2 $1 2

  • ZRANGEBYLEX

    *4\r\n$11\r\nZRANGEBYLEX\r\n$15\r\nzrangebylex_286\r\n$7\r\n[value1\r\n$7\r\n[value3\r\n

    *3 $6 value1 $6 value2 $6 value3

  • ZRANGEBYLEX

    *7\r\n$11\r\nZRANGEBYLEX\r\n$15\r\nzrangebylex_290\r\n$7\r\n[value1\r\n$7\r\n[value3\r\n$5\r\nLIMIT\r\n$1\r\n0\r\n$1\r\n1\r\n

    *1 $6 value1

  • ZREMRANGEBYRANK

    *4\r\n$15\r\nZREMRANGEBYRANK\r\n$19\r\nzremrangebyrank_291\r\n$1\r\n1\r\n$1\r\n5\r\n

    :5

其他命令

  • DEL KEY

    *2\r\n$3\r\nDEL\r\n$6\r\ndel_19\r\n

    :1

  • EXISTS KEY

    *2\r\n$6\r\nEXISTS\r\n$9\r\nexists_18\r\n

    :1

  • SELECT

    *2\r\n$6\r\nSELECT\r\n$1\r\n1\r\n

    +OK

  • PING

    *1\r\n$4\r\nPING\r\n

    +PONG

点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
待兔 待兔
6个月前
手写Java HashMap源码
HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22
Jacquelyn38 Jacquelyn38
3年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
Stella981 Stella981
3年前
Opencv中Mat矩阵相乘——点乘、dot、mul运算详解
Opencv中Mat矩阵相乘——点乘、dot、mul运算详解2016年09月02日00:00:36 \牧野(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fme.csdn.net%2Fdcrmg) 阅读数:59593
Stella981 Stella981
3年前
KVM调整cpu和内存
一.修改kvm虚拟机的配置1、virsheditcentos7找到“memory”和“vcpu”标签,将<namecentos7</name<uuid2220a6d1a36a4fbb8523e078b3dfe795</uuid
Easter79 Easter79
3年前
Twitter的分布式自增ID算法snowflake (Java版)
概述分布式系统中,有一些需要使用全局唯一ID的场景,这种时候为了防止ID冲突可以使用36位的UUID,但是UUID有一些缺点,首先他相对比较长,另外UUID一般是无序的。有些时候我们希望能使用一种简单一些的ID,并且希望ID能够按照时间有序生成。而twitter的snowflake解决了这种需求,最初Twitter把存储系统从MySQL迁移
Wesley13 Wesley13
3年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
3年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
1年前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这