redis conventional command record

 

 

Outline

Because redis is single-threaded execution, so do not care about concurrency issues.

Simply record what redis operation command, reserved for review, go back and sort out things and other operations.

reids is stored in the form of kev-value, which value is several:

  1. String: is a simple string

  2. String list: re-ordered list

  3. String set: unordered deduplication

  4. Ordered set of strings: Ordered to heavy

  5. Hash: storing a hash table

  6. HyperLogLog: base operation, i.e., to obtain the number of elements in the weight set

Various types of storage Commands

String

Simple string stored

String Manipulation

New

  • set key value: 设置value

  • setex key 2 value: setting value, and set the expiration time of 2s

  • psetex key 2000 value: setting value, and set the expiration time of 2000ms

  • setnx key value: setting value, when the key is not present is provided

  • append key value: If the key exists, the value will fight back to the original value, or else directly

Update

  • getset key value: setting value and returns the old value

  • setrange key 2 value: update the value back to the original value of the offset fight 2

Inquire

  • get key: get value

  • getrange key 2 3: Get value of 2-3 string, index from 0, negative numbers from the back

  • strlen key: Get string length

String bulk operations

  • mset key1 value1 [key2 value2 ...]: Batch Set

  • msetnx key1 value1 [key2 value2 ...]: Bulk setting is present when the key is not covered

  • mget key1 [key2 ...]: Batch acquisition

Bit String operations

Such as setting whether reading an article, user id can be used as an offset, 1 read, 0 indicates no reading

  • getbit key offset: offset return value, 0 or 1

  • setbit key offset 1: setting the offset value

Counting operation

Simple to understand deposit numbers, because redis is single-threaded, so it can use it to anti-concurrent

  • incr key: +1, 0 absence + 1

  • incrby key 2: +2

  • incrbyfloat key 2.4: +2.4

  • decr key: -1

  • decrby key 2.4: -2.4

List

List is an ordered set of repeatable, reference may java in List

insert

  • linsert key before (after) value1 value: value inserted in front of value1 (rear), if successful, returns a list of the new length, return -1 on failure, if the list is empty, return 0

  • lpush key value1 [value2 ...]: the value into the head of the list

  • rpush key value1 [value2 ...]: the value into the tail of the list

  • lpushx key value: the value into the head of the list, if the list does not exist, the operation is invalid

  • rpushx key value: the value of the tail is inserted into the list, if the list does not exist, the operation is invalid

  • lset key 2 value: Set list index value of 2

delete

  • lrem key count value: delete the list value

    • count: The number of deleted, an integer from front to back, back to front negative, 0 Remove all

  • ltrim key 2 3: 2-3 Retains only the elements of the list, delete the remaining elements

Inquire

  • blpop key1 [key2 ...] timeout: Obtain and remove the first element of the list, blocking timeout seconds, if not get the returns nil

  • brpop key1 [key2 ...] timeout: Retrieves and removes the last element of the list, blocking

  • brpoplpush key1 key2 timeout: pop up (deleted) from the last value key1 key2 inserted into, if not get timeout seconds, returns nil

  • lpop key: pop the first element of the list

  • rpop key: pop the last element of the list

  • rpoplpush key1 key2: pop key1 last element inserted into the key2

  • lindex key 2: Get a list index for the element 2

  • llen key: get a list of length

  • lrange key 2 3: 2-3 to obtain a list of elements, and negative numbers back to front

set

Is an unordered set of deduplication, refer to the java HashSet

Update

  • sadd key value1 [value2 ...]: insert elements

  • smove key1 key2 value: the value moved from key2 key1, key1 if the value does not exist, the operation is not performed

  • srem key value1 [value2 ...]: to remove elements from the collection

Inquire

Operating a plurality of sets

  • sdiff key1 [key2 ...]: Returns a collection of all the difference set (key1 value, not in another collection 0)

  • sdiffstore newKey key1 [key2 ...]: Returns a collection of all the difference set, stores the result in newKey

  • sinter key1 [key2 ...]: Returns all intersection of the sets (each set value are re-present)

  • sinterstore newKey key1 [key2 ...]: Returns all intersection of the sets, the result is stored in the newKey

  • sunion key1 [key2 ...]: Returns the collection of all union

  • sunionstrore newKey key1 [key2 ...]: Returns a collection of all the set and the result is stored in newKey

Gets the element

  • spop key [count]: from the set of random pop-up element, if the specified count, count pop-up element

  • srandmember key [count]: get a random element from the collection, if the specified count, the count acquired elements, and spop different, this command does not remove elements

  • scard key: Gets a collection of the number of elements

  • sismember key value: to see whether the value in the collection

  • smembers key: Gets a collection of all the elements

  • the Cursor Key SSCAN [H match * ] [COUNT COUNT]: iterative elements in the collection

    • cursor: the cursor, use the command returns a new cursor as the next iteration of the cursor when the return is 0, iteration is complete

    • count: Specifies the number of elements returned, the default is 10, the number of each iteration of the acquisition may not be the same

    • match: the return of elements of screening, because it is screened after the return result, it may return empty

Ordered set

Re-ordered set is ordered to be in the reference java LindedHashSet

redis ordered collection of points for each element is provided by an associated, by sorting the score, the score when the same, by the natural order, i.e., abcd

Update

  • zadd key score1 value1 [score2 value2 ...]: Add the element, if there is an update scores

  • zincrby key 2.3 value: value of +2.3 points, if the present value is not equal to add

delete

  • zrem key value1 [value2 ...]: delete elements in the collection

  • zremrangebylex key min max: Delete the specified range of elements of the collection, (min max Reference zlexcount)

  • zremrangebyrank key 2 3: Delete the set of elements ranked 2-3

  • zremrangebyscore key min max: Delete the specified range fraction collection element, (min max Reference zlexcount)

 

Inquire

Gets the count

  • zcard key: get set size

  • zcount key 2 3: obtaining the number of points in the collection of elements 2-3

  • zlexcount key min max: Get the number of members of the collection members between the min-max

    • min :-( negative infinity), [a (a minimum of elements, closed interval), (a (open section)

    • max: + (positive infinity), [a, (a supra

Operating a plurality of sets

  • zinterstore newKey num key1 [key2 ...]: calculating a plurality of intersection of the sets, the result is stored into newKey, the result is a fractional set of elements and each element in the collection points, designated NUM set back with several

  • zunionstore newKey num key1 [key2 ...]: calculating a plurality of sets and sets, newKey store the result in the result set points for the set of elements and fractions of elements, designated NUM set back with several

Get range of elements

  • zrange key 2 3 [withscores]: Gets the collection order of the elements 2-3, the negative back to front, from small to large by score

    • withscores: Returns the fractional value

  • zrevrange key 2 3 [withscores]: Similar zrange, Score descending order

  • zrangebylex key min max [limit offset count]: Returns the specified range of elements of the collection, (min max Reference zlexcount)

    • limit offset count: refer to sql

  • zrangebyscore key min max: Returns a collection of elements specified range fraction, (min max Reference zlexcount)

  • zrevrangebyscore key max min [withscores]: Similar zrangebyscore, descending Score

Obtain information element

  • zrank key value: Returns the value rankings

  • zrevrank key value: Returns the value of the ranking, in descending score

  • zscore key value: returns the score value of

  • zscan key cursor [match h *] [count count]: iterative set, a reference parameter sscan

Hash

Storing a hash table, it simply is more kay-value pairs can be used to store object attributes

Update

  • hmset key field1 value1 [field2 value2 ...]: the batch setting key pair

  • hset key field value: set key-value pairs

  • hsetnx key field value: setting key pair, If there is already not set

  • hincrby key field 2: Field to +2

  • hincrbyfloat key field 2.4: +2.4 to field

delete

  • hdel key field1 [field2 ...]: Delete field hash table

Inquire

  • hlen key: Gets the number of fields

  • hexists key field: the hash table to see whether there are fields in field

  • hget key field: get the value of the hash table fields

  • hkeys key: Get all fields

  • hvals key: Get all values

  • hgetall key: Get all the fields and values ​​of the hash table

  • hmget key field1 [field2 ...]: Gets all the values ​​of a given field

  • Cursor Key HSCAN [match H * ] [COUNT COUNT]: iteration, the parameter reference sscan

HyperLogLog

HyperLogLog (What on earth is the name) is used to make statistical base, which is the statistical weight to a number of elements in the collection, a collection that is not used directly like?

Using a collection of words, each element is stored, For to do a lot of statistics, the cost of memory is very, HyperLogLog storage elements not directly, no matter how many elements (2 ^ 64) requires only 12KB of memory space, because of this, With this configuration does not return directly elements, wherein only count the number of elements, but only estimates can be appreciated.

  • pfadd key value1 [value2 ...]: Add the element

  • pfcount key1 [key2 ...]: Returns the base estimate, if the estimated worth and a plurality of return

  • pfmerge newKey key1 [key2 ...]: a plurality of combined into one storage in the newKey

Spoken instructions

Update

  • del key: Delete key

  • expire key 2: 2s set the expiration time for the key

  • pexpire key 2000: set the expiration time for the key 2000ms

  • expireat key timestamp: set the expiration time for the key, the specified expiration time stamp

  • pexpireat key millseconds-timestamp: expiration time set key, a timestamp milliseconds (not used)

  • persist key: remove the key expiration time

  • ttl key: acquisition of key remaining expiration time

  • pttl key: acquiring remaining expiration time in milliseconds for key

  • move key 2: 2 is moved to the library key

  • rename key newKey: Rename

  • renamenx key newKey: rename, if no operation is present newKey

Inquire

  • dump key: Returns the value of the sequence

  • exists key: to see if there is key

  • keys pattern: get in line with all the key match

    • pattern: * means all, H * beginning h, etc.

  • randomkey: random returns from the current library a key

  • type key: return data type of storage

Storehouse

    • select 1: 1 Select the library

Guess you like

Origin www.cnblogs.com/hujingnb/p/11279961.html