The recommendation Redis, Memcached or customers?

1, Redis, Memcached major difference is?

Based Key, Value type Nosql database lot, we often hear that more than two. A few years ago, we often hear Memcached, Redis but a few years can be heard more details.

A, Redis more stored data type. Memcached generally only ordinary string key storage, and may also store Redis other four data structures (lists, sets, hash table, ordered set).

B, Redis support data off the disk. Redis either as a master database, and other databases can be used as an auxiliary storage system. The Memcached generally only use the memory database.

C, Redis supports master-slave replication. Redis environment may be used as an HA, the primary server will modify the log data is automatically synchronized to the server.

Two, Redis are five data types are supported?

1, string

set hello world // hello is the key name, world is the value. String data type

2. List

rpush list-key item

rpush list-key item2 // list-key is a key name, item, item2 is the value.

3, collection

sadd set-key item1

sadd set-key item2

sadd set-key item3 // set with a list of similar, but does not allow the same set of stored values

4, hash

Hash is like a miniature redis

hset hash-key sub-key1 value1

hset hash-key sub-key2 value2

5, ordered set

zadd zset-key 728 member1

zadd zset-key 982 member0 // member1, member0 are members, 728,982 are floating-point score. Similar hash ordered set, the members can access elements; however, an ordered set of structural elements can be accessed according to the order of scores, the scores.

Third, we use Redis data types to solve a real problem!

1, if there are dozens of articles, need to vote, the need to avoid a single user to repeat the voting day. To avoid storing invalid user data. We can use the collection type stores the user's ID.

2, if we need to store dozens of articles, we can use a set of ordered type. A member of an ordered collection of articles ID, score of Published articles. We can be sorted according to articles Published articles.

I hope this article can help you.

More real-time updates, visit public number.    

 

Click here to get the highest ¥ 1888 Ali cloud offering universal vouchers

Guess you like

Origin blog.csdn.net/qq_29718979/article/details/93534159
Recommended