Redis基本数据类型命令汇总

前言

  前阶段写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
posted @ 2019-01-25 09:56  丶Pz  阅读(272)  评论(0编辑  收藏  举报