redis命令学习

来源:互联网 发布:手机淘宝降价提醒设置 编辑:程序博客网 时间:2024/06/16 03:57

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.
CommandReference: Contents
    Categorized Command List
    Connection handling
    Commands operating on all value types
    Commands operating on string values
    Commands operating on lists
    Commands operating on sets
    Commands operating on sorted zsets (sorted sets)
    Commands operating on hashes
    Sorting
    Transactions
    Publish/Subscribe
    Persistence control commands
    Remote server control commands

Categorized Command List

Connection handling

CommandParametersDescriptionQUIT-close the connectionAUTHpasswordsimple password authentication if enabled

Commands operating on all value types

CommandParametersDescriptionEXISTSkeytest if a key existsDELkeydelete a keyTYPEkeyreturn the type of the value stored at keyKEYSpatternreturn all the keys matching a given patternRANDOMKEY-return a random key from the key spaceRENAMEoldname newnamerename the old key in the new one, destroying the newname key if it already existsRENAMENXoldname newnamerename the oldname key tonewname, if thenewname key does not already existDBSIZE-return the number of keys in the current dbEXPIRE-set a time to live in seconds on a keyPERSIST-remove the expire from a keyTTL-get the time to live in seconds of a keySELECTindexSelect the DB with the specified indexMOVEkey dbindexMove the key from the currently selected DB to thedbindex DBFLUSHDB-Remove all the keys from the currently selected DBFLUSHALL-Remove all the keys from all the databases

Commands operating on string values

CommandParametersDescriptionSETkey valueSet a key to a string valueGETkeyReturn the string value of the keyGETSETkey valueSet a key to a string returning the old value of the keySETNXkey valueSet a key to a string value if the key does not existSETEXkey time valueSet+Expire combo commandSETBITkey offset valueSet bit at offset to valueGETBITkey offsetReturn bit value at offsetMSETkey1 value1 key2 value2 ...keyN valueNSet multiple keys to multiple values in a single atomic operationMSETNXkey1 value1 key2 value2 ...keyN valueNSet multiple keys to multiple values in a single atomic operation if none of the keys already existMGETkey1 key2 ... keyNMulti-get, return the strings values of the keysINCRkeyIncrement the integer value of keyINCRBYkey integerIncrement the integer value of key by integerDECRkeyDecrement the integer value of keyDECRBYkey integerDecrement the integer value of key by integerAPPENDkey valueAppend the specified string to the string stored at keySUBSTRkey start endReturn a substring of a larger string

Commands operating on lists

CommandParametersDescriptionRPUSHkey valueAppend an element to the tail of the List value at keyLPUSHkey valueAppend an element to the head of the List value at keyLLENkeyReturn the length of the List value at keyLRANGEkey start endReturn a range of elements from the List at keyLTRIMkey start endTrim the list at key to the specified range of elementsLINDEXkey indexReturn the element at index position from the List at keyLSETkey index valueSet a new value as the element at index position of the List at keyLREMkey count valueRemove the first-N, last-N, or all the elements matching value from the List at keyLPOPkeyReturn and remove (atomically) the first element of the List at keyRPOPkeyReturn and remove (atomically) the last element of the List at keyBLPOPkey1 key2 ... keyN timeoutBlocking LPOPBRPOPkey1 key2 ... keyN timeoutBlocking RPOPRPOPLPUSHsrckey dstkeyReturn and remove (atomically) the last element of the source List stored atsrckey and push the same element to the destination List stored atdstkeyBRPOPLPUSHsrckey dstkeyLike RPOPLPUSH but blocking of source key is empty

Commands operating on sets

CommandParametersDescriptionSADDkey memberAdd the specified member to the Set value at keySREMkey memberRemove the specified member from the Set value at keySPOPkeyRemove and return (pop) a random element from the Set value at keySMOVEsrckey dstkey memberMove the specified member from one Set to another atomicallySCARDkeyReturn the number of elements (the cardinality) of the Set at keySISMEMBERkey memberTest if the specified value is a member of the Set at keySINTERkey1 key2 ... keyNReturn the intersection between the Sets stored at key1, key2, ..., keyNSINTERSTOREdstkey key1 key2 ... keyNCompute the intersection between the Sets stored at key1, key2, ..., keyN, and store the resulting Set at dstkeySUNIONkey1 key2 ... keyNReturn the union between the Sets stored at key1, key2, ..., keyNSUNIONSTOREdstkey key1 key2 ... keyNCompute the union between the Sets stored at key1, key2, ..., keyN, and store the resulting Set at dstkeySDIFFkey1 key2 ... keyNReturn the difference between the Set stored at key1 and all the Sets key2, ..., keyNSDIFFSTOREdstkey key1 key2 ... keyNCompute the difference between the Set key1 and all the Sets key2, ..., keyN, and store the resulting Set at dstkeySMEMBERSkeyReturn all the members of the Set value at keySRANDMEMBERkeyReturn a random member of the Set value at key

Commands operating on sorted zsets (sorted sets)

CommandParametersDescriptionZADDkey score memberAdd the specified member to the Sorted Set value at key or update the score if it already existZREMkey memberRemove the specified member from the Sorted Set value at keyZINCRBYkey increment memberIf the member already exists increment its score byincrement, otherwise add the member settingincrement as scoreZRANKkey memberReturn the rank (or index) or member in the sorted set at key, with scores being ordered from low to highZREVRANKkey memberReturn the rank (or index) or member in the sorted set at key, with scores being ordered from high to lowZRANGEkey start endReturn a range of elements from the sorted set at keyZREVRANGEkey 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 scoreZRANGEBYSCOREkey min maxReturn all the elements with score >= min and score <= max (a range query) from the sorted setZCOUNTkey min maxReturn the number of elements with score >= min and score <= max in the sorted setZCARDkeyReturn the cardinality (number of elements) of the sorted set at keyZSCOREkey elementReturn the score associated with the specified element of the sorted set at keyZREMRANGEBYRANKkey min maxRemove all the elements with rank >= min and rank <= max from the sorted setZREMRANGEBYSCOREkey min maxRemove all the elements with score >= min and score <= max from the sorted setZUNIONSTORE / 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

CommandParametersDescriptionHSETkey 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 hashHDELkey fieldRemove the specified field from a hashHLENkeyReturn 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

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

Transactions

CommandParametersDescriptionMULTI/EXEC/DISCARD/WATCH/UNWATCH-Redis atomic transactions

Publish/Subscribe

CommandParametersDescriptionSUBSCRIBE/UNSUBSCRIBE/PUBLISH-Redis Public/Subscribe messaging paradigm implementation

Persistence control commands

CommandParametersDescriptionSAVE-Synchronously save the DB on diskBGSAVE-Asynchronously save the DB on diskLASTSAVE-Return the UNIX time stamp of the last successfully saving of the dataset on diskSHUTDOWN-Synchronously save the DB on disk, then shutdown the serverBGREWRITEAOF-Rewrite the append only file in background when it gets too big

Remote server control commands

CommandParametersDescriptionINFO-Provide information and statistics about the serverMONITOR-Dump all the received requests in real timeSLAVEOF-Change the replication settingsCONFIG-Configure a Redis server at runtime
原创粉丝点击