当前位置: 首页>>代码示例>>Java>>正文


Java BinaryJedis类代码示例

本文整理汇总了Java中redis.clients.jedis.BinaryJedis的典型用法代码示例。如果您正苦于以下问题:Java BinaryJedis类的具体用法?Java BinaryJedis怎么用?Java BinaryJedis使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BinaryJedis类属于redis.clients.jedis包,在下文中一共展示了BinaryJedis类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCon

import redis.clients.jedis.BinaryJedis; //导入依赖的package包/类
/**
 * 获取jedis的连接
 * 
 * @return
 */
public BinaryJedis getCon() {
    try {
        if (null == jedis) {
            System.out.println("jedis 重新获取链接");
            this.jedis = jedisPool.getResource();
        }

    }
    catch (Exception e) {
        e.printStackTrace();
        try {
            Thread.sleep(10 * 1000);
        }
        catch (InterruptedException e1) {
            e1.printStackTrace();
        }
        if (null == jedis) {
            this.jedis = jedisPool.getResource();
        }
    }
    jedis.select(Default_DB);
    return jedis;
}
 
开发者ID:jiumao-org,项目名称:wechat-mall,代码行数:29,代码来源:BaseRedis.java

示例2: testBinaryBitfield

import redis.clients.jedis.BinaryJedis; //导入依赖的package包/类
@Test
/**
 * Binary Jedis tests should be in their own class
 */
public void testBinaryBitfield() {
  jedis.close();
  BinaryJedis binaryJedis = new BinaryJedis("localhost");
  binaryJedis.auth("foobared");
  binaryJedis.del("mykey".getBytes());
  try {
    List<Long> responses = binaryJedis.bitfield("mykey".getBytes(), "INCRBY".getBytes(),"i5".getBytes(),"100".getBytes(),"1".getBytes(), "GET".getBytes(), "u4".getBytes(), "0".getBytes());
    assertEquals((Long)1l, responses.get(0));
    assertEquals((Long)0l, responses.get(1));
  } finally {
    binaryJedis.del("mykey".getBytes());
    binaryJedis.close();
  }
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:19,代码来源:JedisTest.java

示例3: validateObject

import redis.clients.jedis.BinaryJedis; //导入依赖的package包/类
@Override
public boolean validateObject(PooledObject<Jedis> p) {

    BinaryJedis jedis = (BinaryJedis) p.getObject();
    try {
        HostAndPort hostAndPort = (HostAndPort) this.hostAndPort.get();

        String connectionHost = jedis.getClient().getHost();
        int connectionPort = jedis.getClient().getPort();

        return ((hostAndPort.getHost().equals(connectionHost))
                && (hostAndPort.getPort() == connectionPort)
                && (jedis.isConnected()) && (jedis.ping().equals("PONG")));
    } catch (Exception e) {
    }
    return false;
}
 
开发者ID:DarkPhoenixs,项目名称:connection-pool-client,代码行数:18,代码来源:RedisConnectionFactoryOld.java

示例4: init

import redis.clients.jedis.BinaryJedis; //导入依赖的package包/类
@PostConstruct
public void init() {
  logger.log(Level.INFO, "Initializing Cache.");

  jedis = new BinaryJedis("redis-cache");

  random = new Random();

  try {
    jedis.sadd(jedisKey.getBytes(),
               serialize(new TennisMatch("12341234",
                                         "ROLLAND GARROS - QUARTER FINALS",
                                         "Ferrer D.",
                                         "es",
                                         "Almagro N.",
                                         "es")));
          jedis.sadd(jedisKey.getBytes(),
                     serialize(new TennisMatch("12351235", "US OPEN - QUARTER FINALS", "Djokovic N.", "rs", "Berdych T.", "cz")));
          jedis.sadd(jedisKey.getBytes(),
                     serialize(new TennisMatch("12361236", "US OPEN - QUARTER FINALS", "Murray A.", "gb", "Chardy J.", "fr")));
          jedis.sadd(jedisKey.getBytes(),
                     serialize(new TennisMatch("12371237", "US OPEN - QUARTER FINALS", "Federer R.", "ch", "Tsonga J.W.", "fr")));
      }catch (Exception ex){
          logger.severe("Error with Redis" + ex.getCause());
      }
  }
 
开发者ID:mgreau,项目名称:docker4dev-tennistour-app,代码行数:27,代码来源:StarterServiceLive.java

示例5: RedisPool

import redis.clients.jedis.BinaryJedis; //导入依赖的package包/类
public RedisPool(final String host) {
    URI uri = URI.create(host);
    if (uri.getScheme() != null && uri.getScheme().equals("redis")) {
        String h = uri.getHost();
        int port = uri.getPort();
        String password = JedisURIHelper.getPassword(uri);
        int database = 0;
        Integer dbIndex = JedisURIHelper.getDBIndex(uri);
        if (dbIndex != null) {
            database = dbIndex.intValue();
        }
        this.internalPool = new GenericObjectPool<BinaryJedis>(
                new BinaryJedisFactory(h, port, Protocol.DEFAULT_TIMEOUT,
                        password, database, null),
                new GenericObjectPoolConfig());
    } else {
        this.internalPool = new GenericObjectPool<BinaryJedis>(new BinaryJedisFactory(
                host, Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT,
                null, Protocol.DEFAULT_DATABASE, null),
                new GenericObjectPoolConfig());
    }
}
 
开发者ID:yamingd,项目名称:argo,代码行数:23,代码来源:RedisPool.java

示例6: makeObject

import redis.clients.jedis.BinaryJedis; //导入依赖的package包/类
@Override
public PooledObject<BinaryJedis> makeObject() throws Exception {
    final HostAndPort hostAndPort = this.hostAndPort.get();
    final Jedis jedis = new Jedis(hostAndPort.getHost(), hostAndPort.getPort(), this.timeout);

    jedis.connect();
    if (null != this.password) {
        jedis.auth(this.password);
    }
    if (database != 0) {
        jedis.select(database);
    }
    if (clientName != null) {
        jedis.clientSetname(clientName);
    }

    return new DefaultPooledObject<BinaryJedis>(jedis);
}
 
开发者ID:yamingd,项目名称:argo,代码行数:19,代码来源:BinaryJedisFactory.java

示例7: mget

import redis.clients.jedis.BinaryJedis; //导入依赖的package包/类
/**
 * Get Object List
 * @param clazz
 * @param keys
 * @param <T>
 * @return
 */
public <T> List<T> mget(final Class<T> clazz, final String... keys){
    return this.execute(new RedisCommand<List<T>>(){
        public List<T> execute(final BinaryJedis conn) throws Exception {
            List<byte[]> bytes = conn.mget(SafeEncoder.encodeMany(keys));
            List<T> ret = Lists.newArrayList();
            for (byte[] item : bytes){
                if (item != null) {
                    ret.add(messagePack.read(item, clazz));
                }else{
                    ret.add(null);
                }
            }
            return ret;
        }
    });
}
 
开发者ID:yamingd,项目名称:argo,代码行数:24,代码来源:RedisBuket.java

示例8: hall

import redis.clients.jedis.BinaryJedis; //导入依赖的package包/类
/**
 * 返回HashMap的K-V值.
 * @param key
 * @return
 */
public Map<String, Integer> hall(final String key){
	return this.execute(new RedisCommand<Map<String, Integer>>(){
		public Map<String, Integer> execute(final BinaryJedis conn) throws Exception {
               Map<byte[], byte[]> bs = conn.hgetAll(SafeEncoder.encode(key));
               Map<String, Integer> vals = Maps.newHashMap();
               Iterator<byte[]> itor = bs.keySet().iterator();
               while (itor.hasNext()){
                   byte[] k = itor.next();
                   byte[] data = bs.get(k);
                   int v = data == null ? 0 : Integer.parseInt(SafeEncoder.encode(data));
                   vals.put(SafeEncoder.encode(k), v);
               }
			return vals;
		}
	});
}
 
开发者ID:yamingd,项目名称:argo,代码行数:22,代码来源:RedisBuket.java

示例9: lrange

import redis.clients.jedis.BinaryJedis; //导入依赖的package包/类
/**
   * 分页获取队列的元素.
   * @param key 缓存Key
   * @param page 页码
   * @param limit 每页记录数.
   * @return
   */
  public List<String> lrange(final String key, final int page, final int limit){
  	return this.execute(new RedisCommand<List<String>>(){
	public List<String> execute(final BinaryJedis conn) throws Exception {
		long start = (page - 1) * limit;
		long end = start + limit;
		List<byte[]> ls = conn.lrange(SafeEncoder.encode(key), start, end);
              List<String> ret = Lists.newArrayList();
              for (byte[] b : ls){
                  if (b != null) {
                      ret.add(SafeEncoder.encode(b));
                  }
              }
              return ret;
	}
});
  }
 
开发者ID:yamingd,项目名称:argo,代码行数:24,代码来源:RedisBuket.java

示例10: lpop

import redis.clients.jedis.BinaryJedis; //导入依赖的package包/类
public List<String> lpop(final String key, final int limit){
    return this.execute(new RedisCommand<List<String>>(){
        public List<String> execute(final BinaryJedis conn) throws Exception {
            byte[] bk = SafeEncoder.encode(key);
            List<String> resp = Lists.newArrayList();
            for (int i = 0; i < limit; i++) {
                byte[] bs = conn.lpop(bk);
                if (bs != null){
                    resp.add(SafeEncoder.encode(bs));
                }

            }
            return resp;
        }
    });
}
 
开发者ID:yamingd,项目名称:argo,代码行数:17,代码来源:RedisBuket.java

示例11: rpop

import redis.clients.jedis.BinaryJedis; //导入依赖的package包/类
public List<String> rpop(final String key, final int limit){
    return this.execute(new RedisCommand<List<String>>(){
        public List<String> execute(final BinaryJedis conn) throws Exception {
            byte[] bk = SafeEncoder.encode(key);
            List<String> resp = Lists.newArrayList();
            for (int i = 0; i < limit; i++) {
                byte[] bs = conn.rpop(bk);
                if (bs != null){
                    resp.add(SafeEncoder.encode(bs));
                }

            }
            return resp;
        }
    });
}
 
开发者ID:yamingd,项目名称:argo,代码行数:17,代码来源:RedisBuket.java

示例12: zrange

import redis.clients.jedis.BinaryJedis; //导入依赖的package包/类
public Set<String> zrange(final String key, final int page, final int limit){
  	return this.execute(new RedisCommand<Set<String>>(){
	public Set<String> execute(final BinaryJedis conn) throws Exception {
		long start = (page - 1) * limit;
		long end = start + limit;
		Set<byte[]> bs = conn.zrange(SafeEncoder.encode(key), start, end);
              Set<String> ret = Sets.newHashSet();
              for (byte[] b : bs){
                  if (b != null) {
                      ret.add(SafeEncoder.encode(b));
                  }
              }
              return ret;
	}
});
  }
 
开发者ID:yamingd,项目名称:argo,代码行数:17,代码来源:RedisBuket.java

示例13: zrevrange

import redis.clients.jedis.BinaryJedis; //导入依赖的package包/类
public Set<String> zrevrange(final String key, final int page, final int limit){
  	return this.execute(new RedisCommand<Set<String>>(){
	public Set<String> execute(final BinaryJedis conn) throws Exception {
		long start = (page - 1) * limit;
		long end = start + limit;
		Set<byte[]> bs = conn.zrevrange(SafeEncoder.encode(key), start, end);
              Set<String> ret = Sets.newHashSet();
              for (byte[] b : bs){
                  if (b != null) {
                      ret.add(SafeEncoder.encode(b));
                  }
              }
              return ret;
	}
});
  }
 
开发者ID:yamingd,项目名称:argo,代码行数:17,代码来源:RedisBuket.java

示例14: validateObject

import redis.clients.jedis.BinaryJedis; //导入依赖的package包/类
@Override
public boolean validateObject(PooledObject<Jedis> pooledJedis) {
    final BinaryJedis jedis = pooledJedis.getObject();
    try {
        HostAndPort hostAndPort = this.hostAndPort.get();
        String connectionHost = jedis.getClient().getHost();
        int connectionPort = jedis.getClient().getPort();

        return hostAndPort.getHost().equals(connectionHost)
                && hostAndPort.getPort() == connectionPort && jedis.isConnected()
                && jedis.ping().equals("PONG");
    } catch (final Exception e) {
        return false;
    }
}
 
开发者ID:YanXs,项目名称:nighthawk,代码行数:16,代码来源:JaRedisFactory.java

示例15: activateObject

import redis.clients.jedis.BinaryJedis; //导入依赖的package包/类
@Override
public void activateObject(PooledObject<Jedis> pooledJedis) throws Exception {
    final BinaryJedis jedis = pooledJedis.getObject();
    if (jedis.getDB() != database) {
        jedis.select(database);
    }
}
 
开发者ID:YanXs,项目名称:nighthawk,代码行数:8,代码来源:JaRedisFactory.java


注:本文中的redis.clients.jedis.BinaryJedis类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。