de.topicmapslab.majortom.redis.util
Class RedisHandler

java.lang.Object
  extended by de.topicmapslab.majortom.redis.util.RedisHandler

public class RedisHandler
extends java.lang.Object

Utility class to connect to Redis store and enable concurrent access

Author:
Sven Krosse

Field Summary
private static java.lang.String AUTO_INCREMENT_KEY
           
private  int database
           
private  java.lang.String host
           
private  redis.clients.jedis.Jedis jedis
           
private static java.util.concurrent.locks.Lock lock
           
private  java.lang.String password
           
private  int port
           
 
Constructor Summary
RedisHandler(java.lang.String host, int port, java.lang.String password, int database)
          constructor
 
Method Summary
 java.lang.Object call(java.lang.String method, java.lang.Object... arguments)
           
 void clear()
          Clear the database
 void del(java.lang.String... keys)
          Delete the keys
 boolean exists(java.lang.String key)
           
 java.lang.String get(java.lang.String key)
          Fetch the value for the given key.
 java.lang.String get(java.lang.String key, java.lang.String field)
          Fetch the value for the given key.
 void hdel(java.lang.String key, java.lang.String field)
          Fetch the value for the given key.
 java.util.Map<java.lang.String,java.lang.String> hgetall(java.lang.String key)
          Fetch all key-value-pairs for the given key.
 java.util.Set<java.lang.String> list(java.lang.String filter)
          Returns all known keys
 long nextId()
          Returns a new construct id from redis
 redis.clients.jedis.Pipeline pipeline()
          Returns a pipeline (Which is used OUTSIDE the LOCK)!!!
private  void reconnect()
          Internal method to open a connection and close existing one
 void sadd(java.lang.String key, java.lang.String value)
          Store the given value for the given key.
 void set(java.lang.String key, java.lang.String value)
          Store the given value for the given key.
 void set(java.lang.String key, java.lang.String field, java.lang.String value)
          Store the given value for the given key.
 java.util.Set<java.lang.String> sinter(java.lang.String... keys)
          Calls intersect
 java.util.Set<java.lang.String> smembers(java.lang.String key)
          Fetch the value for the given key.
 void srem(java.lang.String key, java.lang.String member)
           
 java.util.Set<java.lang.String> sunion(java.lang.String... keys)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AUTO_INCREMENT_KEY

private static final java.lang.String AUTO_INCREMENT_KEY
See Also:
Constant Field Values

lock

private static final java.util.concurrent.locks.Lock lock

jedis

private redis.clients.jedis.Jedis jedis

host

private final java.lang.String host

port

private final int port

password

private final java.lang.String password

database

private final int database
Constructor Detail

RedisHandler

public RedisHandler(java.lang.String host,
                    int port,
                    java.lang.String password,
                    int database)
constructor

Parameters:
host - the host
port - the port or Integer.MIN_VALUE if port is not needed
password - the password or null if password is not needed
database - the database number
Method Detail

reconnect

private void reconnect()
Internal method to open a connection and close existing one


get

public java.lang.String get(java.lang.String key)
Fetch the value for the given key. The method locked for all threads until caller is finished.

Parameters:
key - the key
Returns:
the value

exists

public boolean exists(java.lang.String key)

smembers

public java.util.Set<java.lang.String> smembers(java.lang.String key)
Fetch the value for the given key. The method locked for all threads until caller is finished.

Parameters:
key - the key
Returns:
the value

get

public java.lang.String get(java.lang.String key,
                            java.lang.String field)
Fetch the value for the given key. The method locked for all threads until caller is finished.

Parameters:
key - the key
field - the field
Returns:
the value

hgetall

public java.util.Map<java.lang.String,java.lang.String> hgetall(java.lang.String key)
Fetch all key-value-pairs for the given key. The method locked for all threads until caller is finished.

Parameters:
key - the key
Returns:
the key-value-pairs

hdel

public void hdel(java.lang.String key,
                 java.lang.String field)
Fetch the value for the given key. The method locked for all threads until caller is finished.

Parameters:
key - the key
field - the field

del

public void del(java.lang.String... keys)
Delete the keys

Parameters:
keys - the keys

set

public void set(java.lang.String key,
                java.lang.String value)
Store the given value for the given key. The method locked for all threads until caller is finished.

Parameters:
key - the key
value - the value

set

public void set(java.lang.String key,
                java.lang.String field,
                java.lang.String value)
Store the given value for the given key. The method locked for all threads until caller is finished.

Parameters:
key - the key
value - the value

sadd

public void sadd(java.lang.String key,
                 java.lang.String value)
Store the given value for the given key. The method locked for all threads until caller is finished.

Parameters:
key - the key
value - the value

call

public java.lang.Object call(java.lang.String method,
                             java.lang.Object... arguments)

sinter

public java.util.Set<java.lang.String> sinter(java.lang.String... keys)
Calls intersect

Parameters:
keys - the keys
Returns:
the intersect result

nextId

public long nextId()
Returns a new construct id from redis

Returns:
the new redis id

list

public java.util.Set<java.lang.String> list(java.lang.String filter)
Returns all known keys

Parameters:
filter - the filter
Returns:
the key set

sunion

public java.util.Set<java.lang.String> sunion(java.lang.String... keys)

srem

public void srem(java.lang.String key,
                 java.lang.String member)

clear

public void clear()
Clear the database


pipeline

public redis.clients.jedis.Pipeline pipeline()
Returns a pipeline (Which is used OUTSIDE the LOCK)!!!