Java Code Examples for redis.clients.util.SafeEncoder#encode()

The following examples show how to use redis.clients.util.SafeEncoder#encode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JRedisCache.java    From springJredisCache with Apache License 2.0 6 votes vote down vote up
/**
 * 通常为了适应大多数场景  还是使用这方式订阅吧
 * <p/>
 * 表达式的方式订阅
 * 使用模式匹配的方式设置要订阅的消息            订阅得到信息在JedisPubSub的onMessage(...)方法中进行处理
 *
 * @param patterns
 */
@Override
public void psubscribe(final String... patterns) {
    Jedis jedis = null;
    try {
        jedis = jedisPool.getResource();
        final byte[][] ps = new byte[patterns.length][];
        for (int i = 0; i < ps.length; i++) {
            ps[i] = SafeEncoder.encode(patterns[i]);
        }
        jedis.psubscribe(jRedisBinaryPubSub, ps);
    } catch (Exception ex) {
        coverException(ex, jedisPool, jedis);
    } finally {
        if (jedis != null && jedis.isConnected()) {
            jedisPool.returnResource(jedis);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("close redis connection-{" + jedis.toString() + "}");
            }
        }
    }
}
 
Example 2
Source File: JRedisCache.java    From springJredisCache with Apache License 2.0 6 votes vote down vote up
/**
 * 订阅指定的消息        订阅得到信息在JedisPubSub的onMessage(...)方法中进行处理
 *
 * @param channels
 */
@Override
public void subscribe(final String... channels) {
    Jedis jedis = null;
    try {
        jedis = jedisPool.getResource();
        final byte[][] ps = new byte[channels.length][];
        for (int i = 0; i < ps.length; i++) {
            ps[i] = SafeEncoder.encode(channels[i]);
        }
        jedis.subscribe(jRedisBinaryPubSub, ps);
    } catch (Exception ex) {
        coverException(ex, jedisPool, jedis);
    } finally {
        if (jedis != null && jedis.isConnected()) {
            jedisPool.returnResource(jedis);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("close redis connection-{" + jedis.toString() + "}");
            }
        }
    }
}
 
Example 3
Source File: JRedisCache.java    From springJredisCache with Apache License 2.0 5 votes vote down vote up
/**
 * 取消订阅的channel
 *
 * @param channels
 */
@Override
public void unsubscribe(String... channels) {
    final byte[][] ps = new byte[channels.length][];
    for (int i = 0; i < ps.length; i++) {
        ps[i] = SafeEncoder.encode(channels[i]);
    }
    jRedisBinaryPubSub.unsubscribe(ps);
}
 
Example 4
Source File: PipelineCluster.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
public Set<byte[]> hkeysBytes(final String key) {
    final byte[] keyByte = SafeEncoder.encode(key);
    return new JedisClusterCommand<Set<byte[]>>(connectionHandler, maxRedirections) {
        public Set<byte[]> execute(Jedis connection) {
            return connection.hkeys(SafeEncoder.encode(key));
        }
    }.runBinary(keyByte);
}
 
Example 5
Source File: Client.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
public void unsubscribe(final String... channels) {
  final byte[][] cs = new byte[channels.length][];
  for (int i = 0; i < cs.length; i++) {
    cs[i] = SafeEncoder.encode(channels[i]);
  }
  unsubscribe(cs);
}
 
Example 6
Source File: Client.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
public void subscribe(final String... channels) {
  final byte[][] cs = new byte[channels.length][];
  for (int i = 0; i < cs.length; i++) {
    cs[i] = SafeEncoder.encode(channels[i]);
  }
  subscribe(cs);
}
 
Example 7
Source File: ObjectCommandsTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test
public void objectEncoding() {
  jedis.lpush(key, "hello world");
  String encoding = jedis.objectEncoding(key);
  assertEquals("quicklist", encoding);

  // Binary
  encoding = SafeEncoder.encode(jedis.objectEncoding(binaryKey));
  assertEquals("quicklist", encoding);
}
 
Example 8
Source File: Client.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Override
public void watch(final String... keys) {
  final byte[][] bargs = new byte[keys.length][];
  for (int i = 0; i < bargs.length; i++) {
    bargs[i] = SafeEncoder.encode(keys[i]);
  }
  watch(bargs);
}
 
Example 9
Source File: Client.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Override
public void brpop(final String[] args) {
  final byte[][] bargs = new byte[args.length][];
  for (int i = 0; i < bargs.length; i++) {
    bargs[i] = SafeEncoder.encode(args[i]);
  }
  brpop(bargs);
}
 
Example 10
Source File: PipelineCluster.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
public Set<byte[]> zrevrangeByScoreBytes(final String key, final String max,
                                         final String min, final int offset, final int count) {
    final byte[] keyByte = SafeEncoder.encode(key);
    return new JedisClusterCommand<Set<byte[]>>(connectionHandler, maxRedirections) {
        public Set<byte[]> execute(Jedis connection) {
            return connection.zrevrangeByScore(keyByte,
                    SafeEncoder.encode(max), SafeEncoder.encode(min), offset, count);
        }
    }.runBinary(keyByte);
}
 
Example 11
Source File: PipelineCluster.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
public Set<Tuple> zrevrangeWithScoresBytes(final String key, final long start, final long end) {
    final byte[] keyByte = SafeEncoder.encode(key);
    return new JedisClusterCommand<Set<Tuple>>(connectionHandler, maxRedirections) {
        @Override
        public Set<Tuple> execute(Jedis connection) {
            return connection.zrevrangeWithScores(keyByte, start, end);
        }
    }.runBinary(keyByte);
}
 
Example 12
Source File: Client.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
public void punsubscribe(final String... patterns) {
  final byte[][] ps = new byte[patterns.length][];
  for (int i = 0; i < ps.length; i++) {
    ps[i] = SafeEncoder.encode(patterns[i]);
  }
  punsubscribe(ps);
}
 
Example 13
Source File: PipelineCluster.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
public String setex(final String key, final int seconds, final byte[] value) {
    final byte[] keyByte = SafeEncoder.encode(key);
    return new JedisClusterCommand<String>(connectionHandler, maxRedirections) {
        public String execute(Jedis connection) {
            return connection.setex(keyByte, seconds, value);
        }
    }.runBinary(keyByte);
}
 
Example 14
Source File: PipelineCluster.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
public Long hset(final String key, final String field, final byte[] value) {
    final byte[] keyByte = SafeEncoder.encode(key);
    return new JedisClusterCommand<Long>(connectionHandler, maxRedirections) {
        public Long execute(Jedis connection) {
            return connection.hset(keyByte, SafeEncoder.encode(field), value);
        }
    }.runBinary(keyByte);
}
 
Example 15
Source File: PipelineCluster.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
public Set<byte[]> zrangeByScoreBytes(final String key, final String min,
                                      final String max, final int offset, final int count) {
    final byte[] keyByte = SafeEncoder.encode(key);
    return new JedisClusterCommand<Set<byte[]>>(connectionHandler, maxRedirections) {

        public Set<byte[]> execute(Jedis connection) {
            return connection.zrangeByScore(keyByte,
                    SafeEncoder.encode(min), SafeEncoder.encode(max), offset, count);
        }
    }.runBinary(keyByte);
}
 
Example 16
Source File: PipelineCluster.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
public Double zincrby(final String key, final double score,
                      final byte[] member) {
    final byte[] keyByte = SafeEncoder.encode(key);
    return new JedisClusterCommand<Double>(connectionHandler, maxRedirections) {
        public Double execute(Jedis connection) {
            return connection.zincrby(keyByte, score, member);
        }
    }.runBinary(keyByte);
}
 
Example 17
Source File: PipelineCluster.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
public List<byte[]> blpopBytes(final String arg) {
    final byte[] keyByte = SafeEncoder.encode(arg);
    return new JedisClusterCommand<List<byte[]>>(connectionHandler, maxRedirections) {
        public List<byte[]> execute(Jedis connection) {
            return connection.blpop(keyByte);
        }
    }.runBinary(keyByte);
}
 
Example 18
Source File: Protocol.java    From cachecloud with Apache License 2.0 4 votes vote down vote up
Keyword() {
  raw = SafeEncoder.encode(this.name().toLowerCase());
}
 
Example 19
Source File: ScanResult.java    From cachecloud with Apache License 2.0 4 votes vote down vote up
public ScanResult(String cursor, List<T> results) {
  this(SafeEncoder.encode(cursor), results);
}
 
Example 20
Source File: RedisObject.java    From jeesuite-libs with Apache License 2.0 2 votes vote down vote up
/**
 * 重置key(适合一个方法里面频繁操作不同缓存的场景)<br>
 * <font color="red">非线程安全,请不要在多线程场景使用</font>
 * @param key
 * @return
 */
public RedisObject resetKey(String key){
	this.key = key;
	this.keyBytes = SafeEncoder.encode(key);
	return this;
}