redis study concluded (a)

A, redis installation

1, to see if there install gcc tcl compiler environment

Gcc (GNU C Compiler) under the GNU Linux system is launched powerful, superior performance, multi-platform compiler, GNU is one of the representative works. gcc compiler is executable on a variety of hardware platforms super compiler that efficiency compared with the general average efficiency compiler to 20% to 30%.
Gcc compiler capable of C, C ++ language source program, the Department of stylized sequence and the target program to compile and link into an executable file, if not given the name of the executable file, gcc will generate a file named a.out. In the Linux system, the executable file is no uniform suffix, the file system from the properties of the executable file and to distinguish non-executable files. The gcc is to distinguish between categories of input files by extension, let's introduce part of the agreed rules gcc followed.

TCL (Tool Command Language) tool scripting language, is a language package in Linux.

View installation command: whereis gcc tcl

Installation command: yum -y install gcc tcl

2, the installation package redis upload and decompress

3, the manual installation package build and install the make && make PREFIX = / opt / xxx / redis install (installation directory can be arbitrarily designated)

4, configuration scripts directory executable files, ensure the implementation of the script can be executed under any directory

we + / etc / profile

After completion of configuration environment variable, reads the configuration file (the configuration file is a compilation of course) source / etc / profile

5, install redis memory database server, and execute found in the directory install-server.sh /software/redis-2.8.18/utils

./install-server.sh execute this command

During the installation you can set redis external communications port, default is 6379

/etc/redis/6379.conf redis is an in-memory database, with its own instance, each port represents an instance of the current database server has its own configuration file /etc/redis/6379.conf, examples and port number is one to one, one example when after installation, the port number on needs change, create multiple instances may allow

/var/log/redis_6379.log redis log storage directory

/ Var / lib / redis / 6379: redis persistent storage directory data

/ Opt / xxx / redis / bin / redis-server installation directory of the executable file (this directory can be found after the environment variable configuration)

# ---- ¥ above steps to install the redis server ¥ --- #

View server startup, run the command: redis-server -h 

View redis client initiates related commands: redis-cli -h

 

Creating redis client commands:

redis-cli  

redis supported data types: strings, lists, hash, collection, ordered set, HyperLogLog, all the data are in accordance with the data type kv key-value pairs to be stored

Supported data string manner: a, the basic operation when the string operations, additional interception set, get, append ,,,

b, the value type of computing

c, calculated bitmaps

nx --not exists 

xx - only exists when it is operated

A plurality of disposable key combination:

mset k1 a k2 b k3 c

mget ....

Setting the survival time of a key :

expire key seconds

Check the time remaining :

TTL key

PTTL key

key is present but not set TTL, returns -1 key exists, but also the lifetime, returns the remaining seconds or milliseconds had this key is present, but is dead, returns -2

View of a key length : STRLEN key

See a key data type : type key OBJECT encoding key (see the underlying data structure stored)

Calculation of the key value data : INCR k3 INCRBY key number (specified growth step)

Returns the old value and set the new value : GETSET KEY VALUE

FIG key value of the bits is calculated : SETBIT key offset value 

.offset offset. Starting from 0

Check the location of a key value in the first occurrence of : BITPOS key value

bit bit operation : BITOP and k3 k1 k2 (for k1, k2 with the operation, the result of the operation and then placed into the k3)

Statistics on the number of strings all bit to 1: bitCount KEY [the START] [the END]

Note: You can create an unlimited number of instances in redis database, but each instance the number of database operations can be 16 

FLUSHALL: This command will clear all current data database instances under the following

FLUSHDB: only clear all the data in the current database

Different login database: Redis-cli -n 2

 

List lists, arrays

1, implemented based Linked list 2, 3 of the element is a string type, a list of head and tail deletions fast, slow intermediate additions and deletions, additions and deletions element is the norm

4, the element 5 can be repeated to occur, it can contain up to 2 ^ 32-1 elements

command:

Command flow:

Block B block, blocking Lleft R right left and right X exists: exists before the implementation of

Around or pressed into the head and tail elements: String set key "abc"

LPUSH key value  [value.......]

LPUSHX key value 

RPUSH key value [value.....]

RPUSHX key value

list along with a queue, stack, arrays, blocking queue of all the features

Gets the position of elements: LINDEX key index

Setting specifies the location of elements: LSETkey index value

The number of list length, elements: LLEN key LRANGE key 0 -1 

 

Count start removing elements from a list of times equal to the value of the head, LIST can be repeated: LREM key count value 

count> 0: Header search starting from the end of the table, with the value equal to the removal elements, the number of count

count <0: starting from the end of the header to the table search, the value of the removed elements is equal to the number of the absolute value of the count

Removal element outside the specified range: LTRIM key start stop 

An insert data at the specified location: LINSERT key before / after value1 value2 

Blocking: If the pop-up list does not exist or is empty, it will clog 

Timeout is set to 0, that is permanently blocked, you know that there is data to eject

If multiple clients over the obstruction to the same list, using the principle of FIRST SERVICE IN FIRSY, first come first served

Or about the head and tail blocked or pop elements:

BLPOP key [key....] timeout

BRPOP key [key....] timeout

From one end of the list pop-up blocking element is pressed into the head of another list:

BRPOPLPUSH source destination timeout

 

hash Hash:

map the key field and an associated value of the composition, and the value field is a string of data

A hash key contain up to 2 ^ 32-1

Providing a single field: HSET key field value 

A plurality of fields: HMSET key field value 

Returns the number of fields: HLEN key

Determine whether the field is present: HEXISTS key exists 

hash purpose: to save memory space for each to create a bond, he will create some information (such as the type, the last time the key chant access this key, etc.) Additional management is the key

Therefore, there are more database inside the key, redis database server spent in the additional management information storage memory terms will be more, CPU spent key management database will be more floating-point increments on the value of the calculated field 

set set: unordered, deduplication, the element of type String

Increasing one or more elements: SADD key number (if existing elements, is automatically ignored)

Removes an element: SREM key member (element is not present when the automatic ignored)

Returns to combine all the elements included: SMEMBERS key (if the collection Too many elements, for example, one million, needs to traverse, may cause obstruction server, bad production environment should be avoided)

Checks if the given element is present in the collection: SISMEMBER key member 

Returns a collection of the specified random number of elements: SRANDMEMBER key [count]

If the count is positive and is less than the base set, then the command returns a count array contains the elements, elements of the array are different. If the count is greater than equal to the set base, then return the entire collection

Returns the number of elements of the set: Results SCARD key saves the key information is recorded inside the collection length, it is not necessary to traverse

Randomly removes and returns the element is removed from the collection: SPOP key

The set of mobile elements from the source to the target set: SMOVE source destination member

Operation set collection 

Difference set SDIFF key [key ...] removed with their other set intersect a portion from the first set

SDIFFSTORE destination key [key ......], the difference between the target key set result is stored in the 

Intersection: SINTER key [key .....], all taking set intersection portion 

SINTERSTORE destination key[key....]

并集: SUNION key [key....]

sortedSet ordered collection:

Similar set collection, ordered, deduplication, the element is a string type, each element is associated with a floating-point score (Score), and in ascending order arranged according to score, score may be the same

Increasing one or more elements: ZADD key score member [score member ....]

Removing one or more elements: ZREM key member [member .....]

Show scores: ZSCORE key member 

Increase or decrease the score: ZINCRBY key increment member 

increment is to reduce the negative 

Returns the element's rank (index)

ZRANK key member

Returns the elements in reverse order of ranking: ZREVRANK key member

Returns the index of the specified range of elements: ZRANGE key start stop [WITHSCORES], if the same score, then sorted according to the lexicographic order

According to default score from small to large, from largest to smallest score if needed, use ZREVRANGE 

Returns the index range of elements: ZREVRANGE key start stop

Returns the specified value range element: ZRANGEBYSCORE key min max [withscores] [limit offset count]

Back to default score belongs among [min, max], the elements arranged in ascending order of score, score same lexicographic

LIMIT on behalf of the offset skip number of elements, count is the return of several, similar to mysql

Use parentheses, modify the interval open interval

Returns the specified value range elements: Key ZREVRANGEBYSCORE min max [withscores] [COUNT limit offset]

Removes the specified position range of elements: ZREMRANGEBYRANK key start stop 

Removes the specified value range of elements: ZREMRANGEBYSCORE key min max 

Returns the number of elements in the set: ZCARD key

Union:

ZUNIONSTORE destination numkeys key [key...] [WEIGHTS weight] [aggregate sum|min|max]

numkeys: Specifies the number key, you must

weights options, set key corresponding to the previous corresponding key each score must be multiplied by the weight

AGGREGATE option, and specify the result set aggregation

sum: The sum of the score value as a result of all the elements of a set value of the focus score member 

交集: ZINTERSTORE destination numbers key [key....] [weights weight]

 

Guess you like

Origin www.cnblogs.com/wcgstudy/p/11136057.html