Getting Started with Redis

Source: Internet
Author: User
Tags download redis redis server

1. Command line tools

On the windows of the clever command-line instructions, it is really painful, I really can not stand the Windows cmd of the stupid, PowerShell's stupid, only a change.

Introduction of a CMD tool cmder (open source on GitHub), address: http://bliker.github.io/cmder/, if there is a better tool, please tell me, here, thank you first.

Note:"λ" is the identification of the Cmder tool, and the following command usually encounters this character and can skip

2, the official download Redis

Address: http://redis.io/download I downloaded the stable version of 2.8.19. After downloading, unzip the download package to a local directory, such as D:\Programs\redis-2.8.19

3. Start the database service.

Command:

Redis-server.exe redis.windows.conf

  

4, test database,

Below we respectively create String,list,hash, as for the more advanced, we should learn more deeply

Attention:

The redis instruction takes a carriage return as the end identifier, so there is no punctuation in the back, otherwise an error is made, or an incorrect instruction is executed (that is, the semicolon is part of the instruction).

The canssdra instruction ends the semicolon as a directive, so it must be followed by a semicolon ";", otherwise the instruction is not concluded.

Λredis-cli.exe-h 127.0.0.1-p 6379127.0.0.1:6379> keys *;(empty list or set) 127.0.0.1:6379> set name ' Zxh '; Invalid argument (s) 127.0.0.1:6379> set name ' Zxh ' OK
4.1 String

C:\USERS\ZXHΛCD d:\programs\redis-2.8.19c:\users\zxhλd:d:\programs\redis-2.8.19λredis-cli.exe-h 127.0.0.1-p 6379127.0.0.1:6379> KEYS *o* (empty list or set) 127.0.0.1:6379> set username ' zxh ' ok127.0.0.1:6379> get username "Zxh" 127.0.0.1:6379>
4.2 List
127.0.0.1:6379> rpush Friends ' Zhangsan ' (integer) 1127.0.0.1:6379> rpush friends ' Lisi ' (integer) 2127.0.0.1:6379 > Rpush Friends ' Wangwu ' (integer) 3127.0.0.1:6379> lrange friends 0-11) "Zhangsan" 2) "Lisi" 3) "Wangwu" 127.0.0.1:63 79>
4.3 hash
5. Download the client jar

Note that this is not the case with Cassandra, which is not used by the JDBC driver, and is not recommended by the authorities, and there are some problems with the JDBC driver, such as the new version of Redis using the JDBC driver to store data, the length of the data written to the database, not the actual value of the data.

Cliendt jar Package, we choose Jedis, location Branches\mvn-repo\redis\clients\jedis\2.2.0\jedis-2.2.0.jar

or download the Http://files.cnblogs.com/piaolingzxh/jedis-2.2.0.jar.zip directly from here (after downloading, remove the suffix name directly. zip is available)

6. Using Java to connect Redis

Remember to refer to the top of the jar package, the following is the main Java code fragment

Jedis Redis = new Jedis ("localhost", 6379);//Connect redis//stringredis.append ("User", "piaolingzxh");//Listredis.lpush (" Edu "," Xiaoxue "," Chuzhong "," Gaozhong ");//hash key field Valueredis.hset (" Home_address "," province "," Henan "); Redis.hset ("Home_address", "City", "Sanmenxia"), Redis.hset ("home_address", "detail", "what a U doing?"); List List = Redis.hmget ("home_address", "Province", "City", "detail"); for (int i = 0; i < list.size (); i++) {System.out . println (List.get (i)); System.out.println ("OK");
To view the results in a database
C:\USERS\ZXHΛCD d:\programs\redis-2.8.19c:\users\zxhλd:d:\programs\redis-2.8.19λredis-cli.exe-h 127.0.0.1-p 6379127.0.0.1:6379> keys *o* (empty list or set) 127.0.0.1:6379> keys *) "home_address" 2) "Edu" 3) "User" 127.0.0.1:6379> get User "piaolingzxh" 127.0.0.1:6379> lrange edu 0-11) "Gaozhong" 2) "Chuzhong" 3) "Xiaoxue" 127.0.0.1:6379> hgetall home_address 1) "Province" 2) "Henan" 3) "City" 4) "Sanmenxia" 5) "detail" 6) "What a U doing?"
7:scala connection redis8: Redis instruction Set
Connection action-related commands quit: Close connection (connection) Auth: simple Password Authentication persistence Save: Synchronizing data to disk Bgsave: Asynchronously saving data to disk Lastsave: Returns the UNIX timestamp Shundown when the data was last successfully saved to disk: Save to disk, and then turn off service remote Service Control info: Provide server information and statistics Monitor: real-time dump received request slaveof: Change replication Policy settings config: Configure Redis server command exists for value operation at run time (key) : Verify that a key exists del (key): Delete a KeyType (key): The type of the return value keys: Returns all Keyrandomkey that satisfy a given pattern: a keyrename that returns a random key space ( Oldname, newname): Rename keydbsize: Returns the number of keys in the current database expire: Set a key's active time (s) TTL: Get the active time of a key Select (index): Query by index move (key, Dbindex): Move the key in the current database to the Dbindex database flushdb: Delete all Keyflushall in the currently selected database: Delete all keys in all databases command set (key, value) for string operations : Assigns the value Valueget (key) to a string named key in the database: Returns the Valuegetset (key, value) of a string with the name key in the database: assigns the last Valuemget to a string named key ( Key1, Key2,..., key N): Returns VALUESETNX (key, value) of multiple strings in the library: add string, Name key, value Valuesetex (key, Time, value): Adds a string to the library, Set Expiration time Timemset (key n, value N): Bulk set multiple string values Msetnx (key n, value N): If all strings with the name key I do not exist incr (key) : string with the name key incremented by 1 operations Incrby (key, Integer): String with Name Key added INTEGERDECR (key): string minus 1 operation with name Key Decrby (key, Integer) : s with Name keyTring Reduced integerappend (key, value): String value with Name key appended Valuesubstr (key, start, end) : Returns a substring of string value named key to the command of the list operation Rpush (key, value): Adds an element of value to the list end named Key Lpush (key, value) : Adds a value of element Llen (key) to the list header with the name key: Returns the length of the list named key Lrange (key, start, end): Returns the element between start and end in list named Key LTrim ( Key, start, end): Intercepts the Listlindex (key, index) named key: Returns the element LSet (key, index, value) of the index position in the list named key : Assigns the element of the index position in the list with the name Key Lrem (key, Count, value): Removes the element with value in the list of Count key Lpop (key): Returns and removes the first element in the list named key Rpop (key): Returns and removes the tail element of the list named key Blpop (Key1, Key2,... key N, timeout): The block version of the Lpop command. Brpop (Key1, Key2,... key N, timeout): The block version of Rpop. Rpoplpush (Srckey, Dstkey): Returns and removes the tail element of the list named Srckey, and adds the element to the header of the list named Dstkey for the set operation command Sadd (key, member) : add element Membersrem (key, member) to a set named key: Delete the element in set named Key Memberspop (key): Randomly returns and removes an element in a set named Key Smove (Srckey, Dstkey, member): Moves to the collection element SCard (key): Returns the cardinality of the set named Key Sismember (key, member): Member is a set element named Key sinter (Key1, Key2,... Key N): Intersection Sinterstore (Dstkey, (keys)): Intersection and save intersection to DSTKey Collection Sunion (Key1, (keys)): Gather Sunionstore (Dstkey, keys): Sets and saves the set to Dstkey collection Sdiff (Key1, (keys)): Differential Set Sdiffstore ( Dstkey, (keys)): Differential set and save the difference to Dstkey collection smembers (key): Returns all elements of a set named Key Srandmember (key) : Randomly returns an element of the set with the name key to the hash operation command Hset (key, field, value): Adds an element to the hash named key Fieldhget (Key, field) : Returns the Valuehmget (key, fields) of field in the hash named key: Returns the Valuehmset (key, field) corresponding to the hash in the name key. : Add an element to a hash named key field Hincrby (Key, field, integer): Adds Integerhexists (Key, field) to the value of field in the hash named key : A hash with the name key is a field Hdel (Key, field): Delete The field with the key named key field Hlen (key): Returns the number of elements in the hash named key Hkeys (key)  : Returns all keys in a hash named key hvals (key): Returns the Valuehgetall (key) for all keys in a hash named key: Returns all keys (field) and their corresponding value in a hash named key

Reference: http://www.cnblogs.com/oubo/archive/2011/09/07/2394568.html

Getting Started with Redis

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.