Alchemy Database 使用SQL语句操作redis的内存数据库
jopen
13年前
<p>介绍一款很牛的DB(Alchemy Database)介绍给大家认识,这个世界上疯狂的人真多,尤其是这个老外,竟然把Redis改造成一个支持SQL语句的内存型数据库.太NB了.</p> <p>以下是项目主页提供的测试语句.</p> <p>FAST ON COMMODITY HARDWARE:</p> <p>Client/Server using 1GbE LAN to/from a single core running at 3.0GHz, RAM PC3200 (400MHz)<br /> 95K INSERT/sec, 95K SELECT/sec, 90K UPDATE/sec, 100K DELETE/sec<br /> Range Queries returning 10 rows: 40K/sec<br /> 2 Table Joins returning 10 rows: 20K/sec<br /> 10 Table Joins returning 10 rows: 4.5K/sec<br /> Lua script performing read and write: 42K/sec</p> <h2>支持SQL</h2> <h3>Create/Drop操作</h3> <pre class="brush:sql; toolbar: true; auto-links: false;"> CREATE TABLE customer
(id INT, group_id INT, name TEXT, phone text, age INT); CREATE INDEX cust_group_ind ON customer (group_id); DROP TABLE customer DROP INDEX cust_group_ind DESC customer – provides detailed memory usage info DUMP customer – dumps the table to client DUMP customer TO MYSQL – dumps the table in mysql format DUMP customer TO FILE fname – dumps the table to the file “fname”</pre> <h3>单行操作</h3> <pre class="brush:sql; toolbar: true; auto-links: false;"> INSERT INTO customer VALUES (1,300,’John Doe’,’301-933-1891 begin_of_the_skype_highlighting 301-933-1891 end_of_the_skype_highlighting’,30); SELECT group_id, phone FROM customer WHERE id = 1 DELETE FROM customer WHERE id = 1 UPDATE customer SET phone = ‘703-933-1891 begin_of_the_skype_highlighting 703-933-1891 end_of_the_skype_highlighting’, group_id = 4 WHERE id = 1 INSERT INTO customer VALUES (1,300,’John Doe’,’301-933-1891 begin_of_the_skype_highlighting 301-933-1891 end_of_the_skype_highlighting’,30) RETURN SIZE; – returns the size of the row, table, and indices</pre> <h3>索引操作</h3> <ul> <li><tt>SELECT group_id, phone FROM customer WHERE group_id BETWEEN 300 AND 400 [ORDER BY column LIMIT n OFFSET m]</tt></li> <li><tt>SELECT group_id, phone FROM customer WHERE group_id IN (300, 301, 307, 311) [ORDER BY column LIMIT n OFFSET m]</tt></li> <li><tt>DELETE FROM customer WHERE group_id BETWEEN 300 AND 400 [ORDER BY column LIMIT n OFFSET m]</tt></li> <li><tt>UPDATE customer SET phone = ‘703-933-1891 begin_of_the_skype_highlighting 703-933-1891 end_of_the_skype_highlighting’, group_id = 4 WHERE group_id BETWEEN 300 AND 400 [ORDER BY column LIMIT n OFFSET m]</tt></li> <li><em>Introducing</em> the <strong>Non-Relational Range Query</strong> – the IN() can contain ANY redis command that returns rows (e.g. LRANGE, SINTER, ZREVRANGE, etc…)</li> </ul> <blockquote> <p>Get name and number of the 5 most recent active customers</p> <pre>SELECT name, phone FROM customer WHERE group_id IN ($LRANGE L_IND_recent_calls 0 5) [ORDER BY column LIMIT n OFFSET m]</pre> <pre><span>SELECT name</span><span>,</span><span> phone FROM customer WHERE group_id IN </span><span>(</span><span>$LRANGE L_IND_recent_calls </span><span>0</span><span> </span><span>5</span><span>)</span><span> </span><span>[</span><span>ORDER BY column LIMIT n OFFSET m</span><span>]</span></pre> </blockquote> <h3>Update Expressions</h3> <blockquote> <p>UPDATE expressions currently support the following functionalities <tt>(+=, -=, *=, /=, %=, ^=, ||=)</tt></p> <pre>UPDATE customer SET phone = phone || ' ext 912', group_id = group_id * 4, age = age + 1 WHERE id = 1</pre> <pre><span>UPDATE customer SET phone </span><span>=</span><span> phone </span><span>||</span><span> </span><span>' ext 912'</span><span>,</span><span> group_id </span><span>=</span><span> group_id </span><span>*</span><span> </span><span>4</span><span>,</span><span> age </span><span>=</span><span> age </span><span>+</span><span> </span><span>1</span><span> WHERE id </span><span>=</span><span> </span><span>1</span></pre> </blockquote> <p><a href="/misc/goto?guid=4959499521449448667" target="_blank">http://code.google.com/p/alchemydatabase/</a></p>