Alchemy Database 使用SQL語句操作redis的內存數據庫

jopen 12年前發布 | 42K 次閱讀 Redis NoSQL數據庫 NOSQL

介紹一款很牛的DB(Alchemy Database)介紹給大家認識,這個世界上瘋狂的人真多,尤其是這個老外,竟然把Redis改造成一個支持SQL語句的內存型數據庫.太NB了.

以下是項目主頁提供的測試語句.

FAST ON COMMODITY HARDWARE:

Client/Server using 1GbE LAN to/from a single core running at 3.0GHz, RAM PC3200 (400MHz)
95K INSERT/sec, 95K SELECT/sec, 90K UPDATE/sec, 100K DELETE/sec
Range Queries returning 10 rows: 40K/sec
2 Table Joins returning 10 rows: 20K/sec
10 Table Joins returning 10 rows: 4.5K/sec
Lua script performing read and write: 42K/sec

支持SQL

Create/Drop操作

    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”

單行操作

    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

索引操作

  • SELECT group_id, phone FROM customer WHERE group_id BETWEEN 300 AND 400 [ORDER BY column LIMIT n OFFSET m]
  • SELECT group_id, phone FROM customer WHERE group_id IN (300, 301, 307, 311) [ORDER BY column LIMIT n OFFSET m]
  • DELETE FROM customer WHERE group_id BETWEEN 300 AND 400 [ORDER BY column LIMIT n OFFSET m]
  • 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]
  • Introducing the Non-Relational Range Query – the IN() can contain ANY redis command that returns rows (e.g. LRANGE, SINTER, ZREVRANGE, etc…)

Get name and number of the 5 most recent active customers

SELECT name, phone FROM customer WHERE group_id IN ($LRANGE L_IND_recent_calls 0 5) [ORDER BY column LIMIT n OFFSET m]
<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>

Update Expressions

UPDATE expressions currently support the following functionalities (+=, -=, *=, /=, %=, ^=, ||=)

UPDATE customer SET phone = phone || ' ext 912', group_id = group_id * 4, age = age + 1 WHERE id = 1
<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>

http://code.google.com/p/alchemydatabase/

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!