Redis @ SmartOS

Redis也是一套NoSQL資料庫,使用key-value的方式來儲存string, hashes, lists, sets...

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.


# pkgin search redis
php5-redis-  PHP extension for Redis
php53-redis-  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)


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


svcadm enable redis


# redis-cli 
redis> ?
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: 在官方文件中有提供簡單的教程:


redis> set mykey "simon1"
redis> get mykey
redis> set mykey2 "simon2"
redis> get mykey2

而官網建議的clinet實作for Node.js版本為:
下面是node_redis client的範例: (redis.print為callback function)

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);


#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...的功能,但是卻擁有他單純的好處。