Redis Database ABC

Source: Internet
Author: User
Tags set set sqlite git clone

What is a memory database?


Traditional database data are stored on disk and are therefore called disk-resident. Obviously, based on this kind of database,

Data pain requires frequent access to the disk for access to data. Now with the decrease of DRAM cost, the capacity of the system memory is getting bigger and larger, in order to improve the performance of data access, there is a database which is stored in memory, which is the memory database.


What are the advantages of the in-memory database?

In addition to faster data access, the memory database generally also redesigned data caching, sorting algorithms, parallel operations, and so on, so its data processing speed is much faster than DRDB, generally in 10 times times.


How are Redis databases compared to other databases?

Common memory databases are Sqlite/redis/altibase/oracl ' s berkely DB and TimesTen and Extreamdb.

Where SQLite is a small C library that implements a standalone, embeddable, 0-configured SQL database engine. Rdisredis is a high-performance Key-value database. The emergence of Redis, to a large extent, compensates for the lack of memcached such key/value storage, in some cases can be a good complement to the relational database. It provides clients such as Java,c/c++,c#,php,javascript,perl,object-c,python,ruby,erlang, which is convenient to use. Altibase represents the latest technology in memory data management systems and is a software solution that delivers high performance and high availability in a transaction-first environment. Altibase provides the convenience of extreme performance, fault tolerance, and transaction management, especially in the areas of communications, online banking, securities trading, real-time applications and embedded systems. Oracle Berkeley DB is a product of Oracle's acquisition of open source database vendors, formerly known as Berkeley DB, which provides developers with fast, reliable local persistence that is not managed. The Oracle Berkeley DB family is typically deployed as a "forefront" database, providing high performance, reliability, scalability, and availability for application use cases that do not require SQL. Oracle Memory Database TimesTen is a relational database optimized for memory that provides instant responsiveness and very high throughput for applications in today's real-time enterprise and industry, such as telecommunications, capital markets, and defense.


Because of the ease of Redis databases and the C + + interface, the Redis database is used in the actual project. So the following is a Redis database for example, analysis of its main operating methods and interface functions. Redis data provides a variety of use commands, which are the basis for implementing RDIs programming, and some commonly used commands are listed below:


List Table Related commands:

Lrange Key star STP returns all elements from the star to the STP (containing the elements at both ends);

Lrange numbers-2-1 "1" represents the rightmost first element, and "2" represents the rightmost second element;

Lrem Key Count Value (Lrem numbers-1 2) Lrem command removes the first count value of the element in the list;

LINDEX Key index (LINDEX numbers-1) index is a negative number, which indicates the indexes that are calculated from the right;

LSET Key index value (LSET numbers 1 7) sets the first number to 7;

LTRIM key start Endltrim command to delete all elements outside the specified index range;

Lpush names "name1" "name2" "Name3" "Name4" to the left to join list;

Rpush names "name1" "name2" to the right to join list;

Lpop names a value to the left of the popup;

Rpop names to the right pops a value;

Llen names gets the total length;

Set set related Operations Command:

Sadd key member [member ...] The Sadd command is used to add one or more elements to the collection and is created automatically if the key does not exist.

Srem Key member [member ...] The Srem command is used to remove one or more elements from the collection and returns the number of successful deletions;

The smembers keysmembers command returns all elements in the collection;

Sismember Key member determines whether the element is in the collection;

Sdiff Seta Setbseta-setb;

The SINTER seta setbsinter command is used to perform intersection operations on multiple sets;

The sunion seta setbunion command is used to perform a set operation on multiple sets;

The SCard keyscard command is used to obtain the number of elements in the collection;

Sdiffstore destination key [key ...]

Sinterstore destination key [key ...]

Sunionstore destination key [key ...]

Srandmember key [Count] randomly obtains the elements in the collection (count of);

SPOP key randomly pops an element from the collection;


Single-Touch Value related commands:

Set name "Hello" setting value;

Get name gets the value;

APPEND name "World" extended value;

Srtlen the length of the name value;

DEL name Delete field;


Hash table Related commands:

MSET name1 "Hello" name2 "World" at the same time set two values;

MGET name1 Name2 simultaneously obtains two values;

Hset car Name "BMW" set hash table value

Hget car name to get a single hash value

Hmset car price 1250 speed 1000 set multiple key values

Hmget car price speed get multiple key values

Hgetall car Get all properties and values

Hexists car Price determine if there is

Hdel car Price Delete hash key value

Hkeys car shows all the hash built

Hvals car Shows all the hash values

Hlen car Gets the hash key value logarithm


Sorted set ordered set related Operations Command:

Zadd key score member [score member ...] (Zadd scoreboard, Tom, Peter David)



How do I use the Redis database in my code?

1. Download source code: Git clone Https://github.com/redis/hiredis

2.CD Hiredis && make && sudo make install

If you see the following output, it means that the installation is complete:

[[email protected] hiredis]# make install

Mkdir-p/usr/local/include/hiredis/usr/local/lib

Cp-a hiredis.h async.h read.h sds.h Adapters/usr/local/include/hiredis

Cp-a libhiredis.so/usr/local/lib/libhiredis.so.0.13

Cd/usr/local/lib && ln-sf libhiredis.so.0.13 libhiredis.so

Cp-a Libhiredis.a/usr/local/lib

Mkdir-p/usr/local/lib/pkgconfig

Cp-a Hiredis.pc/usr/local/lib/pkgconfig

3. Programming

Because the Redis database is based on a key-value two-tuple, each element in any one record has these two properties, so before calling Redis in the program,

The organization of business data in the database needs to be designed and defined. This requires a clear answer to the following questions:

1. What is a key?

2. What are the attributes or sub-keys for each record?

3. How do data relate to each other?

4. What commands are used to establish key values and to access the desired data?

Once we've figured out all of the above, we just need to include the header files that are dependent on the/usr/local/include/hiredis in the application,

Call the commands listed above in the program code, and then add-lhiredis to the last Makefile link stage to specify the link to the libhiredis.so Dynamic library.

You can compile the desired executable file.


Note It is easy to overlook the fact that after the application is finally generated, the program cannot run immediately, because the Redis database is based on the client server model and requires the Redis-server service to be started to ensure that all Redis commands are executed.

   


Reference Documents and Links:

Http://www.cnblogs.com/newstart/archive/2013/01/06/2847067.html

Http://www.linuxidc.com/Linux/2014-12/111009.htm

Https://github.com/redis/hiredis

Http://baike.baidu.com/view/4595959.htm

https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=0&rsv_idx=1&tn=baidu&wd=%E5%86%85%E5%AD%98%E6% 95%b0%e6%8d%ae%e5%ba%93&rsv_pq=b5a65a6c00c862ff&rsv_t=8e86c%2bbcvq12kl8ujg97zb% 2f7esbxf9rv6pnt78rhsp6sedfe2kevjcl6mh8&rsv_enter=1&rsv_sug3=9&rsv_sug1=9&rsv_sug7=100


This article is from the "Store Chef" blog, so be sure to keep this source http://xiamachao.blog.51cto.com/10580956/1771278

Redis Database ABC

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.