Database First Day

Source: Internet
Author: User
Tags bitwise memcached

Cookies
Session

client<--------------------------->server
-------------------->sessionid=[user, password]
sookie=sid<----------------------

People---------------------------------> Supermarkets (VIP)
Card [ID] pc
Cookies=id session=[Info]

Local session
Mecached Sharing Session

Using memcached to realize session sharing [networking]
How to realize shared read and write information
Modify 2.100 and 2.200, read and write information to 4.5 memcached

    1. Java---->memcached
      [Email protected] ~]# cd/root/lnmp_soft/session/
      [email protected] session]# CP *.jar/usr/local/tomcat/lib/
      Operating on Web1 and WEB2
      The biggest advantage of the jar package is that it does not have to be installed

2. Tell 2.100 and 2.200memcached on that (even which IP)


Both have to do this step
Open configuration file
Vim/usr/local/tomcat/conf/context.xml

Nosql
memcached[cache database, KV database]
Pre-allocated memory, speed
redis[cache database, KV database, persistent storage, support for more functions]
[Master/slave, cluster]
Redis 1G
Redis
Operating in 2.100 and 2.200


Last command, all the way to the carriage

2.100 Execution: Redis-benchmark
In the execution redis-cli

Set ABC "Hello word" write, overwrite
Get ABC Check

Var/lib/redis/6379/dump.rdb viewing data for a database

            

127.0.0.1:6379> Ping
PONG
127.0.0.1:6379> set string1 "Hello the word"//Set string variable
Ok
127.0.0.1:6379> get string1//view string variable
"Hello the word"
127.0.0.1:6379> set string2 "Hello" ex 5//Set string variable and set expiration time to 5 seconds
Ok
127.0.0.1:6379> get string2//view string variable
"Hello"
127.0.0.1:6379> get string2//string expires, view this value as empty
(nil)
127.0.0.1:6379> Get string1
"Hello the word"
127.0.0.1:6379> Set string1 Hello NX//Execute SET instruction only if string1 does not exist
(nil)
127.0.0.1:6379> Set string1 Hello XX//execute SET instruction only if string1 exists
Ok
127.0.0.1:6379> get string1//view the value of string1 after modification
"Hello"
127.0.0.1:6379> set string1 "Hello the World"//Modify the value of string1
Ok
127.0.0.1:6379> Get string1
"Hello the World"
127.0.0.1:6379> SetRange string1 6 "Redis"//Replace string1 value starting with 6th character
(integer) 15
127.0.0.1:6379> Get string1
"Hello Redisorld"
127.0.0.1:6379> strlen string1//Calculate the length of the string1
(integer) 15
127.0.0.1:6379> append string1 xxx//append operation to string1
(integer) 18
127.0.0.1:6379> Get string1
"Hello redisorldxxx"
127.0.0.1:6379> append string1 "xxx"
(integer) 22
127.0.0.1:6379> Get string1
"Hello redisorldxxx xxx"
127.0.0.1:6379> setbit string2 0 1//Bitwise set STRING2 value, 0 bit 1
(integer) 0
127.0.0.1:6379> setbit string2 1 1//Bitwise set STRING2 value, 1 bit 1
(integer) 0
127.0.0.1:6379> setbit string2 2 1
(integer) 0
127.0.0.1:6379> setbit string2 3 0
(integer) 0
127.0.0.1:6379> get string2//Can not view all values
"\xe0"
127.0.0.1:6379> bitcount string2//Count of 1 in string2
(integer) 3
127.0.0.1:6379> getbit string2 0//view value of string2 No. 0 bit
(integer) 1
127.0.0.1:6379> getbit string2 1//view value of string2 1th bit
(integer) 1
127.0.0.1:6379> DECR string3//decrement operation with an initial value of 0
(integer)-1
127.0.0.1:6379> DECR String3
(integer)-2
127.0.0.1:6379> DECR String3
(integer)-3
127.0.0.1:6379> DECR String3
(integer)-4
127.0.0.1:6379> DECR String3
(integer)-5
127.0.0.1:6379> set String4 10//Custom variable initial value is 10
Ok
127.0.0.1:6379> DECR String4//decrement a custom variable
(integer) 9
127.0.0.1:6379> DECR String4
(integer) 8
127.0.0.1:6379> DECR String4
(integer) 7
127.0.0.1:6379> Decrby String4 2//decrement variable by 2 operation
(integer) 5
127.0.0.1:6379> Decrby String4 2
(integer) 3
127.0.0.1:6379> Get String4
"3"
127.0.0.1:6379> set String5 "Hello the World"//Set string variable
Ok
127.0.0.1:6379> getrange string5 0 4//view string No. 0 to 4th bit
"Hello"
127.0.0.1:6379> GetRange string5-3-1//view string to the bottom 3rd to the 1th digit
"Rld"
127.0.0.1:6379> incr page//increment operation on variable, initial value is 0
(integer) 1
127.0.0.1:6379> incr Page
(integer) 2
127.0.0.1:6379> incr Page
(integer) 3
127.0.0.1:6379> incr Page
(integer) 4
127.0.0.1:6379> set String6 10//Set string variable to 10
Ok
127.0.0.1:6379> incr String6//Increment the variable
(integer) 11
127.0.0.1:6379> incr String6
(integer) 12
127.0.0.1:6379> Incrby String6 2//Increment 2 operation on a variable
(integer) 14
127.0.0.1:6379> Incrby String6 2
(integer) 16
127.0.0.1:6379> Incrby String6 2
(integer) 18
127.0.0.1:6379> Incrby String6 2
(integer) 20
127.0.0.1:6379> Set num 16.1//Set floating-point variable
Ok
127.0.0.1:6379> incrbyfloat num 1.1//Increment 1.1 operation for floating-point numbers
"17.2"
127.0.0.1:6379> Incrbyfloat Num 1.1
"18.3"
127.0.0.1:6379> Incrbyfloat Num 1.1
"19.4"
127.0.0.1:6379> Incrbyfloat Num 1.1
"20.5"
127.0.0.1:6379> hset hkey google "www.g.cn"
Set hash table Hkey,google column has a value of www.g.cn
(integer) 1
127.0.0.1:6379> hset hkey Baidu "Www.baidu.com"
Set hash table Hkey,baidu column has a value of www.baidu.com
(integer) 1
127.0.0.1:6379> hget hkey Google//View the value of Google columns in the hash table hkey
"Www.g.cn"
127.0.0.1:6379> Hget hkey Baidu//View the value of the Baidu column in the hash table hkey
"Www.baidu.com"
127.0.0.1:6379> hmset site Google "www.g.cn" Baidu "www.baidu.com"
Ok
Set hash table multiple columns and values at once
127.0.0.1:6379> Hmget site Google Baidu
1) "www.g.cn"
2) "Www.baidu.com"
View multiple column values of a hash table site at once
127.0.0.1:6379> Hgetall site//View all columns and values in the site table
1) "Google"
2) "www.g.cn"
3) "Baidu"
4) "Www.baidu.com"
127.0.0.1:6379> Hdel site Google//delete site table in Google columns
(integer) 1
127.0.0.1:6379> Hgetall site//Verify Delete effect
1) "Baidu"
2) "Www.baidu.com"
127.0.0.1:6379> hmset site Google "www.g.cn" Baidu "www.baidu.com" Sina "www.sina.com"
Ok
127.0.0.1:6379> Hkeys site//View all columns of the site table
1) "Baidu"
2) "Google"
3) "Sina"
127.0.0.1:6379> hvals site//View values of all columns in the site table
1) "Www.baidu.com"
2) "www.g.cn"
3) "Www.sina.com"
127.0.0.1:6379> hmget site Google Baidu//one-time view of multiple column values in the site table
1) "www.g.cn"
2) "Www.baidu.com"

127.0.0.1:6379> Lpush List1 a b c//Create list and assign values
(integer) 3
127.0.0.1:6379> Lpush List2 A//Create list and assign values
(integer) 1
127.0.0.1:6379> Lpush list2 b//Append new values to the list
(integer) 2
127.0.0.1:6379> Lpush list2 C//Append new values to the list
(integer) 3
127.0.0.1:6379> Lrange List1 0-1
View all values in list List1, from 0 bits to the last 1 bits
1) "C"
2) "B"
3) "A"
127.0.0.1:6379> Lrange List1 1 2//view values for 1th and 2 bits in the list
1) "B"
2) "A"
127.0.0.1:6379> lrange List1 1-1//View the value of 1th to last 1 digits in the list
1) "B"
127.0.0.1:6379> lrange List2 0-1//View all values
1) "A"
2) "C"
3) "B"
4) "A"
127.0.0.1:6379> Lrange List2 0-1
1) "T"
2) "A"
3) "C"
4) "B"
5) "A"
127.0.0.1:6379> Lpop List2
Returns the List2 list header element data and removes the value from the list, returns nil if key does not exist
"T"
127.0.0.1:6379> lrange List2 0-1//verification Results
1) "A"
2) "C"
3) "B"
4) "A"
127.0.0.1:6379> Lpop List2//Continuation Delete Head element
A
127.0.0.1:6379> lrange List2 0-1//verification Results
1) "C"
2) "B"
3) "A"
127.0.0.1:6379> Lpop List2
C
127.0.0.1:6379> Lrange List2 0-1
1) "B"
2) "A"
127.0.0.1:6379> lrange list4 0-1//View all data below
1) "F"
2) "E"
3) "D"
4) "A"
5) "C"
127.0.0.1:6379> lindex list4 0//return No. 0 value in List4
"F"
127.0.0.1:6379> lindex list4 1//return 1th value in List4
E
127.0.0.1:6379> lindex list4-1//Returns the last 1 values in List4
C
127.0.0.1:6379> lindex list4-2//returns to the bottom 2nd value in List4
A
127.0.0.1:6379> Lrange List4 0-1
1) "F"
2) "E"
3) "D"
4) "A"
5) "C"
127.0.0.1:6379> LSet list4 0 test//No. 0 for LIST4 is the insertion value, the value is test
Ok
127.0.0.1:6379> lrange list4 0-1//verification Results
1) "Test"
2) "D"
3) "A"

127.0.0.1:6379> set MyKey "Hello"//define string variable
Ok
127.0.0.1:6379> get MyKey//view variables
"Hello"
127.0.0.1:6379> del mykey//delete variable
(integer) 1
127.0.0.1:6379> Get MyKey//Verify Results
(nil)
127.0.0.1:6379> set MyKey "Hello"//define variable as value
Ok
127.0.0.1:6379> get MyKey//view value
"Hello"
127.0.0.1:6379> Get MyKey
"Hello"
127.0.0.1:6379> expire MyKey 10//define Expiration time
(integer) 1
127.0.0.1:6379> get MyKey//10 seconds after view, no value
(nil)
127.0.0.1:6379> set MyKey "Hello"//Set Variable
Ok
127.0.0.1:6379> persist MyKey//redefine expiration time is, permanently valid
(integer) 1
127.0.0.1:6379> Get MyKey
"Hello"
127.0.0.1:6379> Get MyKey
"Hello"
127.0.0.1:6379> TTL MyKey
(integer)-1//Never Expires
127.0.0.1:6379> expire MyKey 10//define Expiration time
(integer) 1
127.0.0.1:6379> TTL MyKey//View Expiration time
(integer) 9
127.0.0.1:6379> TTL MyKey
(integer) 8
127.0.0.1:6379> TTL MyKey
(integer) 7
127.0.0.1:6379> TTL MyKey
(integer) 6
127.0.0.1:6379> TTL MyKey
(integer) 5
127.0.0.1:6379> TTL MyKey
(integer) 4
127.0.0.1:6379> TTL MyKey
(integer) 3
127.0.0.1:6379> TTL MyKey
(integer) 3
127.0.0.1:6379> TTL MyKey
(integer) 2
127.0.0.1:6379> TTL MyKey
(integer) 1
127.0.0.1:6379> TTL MyKey
(integer)-2//has expired
127.0.0.1:6379> get MyKey//view MyKey value is empty
(nil)
127.0.0.1:6379> set MyKey "Hello"
Ok
127.0.0.1:6379> keys//View all data under the database
1) "String6"
2) "List7"
3) "MyKey"
4) "String4"
5) "DB"
6) "Num"
7) "Result"
8) "Hkey"
9) "String5"
"String1"
One) "Bit1"
) "Page"
"Bit2"
"Site"
() "string2"
() "List1"
) "String3"
) "List6"
127.0.0.1:6379> Keys Li

1) "List7"
2) "List1"
3) "List6"
127.0.0.1:6379> Keys S
1) "String6"
2) "String4"
3) "String5"
4) "String1"
5) "Site"
6) "string2"
7) "String3"
127.0.0.1:6379> keys string[15]//view string1 or String5
1) "String5"
2) "String1"
127.0.0.1:6379> keys string[0-9]//View data for STRING0 value 9
1) "String6"
2) "String4"
3) "String5"
4) "String1"
5) "string2"
6) "String3"
127.0.0.1:6379> keys? It
Using wildcard characters for all data
1) "Bit1"
2) "Bit2"
127.0.0.1:6379> Select 1//Enter 1 database, default database is 0
Ok
127.0.0.1:6379[1]> keys//View data in a new database is empty
(empty list or set)
127.0.0.1:6379[1]> set Test "test"//create variable in database 1
Ok
127.0.0.1:6379[1]> get test//view value of variable
"Test"
127.0.0.1:6379[1]> Select 2//Enter 2 database
Ok
127.0.0.1:6379[2]> Keys
View All data
(empty list or set)
127.0.0.1:6379[2]> Select 1
Ok
127.0.0.1:6379[1]> keys
1) "Test"
127.0.0.1:6379[1]> Select 0
Ok
127.0.0.1:6379> Keys

1) "String6"
2) "List7"
3) "MyKey"
4) "String4"
5) "DB"
6) "Num"
7) "Result"
8) "Hkey"
9) "String5"
"String1"
One) "Bit1"
) "Page"
"Bit2"
"Site"
() "string2"
() "List1"
) "String3"
) "List6"
127.0.0.1:6379> Flushall//Clear All data
Ok
127.0.0.1:6379> keys//Verification Results
127.0.0.1:6379[2]> Select 0
Ok
127.0.0.1:6379> set MyKey "Hello"
Ok
127.0.0.1:6379> Keys

1) "MyKey"
127.0.0.1:6379> Select 1
Ok
127.0.0.1:6379[1]> keys
(empty list or set)
127.0.0.1:6379[1]> Select 0
Ok
127.0.0.1:6379> Keys

1) "MyKey"
127.0.0.1:6379> move MyKey 1//Move the MyKey variable in database 0 to database 1
(integer) 1
127.0.0.1:6379> keysView as empty in database 0
(empty list or set)
127.0.0.1:6379> Select 1//Enter database 1
Ok
127.0.0.1:6379[1]> Keys
View all databases
1) "MyKey"
127.0.0.1:6379[1]> Lpush cost 1 8 7 2 5//Create List cost
(integer) 5
127.0.0.1:6379[1]> sort cost//sorting list values
1) "1"
2) "2"
3) "5"
4) "7"
5) "8"

Database First Day

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.