Redis in Ubuntu installation use

Source: Internet
Author: User
Tags key string set set install redis

One: Installation of configuration 1.1 in ubuntu14.04

sudo apt-get install Redis-server

Use Redis-server-v to view the version of Redis and test

1.2 Configuring Redis

① Modify configuration file, path in/etc/redis/redis.conf

Bind the loopback IP, we can comment out, we will default to bind the machine all IP

② Restart Redis-server

sudo service redis-server restart

Two: basic Operation 1.1key Key operation

1:exists key test Specifies if key exists

2:del key1 Key2---KeyN delete the given key

3:type key returns the value type of the given key

4:keys pattern returns all keys that match the specified pattern

5:rename Oldkey Newkey Change Name

6:dbsize returns the number of keys for the current database

7:expire key seconds Specify an expiration time for key

8:ttl Key returns the remaining number of expired seconds for key

9:select Db-index Select a database

Ten move key Db-index move key from the current database to the specified database

11:FLUSHDB Delete all keys in the current database

12:flushall Delete all keys in all databases

1.2:string type operation

String is the most basic type of redis, and generally we can use it to save serialized objects or binary strings of some images.

1:set key value sets the value of the key corresponding to string type

2:mset key1 value1 key2 value2 set values for multiple keys at once

3:mget key1 key2----KeyN get multiple key values at once

4:INCR key to the value of key to do the Gaga operation, and return the new value

5:DECR Key Ibid, but it's a minus and minus operation.

6:incrby key integer with INCR, plus specified value

7:decrby key integer with DECR, minus the specified value

8:append key value appends value to the string value of the specified key

9:substr Key start end content interception, content subscript starting from 0, interception of content including start and end position

1.3:list Linked list type operations

The list type is actually a two-way linked list, with the push,pop operation adding delete elements from the head or tail of the list, which allows the list to be used as either a stack or as a queue. Generally we use it to get the latest information, can store n, if there is a new record added, delete the old information

The Lpush key string adds a string element to the head of the list corresponding to the key

Rpop key removes the element from the tail of the list and returns the deleted element

Llen key corresponds to the length of list, key does not exist return 0 if key corresponding type is not list returned error

Lrange Key start end returns the element within the specified range, with the subscript starting at 0

Rpush key string Ibid, added at tail

Lpop key removes the element from the head of the list and returns the deleted element

Ltrin key start end intercepts list, preserving elements within specified interval

1.4:set Collection type operations

Set is actually equivalent to an unordered collection of type string

About Set collection types in addition to basic additions, deletions, and other useful operations include the set, intersection, and difference set, which can generally be used to implement a friend referral function.

1:sadd Key member adds a string element to the set set of key corresponding to the successful return 1, if the element is already in the collection, return 0,key corresponding set does not exist return error

2:srem key member [member] removes the given element from the key corresponding set and returns 1 successfully

3:scard Key returns the number of elements of set

4:sismember key member determine if member is in set

5:sinter key1 key2 Key3---KeyN returns the intersection of all given keys

6:sunion Key1 Key2--keyn Returns the set of all the given keys

7:sdiff Key1 Key2--keyn Returns the difference set for all given keys

8:smembers key returns all elements of the key corresponding to set

1.5 Sort set Sorted collection type

The element has a sort function, there are not many identical elements, and as set, the sorted set is also a collection of elements of type string, each of which is associated with a right and is sorted by weight value.

1:zdd key add element to Key's set sort sort set

2:zrevrange key start end gets the value of each element from high to low

3:zscore key value Gets the right information for the element

4:zrank key value gets the rank ordinal of the element

5:zcard Key gets the number of collections

6:zremrangebyrank Key 0 0 Delete an old element with the least weight

Three: Persistence

NoSQL products for internal data security considerations, the data will be stored in the form of files to the hard disk, after the server restarts will automatically restore the hard disk data into the memory, this process is called the process of persistence

3.1: Snapshot persistence

The frequency and trigger mechanism of persistent backups can be modified in the Redis configuration file

The first line indicates that if more than one key is modified in 900 seconds, the snapshot is saved, and the same goes for the backup file name

3.2 AoF Persistence

Rationale: This operation will back up all user-written actions (add, delete, modify) to the file, if you need to restore the data, execute these saved commands

3.2.1 Open AOF Persistence

The first time you turn on the AOF persistence will erase all redis data

# Appendfsync always//write command is immediately forced to write to disk, the slowest, but guaranteed full persistence, deprecated, "the data is the safest, the server performance is lowest"

#appendfsync everysec//force write disk once per second, a good compromise in performance and persistence, recommended "data is relatively safe, server performance compromise"

# Appendfsync no//full OS dependent, best performance, persistent no guaranteed "low data security, highest server performance"

Redis in Ubuntu installation use

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.