redis命令学习

redis web 在线测试版 http://try.redis.io/

CommandReference

Every command name links to a specific wiki page describing the behavior of the command.Every command name links to a specific wiki page describing the behavior of the command.

Categorized Command List

Connection handling

CommandParametersDescription
QUIT-close the connection
AUTHpasswordsimple password authentication if enabled

Commands operating on all value types

CommandParametersDescription
EXISTSkeytest if a key exists
DELkeydelete a key
TYPEkeyreturn the type of the value stored at key
KEYSpatternreturn all the keys matching a given pattern
RANDOMKEY-return a random key from the key space
RENAMEoldname newnamerename the old key in the new one, destroying the newname key if it already exists
RENAMENXoldname newnamerename the oldname key tonewname, if thenewname key does not already exist
DBSIZE-return the number of keys in the current db
EXPIRE-set a time to live in seconds on a key
PERSIST-remove the expire from a key
TTL-get the time to live in seconds of a key
SELECTindexSelect the DB with the specified index
MOVEkey dbindexMove the key from the currently selected DB to thedbindex DB
FLUSHDB-Remove all the keys from the currently selected DB
FLUSHALL-Remove all the keys from all the databases

Commands operating on string values

CommandParametersDescription
SETkey valueSet a key to a string value
GETkeyReturn the string value of the key
GETSETkey valueSet a key to a string returning the old value of the key
SETNXkey valueSet a key to a string value if the key does not exist
SETEXkey time valueSet+Expire combo command
SETBITkey offset valueSet bit at offset to value
GETBITkey offsetReturn bit value at offset
MSETkey1 value1 key2 value2 ...keyN valueNSet multiple keys to multiple values in a single atomic operation
MSETNXkey1 value1 key2 value2 ...keyN valueNSet multiple keys to multiple values in a single atomic operation if none of the keys already exist
MGETkey1 key2 ... keyNMulti-get, return the strings values of the keys
INCRkeyIncrement the integer value of key
INCRBYkey integerIncrement the integer value of key by integer
DECRkeyDecrement the integer value of key
DECRBYkey integerDecrement the integer value of key by integer
APPENDkey valueAppend the specified string to the string stored at key
SUBSTRkey start endReturn a substring of a larger string

Commands operating on lists

CommandParametersDescription
RPUSHkey valueAppend an element to the tail of the List value at key
LPUSHkey valueAppend an element to the head of the List value at key
LLENkeyReturn the length of the List value at key
LRANGEkey start endReturn a range of elements from the List at key
LTRIMkey start endTrim the list at key to the specified range of elements
LINDEXkey indexReturn the element at index position from the List at key
LSETkey index valueSet a new value as the element at index position of the List at key
LREMkey count valueRemove the first-N, last-N, or all the elements matching value from the List at key
LPOPkeyReturn and remove (atomically) the first element of the List at key
RPOPkeyReturn and remove (atomically) the last element of the List at key
BLPOPkey1 key2 ... keyN timeoutBlocking LPOP
BRPOPkey1 key2 ... keyN timeoutBlocking RPOP
RPOPLPUSHsrckey dstkeyReturn and remove (atomically) the last element of the source List stored atsrckey and push the same element to the destination List stored atdstkey
BRPOPLPUSHsrckey dstkeyLike RPOPLPUSH but blocking of source key is empty

Commands operating on sets

CommandParametersDescription
SADDkey memberAdd the specified member to the Set value at key
SREMkey memberRemove the specified member from the Set value at key
SPOPkeyRemove and return (pop) a random element from the Set value at key
SMOVEsrckey dstkey memberMove the specified member from one Set to another atomically
SCARDkeyReturn the number of elements (the cardinality) of the Set at key
SISMEMBERkey memberTest if the specified value is a member of the Set at key
SINTERkey1 key2 ... keyNReturn the intersection between the Sets stored at key1, key2, ..., keyN
SINTERSTOREdstkey key1 key2 ... keyNCompute the intersection between the Sets stored at key1, key2, ..., keyN, and store the resulting Set at dstkey
SUNIONkey1 key2 ... keyNReturn the union between the Sets stored at key1, key2, ..., keyN
SUNIONSTOREdstkey key1 key2 ... keyNCompute the union between the Sets stored at key1, key2, ..., keyN, and store the resulting Set at dstkey
SDIFFkey1 key2 ... keyNReturn the difference between the Set stored at key1 and all the Sets key2, ..., keyN
SDIFFSTOREdstkey key1 key2 ... keyNCompute the difference between the Set key1 and all the Sets key2, ..., keyN, and store the resulting Set at dstkey
SMEMBERSkeyReturn all the members of the Set value at key
SRANDMEMBERkeyReturn a random member of the Set value at key

Commands operating on sorted zsets (sorted sets)

CommandParametersDescription
ZADDkey score memberAdd the specified member to the Sorted Set value at key or update the score if it already exist
ZREMkey memberRemove the specified member from the Sorted Set value at key
ZINCRBYkey increment memberIf the member already exists increment its score byincrement, otherwise add the member settingincrement as score
ZRANKkey memberReturn the rank (or index) or member in the sorted set at key, with scores being ordered from low to high
ZREVRANKkey memberReturn the rank (or index) or member in the sorted set at key, with scores being ordered from high to low
ZRANGEkey start endReturn a range of elements from the sorted set at key
ZREVRANGEkey start endReturn a range of elements from the sorted set at key, exactly like ZRANGE, but the sorted set is ordered in traversed in reverse order, from the greatest to the smallest score
ZRANGEBYSCOREkey min maxReturn all the elements with score >= min and score <= max (a range query) from the sorted set
ZCOUNTkey min maxReturn the number of elements with score >= min and score <= max in the sorted set
ZCARDkeyReturn the cardinality (number of elements) of the sorted set at key
ZSCOREkey elementReturn the score associated with the specified element of the sorted set at key
ZREMRANGEBYRANKkey min maxRemove all the elements with rank >= min and rank <= max from the sorted set
ZREMRANGEBYSCOREkey min maxRemove all the elements with score >= min and score <= max from the sorted set
ZUNIONSTORE / ZINTERSTOREdstkey N key1 ... keyN WEIGHTSw1 ...wN AGGREGATE SUM|MIN|MAXPerform a union or intersection over a number of sorted sets with optional weight and aggregate

Commands operating on hashes

CommandParametersDescription
HSETkey field valueSet the hash field to the specified value. Creates the hash if needed.
HGETkey fieldRetrieve the value of the specified hash field.
HMGETkey field1 ... fieldNGet the hash values associated to the specified fields.
HMSETkey field1 value1 ... fieldN valueNSet the hash fields to their respective values.
HINCRBYkey field integerIncrement the integer value of the hash atkey onfield withinteger.
HEXISTSkey fieldTest for existence of a specified field in a hash
HDELkey fieldRemove the specified field from a hash
HLENkeyReturn the number of items in a hash.
HKEYSkeyReturn all the fields in a hash.
HVALSkeyReturn all the values in a hash.
HGETALLkeyReturn all the fields and associated values in a hash.

Sorting

CommandParametersDescription
SORTkey BY pattern LIMITstart end GETpattern ASC|DESC ALPHASort a Set or a List accordingly to the specified parameters

Transactions

CommandParametersDescription
MULTI/EXEC/DISCARD/WATCH/UNWATCH-Redis atomic transactions

Publish/Subscribe

CommandParametersDescription
SUBSCRIBE/UNSUBSCRIBE/PUBLISH-Redis Public/Subscribe messaging paradigm implementation

Persistence control commands

CommandParametersDescription
SAVE-Synchronously save the DB on disk
BGSAVE-Asynchronously save the DB on disk
LASTSAVE-Return the UNIX time stamp of the last successfully saving of the dataset on disk
SHUTDOWN-Synchronously save the DB on disk, then shutdown the server
BGREWRITEAOF-Rewrite the append only file in background when it gets too big

Remote server control commands

CommandParametersDescription
INFO-Provide information and statistics about the server
MONITOR-Dump all the received requests in real time
SLAVEOF-Change the replication settings
CONFIG-Configure a Redis server at runtime
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值