ラベル H2Database_JRedis の投稿を表示しています。 すべての投稿を表示
ラベル H2Database_JRedis の投稿を表示しています。 すべての投稿を表示

2011年4月3日日曜日

H2 DatabaseとJRedisでキー値が存在しない場合のみ値を設定する関数を作成する

H2 DatabaseとJRedisでキー値が存在しない場合のみ値を設定する関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jredis_setnx 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
Boolean jredis_setnx(String host, Integer intPort,
String key, String value)
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( value == null ){
throw new Exception("value is not specified.");
}

JRedisClient jrc = new JRedisClient(host, port);
return jrc.setnx(key, value);
}
$$

実行例
select jredis_del('192.168.1.25', 6379, 'key1');
select jredis_del('192.168.1.25', 6379, 'key2');
select jredis_set('192.168.1.25', 6379, 'key1', 'value1');
select jredis_setnx('192.168.1.25', 6379, 'key1', 'modified');
select jredis_setnx('192.168.1.25', 6379, 'key2', 'modified');
select jredis_get('192.168.1.25', 6379, 'key1');
select jredis_get('192.168.1.25', 6379, 'key2');

※以下の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に関する他の記事はこちらを参照してください。

2011年4月1日金曜日

H2 DatabaseとJRedisで新しい値を設定して古い値を返す関数を作成する

H2 DatabaseとJRedisで新しい値を設定して古い値を返す関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jredis_getset 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
String jredis_getset(String host, Integer intPort,
String key, String value)
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( value == null ){
throw new Exception("value is not specified.");
}

JRedisClient jrc = new JRedisClient(host, port);
byte result[] = jrc.getset(key, value);
return result==null?null:DefaultCodec.toStr(result);
}
$$

実行例
select jredis_del('192.168.1.25', 6379, 'key1');
select jredis_set('192.168.1.25', 6379, 'key1', 'value1');
select jredis_getset('192.168.1.25', 6379, 'key1', 'modified');
select jredis_get('192.168.1.25', 6379, 'key1');

※以下の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に関する他の記事はこちらを参照してください。

2011年3月31日木曜日

H2 DatabaseとJRedisでSorted Setの値のスコアを取得する関数を作成する

H2 DatabaseとJRedisでSorted Setの値のスコアを取得する関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jredis_zscore 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
Double jredis_zscore(String host, Integer intPort,
String key, String value)
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( value == null ){
throw new Exception("value is not specified.");
}

JRedisClient jrc = new JRedisClient(host, port);
return jrc.zscore(key, value);
}
$$

実行例
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 jredis_zscore('192.168.1.25', 6379, 'sset1', 'value3');

※以下の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に関する他の記事はこちらを参照してください。

2011年3月30日水曜日

H2 DatabaseとJRedisでSorted Setから値を削除する関数を作成する

H2 DatabaseとJRedisでSorted Setから値を削除する関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jredis_zrem 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
Boolean jredis_zrem(String host, Integer intPort,
String key, String value)
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( value == null ){
throw new Exception("value is not specified.");
}

JRedisClient jrc = new JRedisClient(host, port);
return jrc.zrem(key, value);
}
$$

実行例
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 jredis_zrem('192.168.1.25', 6379, 'sset1', 'value3');
select * from jredis_zrange('192.168.1.25', 6379, 'sset1', 0, -1);

※以下の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に関する他の記事はこちらを参照してください。

2011年3月29日火曜日

H2 DatabaseとJRedisでSorted Setからインデックスの範囲で逆順で値を取得する関数を作成する

H2 DatabaseとJRedisでSorted Setからインデックスの範囲で逆順で値を取得する関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jredis_zrevrange 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_zrevrange(String host, Integer intPort,
String key, Long from, Long 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.zrevrange(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_zrevrange('192.168.1.25', 6379, 'sset1', 0, -1);

※以下の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に関する他の記事はこちらを参照してください。

2011年3月28日月曜日

H2 DatabaseとJRedisでスコアの範囲でSorted Setの値を取得する

H2 DatabaseとJRedisでスコアの範囲でSorted Setの値を取得するには、以下のスクリプトを実行します。

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に関する他の記事はこちらを参照してください。

2011年3月27日日曜日

H2 DatabaseとJRedisでSorted Setの要素数を取得する関数を作成する

H2 DatabaseとJRedisでSorted Setの要素数を取得する関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jredis_zcard 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
Long jredis_zcard(String host, Integer intPort,
String key)
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.");
}

JRedisClient jrc = new JRedisClient(host, port);
return jrc.zcard(key);
}
$$

実行例
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 jredis_zcard('192.168.1.25', 6379, 'sset1');

※以下の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に関する他の記事はこちらを参照してください。

2011年3月26日土曜日

H2 DatabaseとJRedisでSorted Setの値のスコアをインクリメントする関数を作成する

H2 DatabaseとJRedisでSorted Setの値のスコアをインクリメントする関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jredis_zincrby 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
Double jredis_zincrby(String host, Integer intPort,
String key, Double score, String value)
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( score == null ){
throw new Exception("score is not specified.");
}
if( value == null ){
throw new Exception("value is not specified.");
}

JRedisClient jrc = new JRedisClient(host, port);
return jrc.zincrby(key, score, value);
}
$$

実行例
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 jredis_zincrby('192.168.1.25', 6379, 'sset1', 1000, 'value2');
select * from jredis_zrange('192.168.1.25', 6379, 'sset1', 0, -1);

※以下の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に関する他の記事はこちらを参照してください。

2011年3月25日金曜日

H2 DatabaseとJRedisでSorted Setからインデックスの範囲で値を取得する関数を作成する

H2 DatabaseとJRedisでSorted Setからインデックスの範囲で値を取得する関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jredis_zrange 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_zrange(String host, Integer intPort,
String key, Long from, Long 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.zrange(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_zrange('192.168.1.25', 6379, 'sset1', 0, -1);

※以下の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に関する他の記事はこちらを参照してください。

2011年3月24日木曜日

H2 DatabaseとJRedisでSorted Setに値を追加する関数を作成する

H2 DatabaseとJRedisでSorted Setに値を追加する関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jredis_zadd 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
Boolean jredis_zadd(String host, Integer intPort,
String key, Double score, String value)
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( score == null ){
throw new Exception("score is not specified.");
}
if( value == null ){
throw new Exception("value is not specified.");
}

JRedisClient jrc = new JRedisClient(host, port);
return jrc.zadd(key, score, value);
}
$$

実行例
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');

※以下の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に関する他の記事はこちらを参照してください。

2011年3月23日水曜日

H2 DatabaseとJRedisでセットから値を削除する関数を作成する

H2 DatabaseとJRedisでセットから値を削除する関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jredis_srem 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
Boolean jredis_srem(String host, Integer intPort,
String key, String value)
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( value == null ){
throw new Exception("value is not specified.");
}

JRedisClient jrc = new JRedisClient(host, port);
return jrc.srem(key, value);
}
$$

実行例
select jredis_del('192.168.1.25', 6379, 'set1');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value1');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value2');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value3');
select jredis_srem('192.168.1.25', 6379, 'set1', 'value1');
select * from jredis_smembers('192.168.1.25', 6379, 'set1');

※以下の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に関する他の記事はこちらを参照してください。

2011年3月22日火曜日

H2 DatabaseとJRedisでサーバの情報を返す関数を作成する

H2 DatabaseとJRedisでサーバの情報を返す関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jredis_info 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_info(String host, Integer intPort)
throws Exception
{
if( host == null ){
throw new Exception("host is not specified.");
}
int port = 6379;
if( intPort != null ){
port = intPort.intValue();
}
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("KEY", Types.VARCHAR, 4096, 0);
rs.addColumn("VALUE", Types.VARCHAR, 4096, 0);

JRedisClient jrc = new JRedisClient(host, port);
for(Map.Entry elem : jrc.info().entrySet()){
rs.addRow(elem.getKey(), elem.getValue());
}

return rs;
}
$$

実行例
select * from jredis_info('192.168.1.25', 6379);

※以下の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に関する他の記事はこちらを参照してください。

2011年3月21日月曜日

H2 DatabaseとJRedisで複数のセットから差集合を作成する関数を作成する

H2 DatabaseとJRedisで複数のセットから差集合を作成する関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jredis_sdiffstore 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
Integer jredis_sdiffstore(String host, Integer intPort,
String dest, String set1, String set2)
throws Exception
{
if( host == null ){
throw new Exception("host is not specified.");
}
int port = 6379;
if( intPort != null ){
port = intPort.intValue();
}
if( dest == null ){
throw new Exception("dest is not specified.");
}
if( set1 == null ){
throw new Exception("set1 is not specified.");
}
if( set2 == null ){
throw new Exception("set2 is not specified.");
}

JRedisClient jrc = new JRedisClient(host, port);
jrc.sdiffstore(dest, set1, set2);
return new Integer(0);
}
$$

実行例
select jredis_del('192.168.1.25', 6379, 'set1');
select jredis_del('192.168.1.25', 6379, 'set2');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value1');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value2');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value3');
select jredis_sadd('192.168.1.25', 6379, 'set2', 'value2');
select jredis_sadd('192.168.1.25', 6379, 'set2', 'value5');
select jredis_sdiffstore('192.168.1.25', 6379, 'rs', 'set1', 'set2');
select * from jredis_smembers('192.168.1.25', 6379, 'rs');

※以下の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に関する他の記事はこちらを参照してください。

2011年3月20日日曜日

H2 DatabaseとJRedisで複数のセットから和集合を作成する関数を作成する

H2 DatabaseとJRedisで複数のセットから和集合を作成する関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jredis_sunionstore 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
Integer jredis_sunionstore(String host, Integer intPort,
String dest, String set1, String set2)
throws Exception
{
if( host == null ){
throw new Exception("host is not specified.");
}
int port = 6379;
if( intPort != null ){
port = intPort.intValue();
}
if( dest == null ){
throw new Exception("dest is not specified.");
}
if( set1 == null ){
throw new Exception("set1 is not specified.");
}
if( set2 == null ){
throw new Exception("set2 is not specified.");
}

JRedisClient jrc = new JRedisClient(host, port);
jrc.sunionstore(dest, set1, set2);
return new Integer(0);
}
$$

実行例
select jredis_del('192.168.1.25', 6379, 'set1');
select jredis_del('192.168.1.25', 6379, 'set2');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value1');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value2');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value3');
select jredis_sadd('192.168.1.25', 6379, 'set2', 'value2');
select jredis_sadd('192.168.1.25', 6379, 'set2', 'value5');
select jredis_sunionstore('192.168.1.25', 6379, 'rs', 'set1', 'set2');
select * from jredis_smembers('192.168.1.25', 6379, 'rs');

※以下の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に関する他の記事はこちらを参照してください。

2011年3月19日土曜日

H2 DatabaseとJRedisで複数のセットから積集合を作成する関数を作成する

H2 DatabaseとJRedisで複数のセットから積集合を作成する関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jredis_sinterstore 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
Integer jredis_sinterstore(String host, Integer intPort,
String dest, String set1, String set2)
throws Exception
{
if( host == null ){
throw new Exception("host is not specified.");
}
int port = 6379;
if( intPort != null ){
port = intPort.intValue();
}
if( dest == null ){
throw new Exception("dest is not specified.");
}
if( set1 == null ){
throw new Exception("set1 is not specified.");
}
if( set2 == null ){
throw new Exception("set2 is not specified.");
}

JRedisClient jrc = new JRedisClient(host, port);
jrc.sinterstore(dest, set1, set2);
return new Integer(0);
}
$$

実行例
select jredis_del('192.168.1.25', 6379, 'set1');
select jredis_del('192.168.1.25', 6379, 'set2');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value1');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value2');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value3');
select jredis_sadd('192.168.1.25', 6379, 'set2', 'value2');
select jredis_sadd('192.168.1.25', 6379, 'set2', 'value5');
select jredis_sinterstore('192.168.1.25', 6379, 'rs', 'set1', 'set2');
select * from jredis_smembers('192.168.1.25', 6379, 'rs');

※以下の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に関する他の記事はこちらを参照してください。

2011年3月18日金曜日

H2 DatabaseとJRedisで複数のセットから差集合を返す関数を作成する

H2 DatabaseとJRedisで複数のセットから差集合を返す関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jredis_sdiff 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_sdiff(String host, Integer intPort,
String key1, String key2)
throws Exception
{
if( host == null ){
throw new Exception("host is not specified.");
}
int port = 6379;
if( intPort != null ){
port = intPort.intValue();
}
if( key1 == null ){
throw new Exception("key1 is not specified.");
}
if( key2 == null ){
throw new Exception("key2 is not specified.");
}
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("ELEMENT", Types.VARCHAR, 4096, 0);

JRedisClient jrc = new JRedisClient(host, port);
for(byte elem[] : jrc.sdiff(key1, key2)){
rs.addRow(elem==null?null:DefaultCodec.toStr(elem));
}
return rs;
}
$$

実行例
select jredis_del('192.168.1.25', 6379, 'set1');
select jredis_del('192.168.1.25', 6379, 'set2');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value1');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value2');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value3');
select jredis_sadd('192.168.1.25', 6379, 'set2', 'value2');
select jredis_sadd('192.168.1.25', 6379, 'set2', 'value5');
select * from jredis_sdiff('192.168.1.25', 6379, 'set1', 'set2');

※以下の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に関する他の記事はこちらを参照してください。

2011年3月17日木曜日

H2 DatabaseとJRedisで複数のセットから和集合を返す関数を作成する

H2 DatabaseとJRedisで複数のセットから和集合を返す関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jredis_sunion 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_sunion(String host, Integer intPort,
String key1, String key2)
throws Exception
{
if( host == null ){
throw new Exception("host is not specified.");
}
int port = 6379;
if( intPort != null ){
port = intPort.intValue();
}
if( key1 == null ){
throw new Exception("key1 is not specified.");
}
if( key2 == null ){
throw new Exception("key2 is not specified.");
}
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("ELEMENT", Types.VARCHAR, 4096, 0);

JRedisClient jrc = new JRedisClient(host, port);
for(byte elem[] : jrc.sunion(key1, key2)){
rs.addRow(elem==null?null:DefaultCodec.toStr(elem));
}
return rs;
}
$$

実行例
select jredis_del('192.168.1.25', 6379, 'set1');
select jredis_del('192.168.1.25', 6379, 'set2');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value1');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value2');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value3');
select jredis_sadd('192.168.1.25', 6379, 'set2', 'value2');
select jredis_sadd('192.168.1.25', 6379, 'set2', 'value5');
select * from jredis_sunion('192.168.1.25', 6379, 'set1', 'set2');

※以下の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に関する他の記事はこちらを参照してください。

2011年3月16日水曜日

H2 DatabaseとJRedisで複数のセットから積集合を返す関数を作成する

H2 DatabaseとJRedisで複数のセットから積集合を返す関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jredis_sinter 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_sinter(String host, Integer intPort,
String key1, String key2)
throws Exception
{
if( host == null ){
throw new Exception("host is not specified.");
}
int port = 6379;
if( intPort != null ){
port = intPort.intValue();
}
if( key1 == null ){
throw new Exception("key1 is not specified.");
}
if( key2 == null ){
throw new Exception("key2 is not specified.");
}
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("ELEMENT", Types.VARCHAR, 4096, 0);

JRedisClient jrc = new JRedisClient(host, port);
for(byte elem[] : jrc.sinter(key1, key2)){
rs.addRow(elem==null?null:DefaultCodec.toStr(elem));
}
return rs;
}
$$

実行例
select jredis_del('192.168.1.25', 6379, 'set1');
select jredis_del('192.168.1.25', 6379, 'set2');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value1');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value2');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value3');
select jredis_sadd('192.168.1.25', 6379, 'set2', 'value2');
select jredis_sadd('192.168.1.25', 6379, 'set2', 'value5');
select * from jredis_sinter('192.168.1.25', 6379, 'set1', 'set2');

※以下の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に関する他の記事はこちらを参照してください。

2011年3月15日火曜日

H2 DatabaseとJRedisでセットからランダムに値を返す関数を作成する

H2 DatabaseとJRedisでセットからランダムに値を返す関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jredis_srandmember 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
String jredis_srandmember(String host, Integer intPort,
String key)
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.");
}

JRedisClient jrc = new JRedisClient(host, port);
byte result[] = jrc.srandmember(key);
return result==null?null:DefaultCodec.toStr(result);
}
$$

実行例
select jredis_del('192.168.1.25', 6379, 'set1');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value1');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value2');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value3');
select jredis_srandmember('192.168.1.25', 6379, 'set1');

※以下の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に関する他の記事はこちらを参照してください。

2011年3月14日月曜日

H2 DatabaseとJRedisでセットの値を別のセットに移動させる関数を作成する

H2 DatabaseとJRedisでセットの値を別のセットに移動させる関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jredis_smove 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
Boolean jredis_smove(String host, Integer intPort,
String srcKey, String destKey, String value)
throws Exception
{
if( host == null ){
throw new Exception("host is not specified.");
}
int port = 6379;
if( intPort != null ){
port = intPort.intValue();
}
if( srcKey == null ){
throw new Exception("srcKey is not specified.");
}
if( destKey == null ){
throw new Exception("destKey is not specified.");
}
if( value == null ){
throw new Exception("value is not specified.");
}

JRedisClient jrc = new JRedisClient(host, port);
return jrc.smove(srcKey, destKey, value);
}
$$

実行例
select jredis_del('192.168.1.25', 6379, 'set1');
select jredis_del('192.168.1.25', 6379, 'set2');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value1');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value2');
select jredis_sadd('192.168.1.25', 6379, 'set1', 'value3');
select jredis_smove('192.168.1.25', 6379, 'set1', 'set2', 'value2');
select * from jredis_smembers('192.168.1.25', 6379, 'set1');
select * from jredis_smembers('192.168.1.25', 6379, 'set2');

※以下の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に関する他の記事はこちらを参照してください。