create alias if not exists jredis_zrangebyscore as $$
import java.io.*;
import java.util.*;
import java.sql.*;
import org.h2.tools.*;
import java.net.*;
import org.jredis.ri.alphazero.*;
import org.jredis.ri.alphazero.support.*;
@CODE
ResultSet jredis_zrangebyscore(String host, Integer intPort,
String key, Double from, Double to)
throws Exception
{
if( host == null ){
throw new Exception("host is not specified.");
}
int port = 6379;
if( intPort != null ){
port = intPort.intValue();
}
if( key == null ){
throw new Exception("key is not specified.");
}
if( from == null ){
throw new Exception("from is not specified.");
}
if( to == null ){
throw new Exception("to is not specified.");
}
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("ELEMENT", Types.VARCHAR, 4096, 0);
JRedisClient jrc = new JRedisClient(host, port);
for(byte elem[] : jrc.zrangebyscore(key, from, to)){
rs.addRow(elem==null?null:DefaultCodec.toStr(elem));
}
return rs;
}
$$
実行例
select jredis_del('192.168.1.25', 6379, 'sset1');
select jredis_zadd('192.168.1.25', 6379, 'sset1', 100, 'value1');
select jredis_zadd('192.168.1.25', 6379, 'sset1', 200, 'value2');
select jredis_zadd('192.168.1.25', 6379, 'sset1', 300, 'value3');
select * from jredis_zrangebyscore('192.168.1.25', 6379, 'sset1', 200, 300);
※以下のjarをCLASSPATH環境変数に追加
jredis-core-all-a.0-SNAPSHOT-jar-with-dependencies.jar
○動作環境
JDK6 Update23, H2 Database 1.3.149 (2011-01-07), JRedis2.0.0
○関連情報
・H2 Databaseに関する他の記事はこちらを参照してください。
0 件のコメント:
コメントを投稿