Redis Summary Notes (i): Installation and common commands _redis

Source: Internet
Author: User
Tags delete key hash redis redis server

First, Redis simple introduction

Redis is a member of the NoSQL family, a memory-type database of key-value pairs. But it supports saving the data locally. This is better than memcached.

Disadvantage: There is no local data buffer, there is no complete data aggregation support

Advantages: Simple configuration, easy to use, high performance, support for different data types (hashes, lists, sets, sorted sets)

asp.net WebUI for viewing content of the cache

Second, the installation

Unofficial version of Windows version. But that's what the "Microsoft Team maintains" is the official statement. Download decompression run up service side (figure)

Linux version of the official version, the specific installation is also very simple

Copy Code code as follows:

$ wget http://download.redis.io/releases/redis-2.8.17.tar.gz
$ tar xzf redis-2.8.17.tar.gz
$ CD redis-2.8.17
$ make

Iii. Common Commands

Set key value Insert key
Get key gets value
Keys * Query all keys
Del key Delete key
Flushall Empty the database
Connection Operations Related commands

Quit: Close connection (connection)
Auth: simple Password Authentication


Persistence of

Save: Synchronize data to disk
Bgsave: Asynchronously save data to disk
Lastsave: Returns the UNIX timestamp that last successfully saved data to disk
Shundown: Synchronize data to disk, and then close the service


Remote Service Control

Info: Provides server information and statistics
Monitor: Real-time dump of requests received
slaveof: Changing Replication policy settings
Config: Configuring the Redis server at run time


Commands for the value operation

Exists (key): Confirm whether a key exists
Del (key): Delete a key
Type (KEY): Returns the types of values
Key (Pattern): Returns all keys that satisfy a given pattern
Randomkey: A random return of the key space
Keyrename (Oldname, newname): Renaming key
Dbsize: Returns the number of key keys in the current database
Expire: Set the active time of a key (s)
TTL: Gets the active time of a key
Select (Index): Query by index
Move (Key, Dbindex): Moves key to Dbindex database in the current database
FLUSHDB: Deletes all keys in the currently selected database
Flushall: Delete all key in all databases


Commands for string operations

Set (key, value): Assign value to string with name key in database
Get (Key): Returns the value of a string with the name key in the database
Getset (key, value): Assigns the last value to a string named key
Mget (Key1, Key2,..., key N): Returns the value of multiple strings in a library
SETNX (key, Value): Add string, name key, value
Setex (Key, Time, value): Add string to library, set expiration time
Mset (key n, Value N): Set multiple string values in bulk
Msetnx (key n, value N): If all strings named key I do not exist
INCR (key): string increment 1 operation with name key
Incrby (Key, Integer): string with name key increases integer
DECR (key): string minus 1 operation with name key
Decrby (Key, Integer): string with Name key reduces integer
Append (key, value): String with Name key appended value
SUBSTR (key, start, end): A substring that returns the value of string with the name key


Commands for the list operation

Rpush (key, value): Adds an element of value to the end of the list named key
Lpush (key, value): Adds an element of value to the list header named key
Llen (Key): Returns the length of the list named key
Lrange (key, start, end): Returns the element between start to end in the list named key
LTrim (key, start, end): Intercept list with name key
Lindex (key, index): Returns an element of the index position in the list named key
LSet (key, index, value): Assigning values to the elements of the index position in the list named key
Lrem (Key, Count, value): Deletes the element of value in the list of Count key
Lpop (Key): Returns and Deletes the first element in the list named key
Rpop (Key): Returns and Deletes the tail element in 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 Deletes the tail element of the list named Srckey and adds the element to the head of the list named Dstkey


Commands for set operations

Sadd (Key, member): add element member to set with Name key
Srem (Key, member): Delete element member in set with Name key
Spop (key): Randomly returns and deletes an element in a set named key
Smove (Srckey, Dstkey, member): Moving to a collection element
SCard (Key): Returns the cardinality of the set with the name key
Sismember (Key, member): Whether member is a set element with the name key
Sinter (Key1, Key2,... key N): Intersection
Sinterstore (Dstkey, (keys)): Find the intersection and save the intersection to the Dstkey collection
Sunion (Key1, (keys)): Seek and set
Sunionstore (Dstkey, (keys)): Ask for and save the set to the Dstkey collection
Sdiff (Key1, (keys)): Difference set
Sdiffstore (Dstkey, (keys)): Finding a difference set and saving the difference to a collection of Dstkey
Smembers (Key): Returns all elements of a set with the name key
Srandmember (key): Randomly returns an element of a set with the name key


Commands for hash operations

    hset (Key, field, value): Adding an element field to a hash named key
    hget (Key, field) : Returns the value
    hmget (Key, (fields)) corresponding to the field in the hash with the name key: Returns value
  of field I in the hash with the name key    Hmset (Key, (Fields)): Add Element field
    Hincrby (Key, field, integer) to hash with name key : Adds the value of the field in the hash named key to the integer
    hexists (Key, field): Whether a field with key field exists in the hash named key
     Hdel (Key, field): Delete the field
    Hlen (key) with the key in the hash with the name key: Returns the number of elements in the hash named key
    Hkeys (Key): Returns all keys in the hash named key
    hvals (Key): Returns value for all keys in the hash named key
    Hgetall (Key): Returns all the keys (field) and their corresponding value

in a hash named key.

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.