Java's basic operations on Redis (very classic)

Source: Internet
Author: User
Tags redis

Turn from: http://www.cnblogs.com/edisonfeng/p/3571870.html

One, server-side installation

1, download

Https://github.com/MSOpenTech/redis

You can see the current downloadable version: redis2.6

    

Download Windows platform files:

    

     

After decompression, select the version that corresponds to the current 64-bit Win7 system:

     

2, installation

1 after decompression, all files in the file will be copied to the Redis installation directory:

     

Functions of several EXE programs:

Redis-benchmark.exe: Performance testing to simulate the simultaneous dispatch of M-sets/gets queries (similar to Apache's AB tools) by n clients.

Redis-check-aof.exe: Update log check

Redis-check-dump.exe: Local Database check Redis-cli.exe: Client

Redis-server.exe: Service Side

2 Add path to System environment variable: procedure is slightly

3 cmd under Start redis-server

    

Note: The system takes default parameters because no configuration file is specified here

3, download the corresponding configuration file

From the above cmd output, the current version of 2.6.12

Open all releases on the original page, find 2.6.12:

    

Download zip file:

    

Copy the redis.conf configuration file to the installation directory:

    

    

configuration file each field meaning: http://cardyn.iteye.com/blog/794194

PS: If the version of the configuration file does not match the version of the current EXE program, it is easy

The server side could not start because of inconsistent parameters.

4. Start the server through the specified configuration file

    

5. Client Access Test

Another cmd window:

Second, the basic function test

1, the basic structure of the program

  

2. Main class

1 function Class Press CTRL + C copy Code press CTRL + C to copy code

2) Test class

Package Com.redis;

public class Main {public

    static void Main (string[] args) {
        //TODO auto-generated method stub
        New Redisclien T (). Show (); 
    }

3, each function function

1 key function Press CTRL + c copy Code press CTRL + C to copy code

Run Result:

======================key==========================
Clear all data in the library: OK
to determine if the key999 key exists: false
add key001, value001 key value pair: OK to
determine if key001 exists: true
new key002,value002 key value pairs: OK
system all keys are as follows:
key002
key001
System Delete Key002:1
to determine if key002 exists: false
set key001 expires in 5 seconds: 1
View remaining lifetime of key001:3
to remove the key001 lifetime: 1
to view the remaining lifetime of key001: -1
View the type of value stored by key: string

2) string function Press CTRL + C to copy code press CTRL + C to copy code

Run Result:

======================string_1========================== empty all the data in the library: OK ============= Add ============= has added 3 key value pairs as follows:
value001 value002 value003 ============= Delete ============= remove key003 key value pair: 1 get key003 key corresponding value: null ============= change ============= Directly overwrite key001 original data: OK gets key001 corresponding new value: Value001-update after key002 original value append: 21 get key002 corresponding new value value002+appendstring = increase, delete, check (multiple) ============= one-time add key201,key202,key203,key204 and its corresponding value: OK get key201,key202,key203,key204 respective values at once: [ value201, value202, value203, value204] One-time delete key201,key202:2 get key201,key202,key203,key204 their respective values: [NULL, NULL, value203, value204] ======================string_2========================== empty all data in the library: OK =============
New key value pairs to prevent overwriting the original value ============= the original key301 does not exist when the new key301:1 originally key302 does not exist, add key302:1 when the key302 exists, try adding key302:0
Gets the value of the key301: value301 gets key302 corresponding value: value302 ============= more than the expiration key value to be deleted ============= add key303, and specify an expiration time of 2 seconds OK
Gets the value of the key303: Key303-2second after 3 seconds, get the key303 corresponding value: null ============= get the original value, update the new value one step complete ============= key302 original value: value302 key302 New value: Value302-after-geTset ============= Gets the substring ============= gets the substring of the key302 corresponding value: 302 

3) List function Press CTRL + c copy Code press CTRL + C to copy code

Run Result:

======================list==========================
Clear all the data in the library: OK
============= Add =============
All elements-stringlists:[hashlist, seriallist, maplist, LinkedList, vector, vector, ArrayList, vector]
all elements-numberlists: [2, 5, 1, 3]
============= Delete =============
The number of specified elements successfully deleted-stringlists:2
after the specified element is deleted-stringlists:[hashlist, seriallist, maplist , LinkedList, ArrayList, vector]
delete elements outside the subscript 0-3 interval: OK
Delete elements beyond the specified interval-stringlists:[hashlist, seriallist, Maplist, LinkedList]
out stack elements: hashlist
elements out of the stack after-stringlists:[seriallist, maplist, LinkedList]
============= Change = =
the value of ======= subscript 0 is modified after-stringlists:[hello list!, Maplist, LinkedList]
============= search =============
Length-stringlists:3
length-numberlists:4
returns the sorted result-stringlists:[linkedlist, maplist, hello list!]
Returns the sorted result-numberlists:[1, 2, 3, 5]
substring-the second start to the end: [Maplist, LinkedList]
gets the element with subscript 2: LinkedList

4 Set function Press CTRL + c copy Code press CTRL + C to copy code

Run Result:

======================set==========================
Clear all the data in the library: OK
============= Add =============
Add elements to the sets set Element001:1 add elements to the
sets collection Element002:1
add elements to the sets collection Element003:1
add element element004:1 to the sets collection to
view all the elements in the sets collection: [element001, element002, element003, element004]

============= Delete = = ===========
Collection Sets Delete element element003:1
View all elements in the sets collection: [element001, element002, element004]

=========== = = Change =============

============= check =============
determine if element001 is in collection sets: True
circular query gets each element in the sets:
element001
element002
element004

============= set Operation =============
add element in Sets1 element001:1 sets1 add element element002:1 sets1 add element element003:1 sets1
add elements in Sets1 element003:1
sets1 add elements element004:1
View all elements in the Sets1 collection: [Element001, element002, ELEMENT003]
View all elements in the Sets2 collection: [element002, element003, element004]
sets1 and sets2 intersections: [element002, element003]
Sets1 and sets2: [element001, element002, element003, element004]
sets1 and sets2 difference sets: [element001]

Related Article

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.