コード例 #1
0
ファイル: Plot.java プロジェクト: Minecarts/ChunkControl
 private boolean set(final String key, final Object value) {
   RedisConnection<String, String> redis = ChunkControl.getPlugin().redis();
   return redis.hset(
       String.format("chunk:%s:%d", key, chunk.getX()),
       String.format("%d", chunk.getZ()),
       String.valueOf(value));
 }
コード例 #2
0
  public RedisConnection<String, String> connect() {
    RedisConnection<String, String> connection = redisClient.connect();

    String password = getConfig().getString("redis.password");
    if (password != null) connection.auth(password);

    return connection;
  }
コード例 #3
0
 @Test
 public void connectToRedisUsingSentinelWithReconnect() throws Exception {
   RedisConnection<String, String> connect = sentinelClient.connect().sync();
   connect.ping();
   connect.quit();
   connect.ping();
   connect.close();
 }
コード例 #4
0
 @SuppressWarnings({"unchecked", "rawtypes"})
 @Override
 public void put(Object key, Object value) {
   if (value instanceof Map) {
     connection.hmset(key.toString(), (Map) value);
   } else {
     connection.set(key.toString(), value.toString());
   }
   if (keyExpiryTime != -1) {
     connection.expire(key.toString(), keyExpiryTime);
   }
 }
コード例 #5
0
ファイル: ReadWriteExample.java プロジェクト: turboic/lettuce
  public static void main(String[] args) {
    // Syntax: redis://[password@]host[:port][/databaseNumber]
    RedisClient redisClient = new RedisClient(RedisURI.create("redis://password@localhost:6379/0"));
    RedisConnection<String, String> connection = redisClient.connect();
    System.out.println("Connected to Redis");

    connection.set("foo", "bar");
    String value = connection.get("foo");
    System.out.println(value);

    connection.close();
    redisClient.shutdown();
  }
コード例 #6
0
 /**
  * Gets the value given the key. Note that it does NOT work with hash values or list values
  *
  * @param key
  * @return value of the key.
  */
 @Override
 public Object get(Object key) {
   if (isInTransaction()) {
     throw new RuntimeException("Cannot call get when in redis transaction");
   }
   return connection.get(key.toString());
 }
コード例 #7
0
 /**
  * Gets all the values given the keys. Note that it does NOT work with hash values or list values
  *
  * @param keys
  * @return values of the keys.
  */
 @SuppressWarnings("unchecked")
 @Override
 public List<Object> getAll(List<Object> keys) {
   if (isInTransaction()) {
     throw new RuntimeException("Cannot call get when in redis transaction");
   }
   return (List<Object>) (List<?>) connection.mget(keys.toArray(new String[] {}));
 }
コード例 #8
0
  @Override
  public void putAll(Map<Object, Object> m) {

    Map<String, String> params = Maps.newHashMap();
    for (Map.Entry<Object, Object> entry : m.entrySet()) {
      params.put(entry.getKey().toString(), entry.getValue().toString());
    }
    connection.mset(params);
  }
コード例 #9
0
    @Override
    public void execute(Tuple tuple) {
      // access the first column 'word'
      String word = tuple.getStringByField("word");

      // access the second column 'count'
      Integer count = tuple.getIntegerByField("count");

      // publish the word count to redis using word as the key
      redis.publish("WordCountTopology", word + "|" + Long.toString(count));
    }
コード例 #10
0
  @Test
  public void sentinelConnectWith() throws Exception {

    RedisClient client =
        new RedisClient(
            RedisURI.Builder.sentinel(TestSettings.host(), 1234, MASTER_ID)
                .withSentinel(TestSettings.host())
                .build());

    RedisSentinelAsyncCommands<String, String> sentinelConnection = client.connectSentinelAsync();
    assertThat(sentinelConnection.ping().get()).isEqualTo("PONG");

    sentinelConnection.close();

    RedisConnection<String, String> connection2 = client.connect().sync();
    assertThat(connection2.ping()).isEqualTo("PONG");
    connection2.quit();

    Wait.untilTrue(connection2::isOpen).waitOrTimeout();

    assertThat(connection2.ping()).isEqualTo("PONG");
    connection2.close();
    FastShutdown.shutdown(client);
  }
コード例 #11
0
 @Override
 public void rollbackTransaction() {
   connection.discard();
   inTransaction = false;
 }
コード例 #12
0
ファイル: Plot.java プロジェクト: Minecarts/ChunkControl
 private String get(final String key) {
   RedisConnection<String, String> redis = ChunkControl.getPlugin().redis();
   return redis.hget(
       String.format("chunk:%s:%d", key, chunk.getX()), String.format("%d", chunk.getZ()));
 }
コード例 #13
0
 /**
  * Calls incrbyfloat on the redis store.
  *
  * @param key
  * @param doubleValue
  */
 public void incrByFloat(String key, double doubleValue) {
   connection.incrbyfloat(key, doubleValue);
   if (keyExpiryTime != -1) {
     connection.expire(key, keyExpiryTime);
   }
 }
コード例 #14
0
 @Override
 public void remove(Object key) {
   connection.del(key.toString());
 }
コード例 #15
0
ファイル: Plot.java プロジェクト: Minecarts/ChunkControl
 private double add(final String key, final double value) {
   RedisConnection<String, String> redis = ChunkControl.getPlugin().redis();
   return redis.hincrbyfloat(
       String.format("chunk:%s:%d", key, chunk.getX()), String.format("%d", chunk.getZ()), value);
 }
コード例 #16
0
 @Override
 public void connect() throws IOException {
   client = new RedisClient(host, port);
   connection = client.connect();
   connection.select(dbIndex);
 }
コード例 #17
0
 @Override
 public void beginTransaction() {
   connection.multi();
   inTransaction = true;
 }
コード例 #18
0
 @Override
 public void commitTransaction() {
   connection.exec();
   inTransaction = false;
 }