originating from: http://www.cnblogs.com/chenping-987123/archive/2012/01/29/2331079.html
Redis is an open source, high-level store of key-value pairs. It is often used as the data structure of the server, its key data type can be strings, HASHS, lists, sets (unordered collection) and sorted sets (ordered collection).
If we want to use Redis under windows for learning, we can go to https://github.com/dmajkic/redis/downloads to download the latest Redis under Windows, the latest version is now 2.4.5
Now complete can be decompressed, there are 2 folders, respectively, corresponding to the 32-bit Windows, 64-bit Windows.
The author's computer is 32-bit Win7 Professional Edition, so open 32 of that folder, you can see some config, exe file, double-click Redis-server.exe Run. You can see some information:
Port number: 6379; The redis.conf configuration file is used; The version number of Redis: 2.4.5; and the number of connections to the client.
At this point, you can double-click Redis-cli.exe to run a client and see Redis 127.0.0.1:6379
At this point, you can demonstrate the functionality of Redis with a single command. The Redis commands are as follows:
Connection control
QUIT Close Connection
AUTH (when enabled only) Simple password verification
For all types of commands
EXISTS key determines whether a key exists; returns 1; otherwise returns 0;
DEL key Deletes a key, or a series of Key;del Key1 Key2 Key3 Key4
Type key returns the data type of a key element (none: Not present, string: Character, List,set,zset,hash)
Keys pattern Returns a list of matching keys (keys foo*: Find keys at the beginning of Foo)
Randomkey randomly obtains a key that already exists and returns an empty string if the current database is empty
RENAME oldname newname Change key name, new key if present will be overwritten
Renamenx oldname newname Change the name of the key and the change fails if the name exists
Dbsize returns the total number of keys for the current database
EXPIRE set the expiration time of a key (in seconds), (EXPIRE Bruce 1000: Set Bruce this key1000 seconds after the system is automatically deleted) Note: If the value has been changed since it has not expired, then that value will be cleared.
How long does the TTL look for a key expire and return seconds
Select Index Selection Database
Move key Dbindex moves the specified key from the current database to the target database Dbindex. Successful return 1, otherwise 0 (the source database does not exist key or the target database already exists with the same name key);
FLUSHDB clears all keys in the current database
Flushall clears all keys in all databases
Commands for working with strings
Set key value sets a string value for a key. Set KeyName datalength data (set Bruce Paitoubing: Save Key to Burce, string length of 10 of a string paitoubing to the database), data maximum cannot exceed 1G.
Get key gets the value of a key. If key does not exist, the string "nil" is returned, and an error is returned if the value of key is not a string type.
Getset key value can be understood as the value of the obtained key and then set this value, more convenient operation (set Bruce Paitoubing, this time need to change Bruce into 1234567890 and get this previous data paitoubing , Getset Bruce 10 1234567890)
MGET key1 Key2 ... KeyN returns the value of multiple keys at once
The difference between Setnx key value Setnx and set is that set can create and update key value, and SETNX is if key does not exist, then key and value data are created
MSET key1 value1 key2 value2 ... keyN valuen set multiple keys and values once in one atom operation
Msetnx key1 value1 key2 value2 ... keyN valuen set multiple keys and values once in an atomic operation (the target key does not exist, if more than one key already exists, it fails)
INCR key self-increment value
Incrby key integer to increment the specified value from the key value
DECR key self-decrement value
Decrby key integer to subtract a specified value from a value
Commands for handling lists
Rpush key value adds an element from the tail of the List (if the sequence does not exist, it is created first, if a key with the same name already exists and not a sequence, then an error is returned)
Lpush key value adds an element from the List header
Llen Key returns the length of a List
Lrange Key start end returns the elements of a sequence from a custom range (Lrange testlist 0 2; return sequence testlist first 0 1 2 elements)
LTRIM Key start end trims data outside a range (LTRIM testlist 0 2; Keep 0 1 2 elements, remaining deleted)
LINDEX key index Returns the sequence value of a position (LINDEX testlist 0; Returns the element with the sequence testlist position 0)
LSET key index value to update values for a location element
Lrem Key Count value removes a number of elements (count) from the List's head (count positive) or tail (count negative) that matches the value of the element, returning the number of deleted elements.
Lpop key pops up the first element of a List
Rpop key pops up the last element of the List
Rpoplpush Srckey Dstkey pops the last element of the _SRCKEY_ and presses it into the _DSTKEY_ header, the key does not exist or the sequence is empty returns "nil"
command to process Collections (sets) (with indexed unordered sequence)
Sadd Key member adds the element to the sets sequence if the element (Membe) does not exist then adds a success of 1, otherwise fails 0; (Sadd testlist 3 \ n One)
Srem key member Deletes an element of the sets sequence if the element does not exist then fails 0, otherwise succeeds 1 (Srem testlist 3 \ n One)
SPOP key randomly pops a member from the collection
Smove Srckey Dstkey member moves an element of a sets sequence to another sets sequence (Smove testlist test 3\n Two; moves the element from sequence testlist to test, testlist There is no both element)
SCard key counts the number of elements of a sets sequence
Sismember Key member learns whether the specified member exists in the collection
SINTER key1 Key2 ... KeyN returns the intersection of Key1, Key2, ..., KeyN
Sinterstore dstkey key1 Key2 ... keyN the intersection of Key1, Key2, ..., KeyN is deposited dstkey
Sunion key1 key2 ... keyN return key1, Key2, ..., KeyN's set
Sunionstore dstkey key1 key2 ... KeyN will Key1, Key2, ..., KeyN set into Dstkey
Sdiff key1 Key2 ... keyN based on Key2, ..., KeyN seek key1 difference set. Official examples:
Key1 = X,a,b,c
Key2 = C
Key3 = A,d
Sdiff Key1,key2,key3 = x,b
Sdiffstore Dstkey Key1 Key2 KeyN based on Key2, ..., KeyN seek key1 difference set and deposit Dstkey
Smembers key returns all elements of a sequence
Srandmember key randomly returns the elements of a sequence
Commands for handling ordered collections (sorted sets) (Zsets)
Zadd Key Score member adds the specified member to the ordered collection, and updates the score (score, sort) if the target exists
Zrem Key member deletes the specified member from an ordered collection
Zincrby Key Increment member adds _increment_ If member exists, otherwise a member score to _INCREMENT_ will be set
Zrange Key start end returns the member of the specified range after ascending order
Zrevrange Key start end returns the member of the specified range after descending sort
Zrangebyscore key min Max returns all members that conform to score >= min and score <= Max Zcard key Returns the number of elements in an ordered collection Zscore key element returns the score value of the specified member Zremrangebyscore Key min Max deletes all members that meet score >= min and score <= max conditions
Sort (List, set, Sorted set)
SORT key by pattern LIMIT start end GET pattern asc| DESC ALPHA sorts a collection or list according to a specified pattern
SORT MyList
Default ascending ASC
SORT MyList DESC
SORT mylist LIMIT 0 10
Starting from ordinal 0, fetch 10
SORT mylist LIMIT 0 ALPHA DESC
Sort by first character
SORT MyList by weight_*
SORT mylist by weight_* GET object_*
SORT mylist by weight_* get object_* Get #
SORT mylist by weight_* STORE Resultkey
Store the returned results in the Resultkey sequence (List)
Persistent control
Save data to disk synchronously
BGSAVE asynchronously saves data to disk
Lastsave returns the last Unix timestamp that was successfully saved to disk
SHUTDOWN synchronizing to the server and shutting down the Redis server (save+quit)
Rewrite log files when bgrewriteaof files are too long
Remote control commands
Info provides information and statistics about the server
Monitor outputs all incoming requests in real time
Slaveof Modifying replication options
Commands are uppercase, in fact lowercase is also possible.
The simplest example:
Set OK OK
Get OK
The specific command you can try one at a.
Redis Commands and Redis windows