redis.clients.jedis.BinaryJedis Java Examples

The following examples show how to use redis.clients.jedis.BinaryJedis. 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: RedisGenericCache.java    From J2Cache with Apache License 2.0 6 votes vote down vote up
@Override
public void evict(String...keys) {
    try {
        BinaryJedisCommands cmd = client.get();
        if (cmd instanceof BinaryJedis) {
            byte[][] bytes = Arrays.stream(keys).map(k -> _key(k)).toArray(byte[][]::new);
            ((BinaryJedis)cmd).del(bytes);
        }
        else {
            for (String key : keys)
                cmd.del(_key(key));
        }
    } finally {
        client.release();
    }
}
 
Example #2
Source File: RedisCacheVendor.java    From jweb-cms with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Map<String, T> batchGet(List<String> keys) {
    try (BinaryJedis jedis = jedisPool.getResource()) {
        byte[][] cacheKeys = new byte[keys.size()][];
        for (int i = 0; i < keys.size(); i++) {
            cacheKeys[i] = redisKey(keys.get(i));
        }
        List<byte[]> jsonValues = jedis.mget(cacheKeys);
        Map<String, T> values = Maps.newHashMap();
        for (int i = 0; i < keys.size(); i++) {
            byte[] json = jsonValues.get(i);
            if (json != null) {
                RedisCacheItem<T> item = JSON.fromJSON(json, cacheClass);
                if (isValid(item)) {
                    values.put(keys.get(i), item.value);
                }
            }
        }
        return values;
    }
}
 
Example #3
Source File: RedisCacheVendor.java    From jweb-cms with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void batchDelete(List<String> keys) {
    try (BinaryJedis jedis = jedisPool.getResource()) {
        byte[][] cacheKeys = new byte[keys.size()][];
        for (int i = 0; i < keys.size(); i++) {
            cacheKeys[i] = redisKey(keys.get(i));
        }
        jedis.del(cacheKeys);
    }
}
 
Example #4
Source File: JedisTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test
public void checkCloseable() {
  jedis.close();
  BinaryJedis bj = new BinaryJedis("localhost");
  bj.connect();
  bj.close();
}
 
Example #5
Source File: ScriptingCommandsTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void evalMultiBulkWithBinaryJedis() {
  String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2],ARGV[3]}";
  List<byte[]> keys = new ArrayList<byte[]>();
  keys.add("key1".getBytes());
  keys.add("key2".getBytes());

  List<byte[]> args = new ArrayList<byte[]>();
  args.add("first".getBytes());
  args.add("second".getBytes());
  args.add("third".getBytes());

  BinaryJedis binaryJedis = new BinaryJedis(hnp.getHost(), hnp.getPort(), 500);
  binaryJedis.connect();
  binaryJedis.auth("foobared");

  List<byte[]> responses = (List<byte[]>) binaryJedis.eval(script.getBytes(), keys, args);
  assertEquals(5, responses.size());
  assertEquals("key1", new String(responses.get(0)));
  assertEquals("key2", new String(responses.get(1)));
  assertEquals("first", new String(responses.get(2)));
  assertEquals("second", new String(responses.get(3)));
  assertEquals("third", new String(responses.get(4)));

  binaryJedis.close();
}
 
Example #6
Source File: RedisDistributeLockTest.java    From azeroth with Apache License 2.0 5 votes vote down vote up
public static void initRedisProvider() {
    JedisPoolConfig poolConfig = new JedisPoolConfig();
    poolConfig.setMaxIdle(1);
    poolConfig.setMinEvictableIdleTimeMillis(60 * 1000);
    poolConfig.setMaxTotal(5);
    poolConfig.setMaxWaitMillis(30 * 1000);
    String[] servers = "127.0.0.1:6379".split(",");
    int timeout = 3000;
    String password = null;
    int database = 0;
    JedisProvider<Jedis, BinaryJedis> provider = new JedisStandaloneProvider("default", poolConfig, servers, timeout, password,
            database, null);
    JedisProviderFactory.setDefaultJedisProvider(provider);
}
 
Example #7
Source File: RedisCacheVendor.java    From jweb-cms with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void batchPut(Map<String, T> values) {
    try (BinaryJedis jedis = jedisPool.getResource()) {
        byte[][] params = new byte[values.size() * 2][];
        int i = 0;
        for (Map.Entry<String, T> entry : values.entrySet()) {
            params[i * 2] = redisKey(entry.getKey());
            params[i * 2 + 1] = entry.getValue() == null ? null : JSON.toJSONBytes(redisValue(entry.getValue()));
            i++;
        }
        jedis.mset(params);
    }
}
 
Example #8
Source File: RedisCacheVendor.java    From jweb-cms with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Optional<T> get(String key) {
    try (BinaryJedis jedis = jedisPool.getResource()) {
        byte[] json = jedis.get(redisKey(key));
        if (json == null) {
            return Optional.empty();
        } else {
            RedisCacheItem<T> item = JSON.fromJSON(json, cacheClass);
            if (isValid(item)) {
                return Optional.ofNullable(item.value);
            }
            return Optional.empty();
        }
    }
}
 
Example #9
Source File: JedisInstrumentation.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@Advice.OnMethodEnter(suppress = Throwable.class)
private static void beforeSendCommand(@Advice.This(typing = Assigner.Typing.DYNAMIC) BinaryJedis thiz,
                                      @Advice.Local("span") Span span,
                                      @Advice.Origin("#m") String method) {
    span = RedisSpanUtils.createRedisSpan(method);
    if (span != null) {
        span.getContext().getDestination()
            .withAddress(thiz.getClient().getHost())
            .withPort(thiz.getClient().getPort());
    }
}
 
Example #10
Source File: RedisCacheVendor.java    From jweb-cms with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void delete(String key) {
    try (BinaryJedis jedis = jedisPool.getResource()) {
        jedis.del(redisKey(key));
    }
}
 
Example #11
Source File: Jedis2InstrumentationTest.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
@BeforeEach
void setUp() {
    shardedJedis = new ShardedJedis(List.of(new JedisShardInfo("localhost", redisPort)));
    binaryJedis = new BinaryJedis("localhost", redisPort);
}
 
Example #12
Source File: JedisSentinelProvider.java    From azeroth with Apache License 2.0 4 votes vote down vote up
@Override
public BinaryJedis getBinary() {
    return get();
}
 
Example #13
Source File: JedisStandaloneProvider.java    From azeroth with Apache License 2.0 4 votes vote down vote up
@Override
public BinaryJedis getBinary() {
    return get();
}
 
Example #14
Source File: RedisCacheVendor.java    From jweb-cms with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void put(String key, T value) {
    try (BinaryJedis jedis = jedisPool.getResource()) {
        jedis.set(redisKey(key), JSON.toJSONBytes(redisValue(value)));
    }
}
 
Example #15
Source File: JedisSentinelProvider.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
@Override
public BinaryJedis getBinary() {	
	return get();
}
 
Example #16
Source File: JedisStandaloneProvider.java    From jeesuite-libs with Apache License 2.0 4 votes vote down vote up
@Override
public BinaryJedis getBinary() {	
	return get();
}
 
Example #17
Source File: ConnectionHandlingCommandsTest.java    From cachecloud with Apache License 2.0 4 votes vote down vote up
@Test
public void binary_quit() {
  BinaryJedis bj = new BinaryJedis(hnp.getHost());
  assertEquals("OK", bj.quit());
}