No SQL database-Redis applications

Source: Internet
Author: User

1 . Getting Started overview
I. What is (WHO)

(1) Redis Remote dictionary server (long-range dictionary server)?

                          is fully open source free, written in C, compliant with BSD protocol, is a high Performance (key value) distributed memory Database
                          in-memory run and support persistent NoSQL database, is one of the most popular NoSQL databases, also become a data-behind server
                (2) Redis and other key-values cache products have the following three features.
                          A. Redis supports data persistence, which allows in-memory data Keep on disk, restart words can be loaded again for use
                          B. Re Dis not only supports simple key-value types of data, but also provides storage of data structures such as List set Zset hash
                &NBS P         C. Backup of Redis support data, data backup of several master-slave modes

II be able to do (what)
(1) Memory storage and persistence: Redis supports the asynchronous writing of in-memory data to a hard disk, with operations that do not affect the continuation of the service fetching the latest n data, such as:
(2) The ID of the latest 10 reviews can be placed in the Redis list to simulate a function similar to httpsession, which needs to set the expiration time.
(3) Publish a subscription message system
(4) Timer counter

Three where to go (where)
HTTP/redis.io/
http://www.redis.cn/

Four how to play
Data type basic operations and configuration
Persistence and Replication Rob/aop
Control of transactions
Copy

Five troubleshooting Java connections VMware Redis is not a problem?
(1). Turn off Firewall service iptables status
(2). Modify the redis.conf configuration file to comment out the port 127.0.0 so that any IP can access
(3). Modify the redis.conf configuration file, Protected-mode Yes
(4). Modify the redis.conf configuration file, plus the password requirepass Yes

six rEdis installation link

Seven Jedis operating redis database

2 . Redis command

A Redis 5 Big data type redis command Daquan

(1). Default 16 database, similar to array the following table is zero-based, the initial default use of number 0th
(2). Select command Switch Database Select 0
(3) Dbsize View the number of keys in the current database
(4). Keys * View all keys for the current library
(5). FLUSHDB clears all data from the current library
(6). Flushall clears all the data for all libraries
(7). exists K1 determine if there is a current key in the library
(8). Move key Name Library name cut key and values into the library
(9). TTL note English L key name see how many seconds expire, 1 means never expires, 2 means expired
(TEN). Type key to see what type of key you have
(one) Expire key name seconds for key assignment expiration Time Unit is wonderful
Two, String type data

The string is the most basic type of redis, and you can understand it as a type that is identical to memcache, a key that corresponds to a value
The string type is binary safe. This means that a Redis string can contain any data, such as a JPG image or a serialized object
The string type is the most basic data type of Redis, and a Redis value can be up to 521m
(1) Set/get/del is add query delete append intercept
(2) Append string appended to the key name string
(3) strlen key name to see the length of key
(4) INCR key name execution plus 1 (value must be number)
(5). Incrby Key Increment increment multiple
(6). Decr execution minus 1
(7). Decrby Decrement multiple
(8). GetRange key to start the corner mark to get the value within the specified interval range
(9). SetRange the start of the key name string sets the value in the range of the specified interval
(Ten). Setex Key value
(one). setnx key Values if a key assignment fails
Mset Add multiple Mget query multiple
Msetnx Add multiple If there is a duplicate assignment in the key that failed

Three, list (listing)

The Redis list is a simple list of strings, sorted by insertion order. You can add an element to the head of the list (left) or tail (right)
Its bottom line is actually a chain list.
(1). Lpush key [] array is advanced after out
(2). Rpush key [] array is FIFO
(3). Lrang Key Start end-1 represents all Queries list
(4). Lpop Key Stack go out one of the top-removed
(5). Rpop key to the bottom of the stack to go out one of the removed bottoms
(6). lindex key point position to get elements (top to bottom) by index subscript
(7). Llen Key Display list length
(8). Lrem Key Delete N value
(9). LTrim key Start index end index intercept the value of the specified range and then assign the value to key
(Ten). Rpoplpush Source list Destination List
(one). LSet Key index Valus indicates the replacement of a corner mark as a Valus value
Linsert key before value 1 values before inserting a corner label
Linsert key After value 1 insert the values after the angle label
(14). It is a list of strings, left right can be inserted
If the key does not exist, create a new linked list if the key already exists, what's new
If the value is all removed, the corresponding key disappears.
The operation of the list is extremely efficient both in terms of head and tail, but it is very inefficient to operate on the intermediate elements.

Four, set (set)

Redis's set is an unordered collection of type string, which is implemented through Hashtable
(1). Sadd Key [] Add data to add duplicate data can only have one
(2). Smembers key queries the collection of all keys
(3). Sismember key to determine if there is a key value
(4). SCard Key gets the number of elements in the collection
(5). Srem Key Values Delete set and medium element
(6). Srandmember key An integer (several random numbers)
(7). Spop Key random out Stack
(8). Smove Key1 Key2 A value in Key1 to assign a value in Key1 to Key2
(8). Math Set Class
Difference set Sdiff Set1 Set2 intersection sinter and set sunion

Five hash (hash)

Redis Hash is a set of key-value pairs
Redis Hash is a string type of field and valus mapping table, hash is particularly suitable for storing objects
Java-like map<string,object>
(1). hset key field values add
(2). hge T key field query
(3). hmset key field values (field values 、、、) add multiple
(4). HMG et key field (field 、、、、、) gets multiple
(5). Hgetall key gets key values key values
(6). hdel key Field Delete
(7). Hlen Key Query length
(8). hexists key field to determine if there is a filed
(9). Hkeys Key Name/hvals Key Name Query collection
Hincreby key field increment incrementing digital Hincreby hash2 K4 2
(one). hincrebyfloat key field increment increment decimal
Hsetnx key field values add non-repeating data

Six Zset (ordered set)

Redis Zset and set are also collections of string-type elements and do not allow duplicate members
The difference is that each element is associated with a double-type fraction
Redis formally uses fractions to sort small to large members of a collection. Zset members are unique, but fractions (score) can be duplicated
(1). Zadd Key Score1 v1 score2 v2 Add
(2). Zrange Key 0-1 Query all
(3). Zrangebyscore key starts score end score intercept contains the current score Zrangebyscore Zset1 (1 (2 does not contain the current value
(4). Zrangebyscore Zset1 1 2 Limit 0 1 page
(5). Zrem key corresponding values in a score, delete the element
(6). Zcard Key Query Collection size
(7). Zcount Key score interval statistic interval size
(8). Zrank Key values get subscript value
(9). Zscore key corresponding value to get the score
(Ten). Zrevrank key values in reverse order get subscript value
(one). Zrevrange Zset1 0-1 Reverse order get data values
(). Zrevrangebyscore key end score start score

              three . snapshotting   Snapshot
          & nbsp                       (1) &NBSP;RDB redis database abbreviation persistence file to Dump.rdb
                                  (2)  aof append only file abbreviation APPENDONLY.AOF profile default no
                &NB Sp                   AOF files If errors can be redis-check-aof--fix appendonly.aof

          Four . Redis Practice
                      & nbsp   Discard Cancel the practice, discard all commands within the execution transaction block abort transaction
                      &NB Sp  exec execute a command within all transaction blocks commits a transaction with a statement error side execution error
                         multi a command within a transaction open transaction
                        Unwatch Cancel Watch command for all key supervisors
                        Watch Ke Y Supervisor One, if the key is changed by another command before the earlier transaction executes, the transaction is interrupted

five . cluster
(1). Copy multiple redis.conf
(2). Turn on Daemonize Yes
(3). pid File name
(4). Specify the port
(5). Log file name
(6). Dump.rdb




No SQL database-Redis applications

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.