跳到主要內容

Redis @ SmartOS

Redis也是一套NoSQL資料庫,使用key-value的方式來儲存string, hashes, lists, sets...
下面是官方介紹Redis的一段說明:

Redis is an open source, advanced key-value store. It is often referred to as a data structure server since keys can containstringshasheslistssets and sorted sets.

一如往常,SmartOS上安裝Redis只有兩個步驟:

# pkgin search redis
php5-redis-5.2.17.2.1.3  PHP extension for Redis
php53-redis-5.3.6.2.1.3  PHP extension for Redis
redis-2.2.14         Persistent key-value database with built-in net interface

=: package is installed and up-to-date
<: package is installed but newer version is available
>: installed package has a greater version than available package

# pkgin install redis-2.2.14
calculating dependencies... done.

nothing to upgrade.
1 packages to be installed: redis-2.2.14 (406K to download, 1316K to install)

proceed ? [y/N] y
downloading packages...
downloading redis-2.2.14.tgz:  203Kbps 100%
error log can be found in /var/db/pkgin/err.log
installing packages...
installing redis-2.2.14...
redis-2.2.14: Creating group ``redis''
redis-2.2.14: Creating user ``redis''
redis-2.2.14: copying /opt/local/share/examples/redis/redis.conf.example to /opt/local/etc/redis.conf
===========================================================================
The following files should be created for redis-2.2.14:

        /etc/rc.d/redis (m=0755)
            [/opt/local/share/examples/rc.d/redis]

===========================================================================
//////////////////////////////////////////////////////////////////////////////

This package is SMF enabled, which means you can use SMF to 'enable',
'disable' or 'restart' the persistent daemon process, e.g.:

  svcadm enable redis

The SMF manifest was automatically imported now.

See our wiki on what's SMF and how to use it to your advantage:


//////////////////////////////////////////////////////////////////////////////
processing local summary...
updating database: 100%
marking redis-2.2.14 as non auto-removable

因Redis預設在安裝時候設定成SMF服務,安裝完成後可以使用svcadm啓動他:

svcadm enable redis

Redis預設提供了一個CLI介面,安裝完成後,可透過redis-cli啓動

# redis-cli 
redis 127.0.0.1:6379
redis 127.0.0.1:6379> ?
redis-cli 2.2.14
Type: "help @<group>" to get a list of commands in <group>
      "help <command>" for help on <command>
      "help <tab>" to get a list of possible help topics
      "quit" to exit

PS: 在官方文件中有提供簡單的教程:http://redis.io/topics/data-types-intro

這邊實作一下於Redis置入string物件的CLI方式

redis 127.0.0.1:6379> set mykey "simon1"
OK
redis 127.0.0.1:6379> get mykey
"simon1"
redis 127.0.0.1:6379> set mykey2 "simon2"
OK
redis 127.0.0.1:6379> get mykey2
"simon2"

同時,Redis也提供許多語言的連接實作,可在這邊找到:http://redis.io/clients
而官網建議的clinet實作for Node.js版本為:https://github.com/mranney/node_redis
下面是node_redis client的範例: (redis.print為callback function)

#redis_example.js 
var redis = require("redis"),
    client = redis.createClient();

client.on("error", function (err) {
    console.log("Error " + err);
});

client.set("string key", "string val", redis.print); //儲存string型態物件
client.get("string key", redis.print); //取回string型態物件

client.hset("hash key", "hashtest 1", "some value", redis.print); //儲存Hash型態物件
client.hset(["hash key", "hashtest 2", "some other value"], redis.print);
client.hkeys("hash key", function (err, replies) { //取回Hash型態物件值
    console.log(replies.length + " replies:");
    replies.forEach(function (reply, i) {
       console.log("    " + i + ": " + reply);
    });
    client.quit();
});

範例執行結果:

#node redis_example.js
Reply: OK
Reply: string val
Reply: 1
Reply: 1
2 replies:
    0: hashtest 1
    1: hashtest 2

承上,redis為與installed server互動的一個NoSQL資料形態,網路上介紹的大部份是屬於執行於redis server上的應用,目前關於redis的server不多的應用不多,相關的實作資訊如下:
以上,Redis是一套不錯的NoSQL系統,相信在許多應用系統上可以使用Redis實作,但因為他相對為較基礎之資料結構實作,不像資料庫系統擁有許多像cluster, load balance, replicate, grid...的功能,但是卻擁有他單純的好處。


這個網誌中的熱門文章

Oracle LISTAGG

同事介紹的一個Oracle的好用查詢:LISTAGG
SELECT A.GROUP_ID,A.KEY, LISTAGG(A.VALUE,'; ')WITHINGROUP(ORDERBYA.VALUE)as GG  fromSYS_PROPERTIESaGROUP byA.GROUP_ID,A.KEY
LISTAGG可以將group後的結果會總顯示於一個欄位 上述SQL原本A.VALUE會是一個row一個row的排列 使用LISTAGG之後,可以將A.VALUE顯示在同一個row中 並且可以指定間隔符號(在此設定為';') 針對某一些報表查詢非常有用唷 :D

Flashback Query

感謝我的好友提供的: 在Oracle好用的指令...
Flashback Query: 讓異動過的資料表回到歷史時間點 Step 1. è
show parameter undo_retention  PS: 這個參數顯示系統上設定歷史保留時間(ex: 900 = 900秒) Step 2. è CREATETABLE XXXXX_0815 ASSELECT *  FROM XXXXXASOFTIMESTAMPTO_TIMESTAMP('2011-08-15 12:00:00','YYYY-MM-DD HH24:MI:SS');
PS: 透過as of timestamp方式取出該時間點的表格資料

Xoom 3.2 Upgrade

雖然Xoom早已經更新到3.2 但是台灣遲遲沒有更新版本@@ 終於按奈不住好奇心了... XDA上找到給604(台版Xoom)的3.2版本ROM(美版的) 動手刷拉~~ 出奇的順利阿... 下面是兩個相關網址:
http://forum.xda-developers.com/showthread.php?t=1165998
http://forum.xda-developers.com/showthread.php?t=1080963
我這邊是刷第二各網址下載的3.2 ROM(http://www.mediafire.com/?adsa081m3z8uykd) 3.1的就沒去測拉... 也沒有再去破解(遲早的ㄅ:P)
使用心得: 1. 順~比3.0操頻還順 2. 原生就支援micro-sd 3. 目前看是不支援USB...缺憾@@ 4. 因為美版的關係,所以有Books跟Videos兩個APP,但是因為網路地區的關係不能用就是了... 5. 沒有原生中文輸入法,不過對我沒差...我都用Google拼音 :D