Java 类redis.clients.jedis.JedisCommands 实例源码

项目:azeroth    文件:DefaultCacheProvider.java   
@Override
public void clearGroup(final String groupName, final boolean containPkCache) {

    String cacheGroupKey = groupName + CacheHandler.GROUPKEY_SUFFIX;
    JedisCommands commands = JedisProviderFactory.getJedisCommands(null);
    try {
        Set<String> keys = commands.zrange(cacheGroupKey, 0, -1);
        //删除实际的缓存
        if (keys != null && keys.size() > 0) {
            RedisBatchCommand.removeObjects(keys.toArray(new String[0]));
        }
        commands.del(cacheGroupKey);
        //删除按ID缓存的
        if (containPkCache) {
            keys = JedisProviderFactory.getMultiKeyCommands(null).keys(groupName + ".id:*");
            if (keys != null && keys.size() > 0) {
                RedisBatchCommand.removeObjects(keys.toArray(new String[0]));
            }
        }

    } finally {
        JedisProviderFactory.getJedisProvider(null).release();
    }

}
项目:conductor    文件:DynoProxy.java   
public Set<String> hkeys(String key) {
    logger.trace("hkeys {}", key);
    JedisCommands client = dynoClient;
    Set<String> keys = new HashSet<>();
    int cursor = 0;
    do {
        ScanResult<Entry<String, String>> sr = client.hscan(key, "" + cursor);
        cursor = Integer.parseInt(sr.getStringCursor());
        List<Entry<String, String>> result = sr.getResult();
        for (Entry<String, String> e : result) {
            keys.add(e.getKey());
        }
    } while (cursor > 0);

    return keys;
}
项目:conductor    文件:DynoProxy.java   
public Set<String> smembers(String key) {
    logger.trace("smembers {}", key);
    JedisCommands client = dynoClient;
    Set<String> r = new HashSet<>();
    int cursor = 0;
    ScanParams sp = new ScanParams();
    sp.count(50);

    do {
        ScanResult<String> sr = client.sscan(key, "" + cursor, sp);
        cursor = Integer.parseInt(sr.getStringCursor());
        r.addAll(sr.getResult());

    } while (cursor > 0);

    return r;

}
项目:conductor    文件:DynoQueueDAOTest.java   
@Before
public void init() throws Exception {
    JedisCommands jedisMock = new JedisMock();
    dao = new DynoQueueDAO(jedisMock, jedisMock, new ShardSupplier() {

        @Override
        public Set<String> getQueueShards() {
            return Arrays.asList("a").stream().collect(Collectors.toSet());
        }

        @Override
        public String getCurrentShard() {
            return "a";
        }
    }, new TestConfiguration());
}
项目:jeesuite-libs    文件:DefaultCacheProvider.java   
@Override
public void clearGroup(final String groupName,final boolean containPkCache) {

    String cacheGroupKey = groupName + CacheHandler.GROUPKEY_SUFFIX;
    JedisCommands commands = JedisProviderFactory.getJedisCommands(null);
    try {   
        Set<String> keys = commands.zrange(cacheGroupKey, 0, -1);
        //删除实际的缓存
        if(keys != null && keys.size() > 0){
            RedisBatchCommand.removeObjects(keys.toArray(new String[0]));
        }
        commands.del(cacheGroupKey);
        //删除按ID缓存的
        if(containPkCache){             
            keys = JedisProviderFactory.getMultiKeyCommands(null).keys(groupName +".id:*");
            if(keys != null && keys.size() > 0){
                RedisBatchCommand.removeObjects(keys.toArray(new String[0]));
            }
        }

    } finally{
        JedisProviderFactory.getJedisProvider(null).release();
    }

}
项目:wint    文件:RedisSessionStore.java   
@Override
public WintCookie commitForCookie(final int expire) {
    redisClient.getRedisTemplate().executeNoResult(new RedisCommandNoResult() {
        @Override
        public void doInExec(JedisCommands commands) {
            String key = getRedisKey();
            if (commands.exists(key)) {
                commands.expire(key, expire);
            }
        }
    });

    WintCookie cookie = new WintCookie(config.getSessionIdName(), sessionId);
    String domain = config.getDomain();
    if (!StringUtil.isEmpty(domain)) {
        cookie.setDomain(domain);
    }
    cookie.setHttpOnly(true);
    // 设置为非持久化cookie
    //  cookie.setMaxAge(config.getExpire());
    cookie.setPath(config.getPath());
    return cookie;
}
项目:trioAop    文件:CallRedisStringOperactionImpl.java   
@Override
public boolean exists(final String key) {
    JedisPool jedisPool = PoolThreadLocal.getPool();
    return new AbstractCommandCall() {
        @Override
        public <T> T exec(JedisCommands commands) {
            return (T) commands.exists(key);
        }
    }.call(jedisPool);
}
项目:trioAop    文件:CallRedisStringOperactionImpl.java   
@Override
public boolean expireat(final String key, final String val, final int cacheTime) {
    JedisPool jedisPool = PoolThreadLocal.getPool();
    return new AbstractCommandCall() {
        @Override
        public <T> T exec(JedisCommands commands) {
            commands.set(key, val);
            if (cacheTime > 0) {
                commands.expire(key, cacheTime);
            }
            return (T) Boolean.TRUE;
        }
    }.call(jedisPool);
}
项目:trioAop    文件:CallRedisStringOperactionImpl.java   
@Override
public String get(final String key) {
    JedisPool jedisPool = PoolThreadLocal.getPool();
    return new AbstractCommandCall() {
        @Override
        public <T> T exec(JedisCommands commands) {
            return (T) commands.get(key);
        }
    }.call(jedisPool);
}
项目:trioAop    文件:CallRedisStringOperactionImpl.java   
@Override
public boolean del(final String key) {
    JedisPool jedisPool = PoolThreadLocal.getPool();
    return new AbstractCommandCall() {
        @Override
        public <T> T exec(JedisCommands commands) {
            commands.del(key);
            return (T) Boolean.TRUE;
        }
    }.call(jedisPool);
}
项目:JInsight    文件:JedisRuleSet.java   
private void interceptJedisCommands() {
  Class<JedisCommands> clazz = JedisCommands.class;
  Method[] methods = clazz.getDeclaredMethods();
  Set<String> methodNames = new HashSet<>();
  for (Method method : methods) {
    if (methodNames.contains(method.getName())) {
      continue;//over-loaded method
    }
    methodNames.add(method.getName());
    addRulesForOperation(method);
  }
}
项目:azeroth    文件:DefaultCacheProvider.java   
@Override
public void putGroup(String cacheGroupKey, String key, long expireSeconds) {
    long score = calcScoreInRegionKeysSet(expireSeconds);
    JedisCommands commands = JedisProviderFactory.getJedisCommands(null);
    try {
        commands.zadd(cacheGroupKey, score, key);
        commands.pexpire(cacheGroupKey, expireSeconds * 1000);
    } finally {
        JedisProviderFactory.getJedisProvider(null).release();
    }
}
项目:azeroth    文件:DefaultCacheProvider.java   
@Override
public void removeFromGroup(String cacheGroupKey, String key) {
    JedisCommands commands = JedisProviderFactory.getJedisCommands(null);
    try {
        commands.zrem(cacheGroupKey, key);
        //
        commands.del(key);
    } finally {
        JedisProviderFactory.getJedisProvider(null).release();
    }
}
项目:azeroth    文件:DefaultCacheProvider.java   
@Override
public void clearExpiredGroupKeys(String cacheGroup) {
    long maxScore = System.currentTimeMillis() / 1000 - this.baseScoreInRegionKeysSet;
    JedisCommands commands = JedisProviderFactory.getJedisCommands(null);
    try {
        commands.zremrangeByScore(cacheGroup, 0, maxScore);
    } finally {
        JedisProviderFactory.getJedisProvider(null).release();
    }
    logger.debug("clearExpiredGroupKeys runing:cacheName:{} , score range:0~{}", cacheGroup, maxScore);
}
项目:conductor    文件:DynoProxy.java   
public Map<String, String> hgetAll(String key) {
    Map<String, String> m = new HashMap<>();
    JedisCommands dyno = dynoClient;
    int cursor = 0;
    do {
        ScanResult<Entry<String, String>> sr = dyno.hscan(key, "" + cursor);
        cursor = Integer.parseInt(sr.getStringCursor());
        for (Entry<String, String> r : sr.getResult()) {
            m.put(r.getKey(), r.getValue());
        }
    } while (cursor > 0);

    return m;
}
项目:conductor    文件:DynoQueueDAO.java   
public DynoQueueDAO(JedisCommands dynoClient, JedisCommands dynoClientRead, ShardSupplier ss, Configuration config) {
    this.dynoClient = dynoClient;
    this.dynoClientRead = dynoClient;
    this.ss = ss;
    this.config = config;
    init();
}
项目:conductor    文件:RedisMetadataDAOTest.java   
@Before
public void init() {
    Configuration config = new TestConfiguration();
    JedisCommands jedisMock = new JedisMock();
    DynoProxy dynoClient = new DynoProxy(jedisMock);

    dao = new RedisMetadataDAO(dynoClient, om, config);
}
项目:conductor    文件:TestModule.java   
@Override
protected void configure() {
    System.setProperty("workflow.system.task.worker.callback.seconds", "0");
    System.setProperty("workflow.system.task.worker.queue.size", "10000");
    System.setProperty("workflow.system.task.worker.thread.count", "10");
    configureExecutorService();
    ConductorConfig config = new ConductorConfig();
    bind(Configuration.class).toInstance(config);
    JedisCommands jedisMock = new JedisMock();


    DynoQueueDAO queueDao = new DynoQueueDAO(jedisMock, jedisMock, new ShardSupplier() {

        @Override
        public Set<String> getQueueShards() {
            return Arrays.asList("a").stream().collect(Collectors.toSet());
        }

        @Override
        public String getCurrentShard() {
            return "a";
        }
    }, config);

    bind(MetadataDAO.class).to(RedisMetadataDAO.class);
    bind(ExecutionDAO.class).to(RedisExecutionDAO.class);
    bind(DynoQueueDAO.class).toInstance(queueDao);
    bind(QueueDAO.class).to(DynoQueueDAO.class);
    bind(IndexDAO.class).to(MockIndexDAO.class);        
    DynoProxy proxy = new DynoProxy(jedisMock);
    bind(DynoProxy.class).toInstance(proxy);
    install(new CoreModule());
    bind(UserTask.class).asEagerSingleton();

}
项目:conductor    文件:ServerModule.java   
public ServerModule(JedisCommands jedis, HostSupplier hs, ConductorConfig config, ConductorServer.DB db) {
    this.dynoConn = jedis;
    this.hs = hs;
    this.config = config;
    this.region = config.getRegion();
    this.localRack = config.getAvailabilityZone();
    this.db = db;

}
项目:westcache    文件:RedisInterceptor.java   
private WestCacheItem executeAndPut(Callable<WestCacheItem> callable,
                                    String redisKey, JedisCommands redis) {
    val item = Envs.execute(callable);
    Redis.expirePut(redis, redisKey, item);

    return item;
}
项目:westcache    文件:RedisCacheManager.java   
private void setVersionToRedis(String cacheKey, String version, JedisCommands redis, String redisKey) {
    val versionKey = prefix + "version:" + cacheKey;
    val versionRedis = redis.get(versionKey);
    if (version.equals(versionRedis)) return;

    redis.del(redisKey);
    redis.set(versionKey, version);
}
项目:westcache    文件:Redis.java   
public static JedisCommands createJedisCommands(
        String host, int port, int maxTotal) {
    val poolConfig = new JedisPoolConfig();
    poolConfig.setMaxTotal(maxTotal);

    val pool = new JedisPool(poolConfig, host, port);
    return proxyJedisCommands(pool);
}
项目:westcache    文件:Redis.java   
public static boolean waitRedisLock(JedisCommands redis, String lockKey) {
    int maxWaitTimes = 10;
    while (maxWaitTimes-- > 0) {
        Long lock = redis.setnx(lockKey, "lock");
        if (lock == 1L) return true;

        Envs.sleepMillis(50L);
    }
    return false;
}
项目:westcache    文件:Redis.java   
public static WestCacheItem getWestCacheItem(WestCacheOption option,
                                             JedisCommands redis,
                                             String redisKey) {
    val jsonValue = redis.get(redisKey);
    if (jsonValue == null) return null;

    val value = FastJsons.parse(jsonValue, option.getMethod(), true);
    if (value == null && !"null".equals(jsonValue)) return null;

    val optional = Optional.fromNullable(value);
    return new WestCacheItem(optional, option);
}
项目:westcache    文件:Redis.java   
public static String expirePut(JedisCommands redis,
                               String redisKey,
                               WestCacheItem item) {
    val duration = item.getDurationSeconds();

    val json = FastJsons.json(item.orNull());
    val result = redis.set(redisKey, json);
    if (duration > 0) {
        log.info("redis set {}={} in ttl {} seconds", redisKey, json, duration);
        redis.expire(redisKey, (int) duration);
    }

    return result;
}
项目:jeesuite-libs    文件:DefaultCacheProvider.java   
@Override
public void putGroup(String cacheGroupKey, String key,long expireSeconds) {
    long score = calcScoreInRegionKeysSet(expireSeconds);
    JedisCommands commands = JedisProviderFactory.getJedisCommands(null);
    try {           
        commands.zadd(cacheGroupKey, score, key);
        commands.pexpire(cacheGroupKey, expireSeconds * 1000);
    } finally{
        JedisProviderFactory.getJedisProvider(null).release();
    }
}
项目:jeesuite-libs    文件:DefaultCacheProvider.java   
@Override
public void removeFromGroup(String cacheGroupKey, String key) {
    JedisCommands commands = JedisProviderFactory.getJedisCommands(null);
    try {           
        commands.zrem(cacheGroupKey, key);
        //
        commands.del(key);
    } finally{
        JedisProviderFactory.getJedisProvider(null).release();
    }
}
项目:jeesuite-libs    文件:DefaultCacheProvider.java   
@Override
public void clearExpiredGroupKeys(String cacheGroup) {
    long maxScore = System.currentTimeMillis() / 1000 - this.baseScoreInRegionKeysSet;
    JedisCommands commands = JedisProviderFactory.getJedisCommands(null);
    try {
        commands.zremrangeByScore(cacheGroup, 0, maxScore);
    } finally {
        JedisProviderFactory.getJedisProvider(null).release();
    }
    logger.debug("clearExpiredGroupKeys runing:cacheName:{} , score range:0~{}", cacheGroup, maxScore);
}
项目:solr-redis    文件:HVals.java   
@Override
public Map<String, Float> execute(final JedisCommands client, final SolrParams params) {
  final String key = ParamUtil.assertGetStringByName(params, "key");

  log.debug("Fetching HVALS from Redis for key: {}", key);

  return ResultUtil.stringIteratorToMap(client.hvals(key));
}
项目:solr-redis    文件:ZRevRange.java   
@Override
public Map<String, Float> execute(final JedisCommands client, final SolrParams params) {
  final String key = ParamUtil.assertGetStringByName(params, "key");
  final long start = ParamUtil.tryGetIntByName(params, "range_start", 0);
  final long end = ParamUtil.tryGetIntByName(params, "range_end", -1);
  final boolean withScores = ParamUtil.tryGetBooleanByName(params, "with_scores", true);

  log.debug("Fetching ZREVRANGE from Redis for key: {} ({}, {})", key, start, end);

  if (withScores) {
    return ResultUtil.tupleIteratorToMap(client.zrevrangeWithScores(key, start, end));
  } else {
    return ResultUtil.stringIteratorToMap(client.zrevrange(key, start, end));
  }
}
项目:solr-redis    文件:HKeys.java   
@Override
public Map<String, Float> execute(final JedisCommands client, final SolrParams params) {
  final String key = ParamUtil.assertGetStringByName(params, "key");

  log.debug("Fetching HKEYS from Redis for key: {}", key);

  return ResultUtil.stringIteratorToMap(client.hkeys(key));
}
项目:solr-redis    文件:ZRevrangeByScore.java   
@Override
public Map<String, Float> execute(final JedisCommands client, final SolrParams params) {
  final String key = ParamUtil.assertGetStringByName(params, "key");
  final String min = ParamUtil.tryGetStringByName(params, "min", "-inf");
  final String max = ParamUtil.tryGetStringByName(params, "max", "+inf");
  final boolean withScores = ParamUtil.tryGetBooleanByName(params, "with_scores", true);

  log.debug("Fetching ZREVRANGEBYSCORE from Redis for key: {} ({}, {})", key, min, max);

  if (withScores) {
    return ResultUtil.tupleIteratorToMap(client.zrevrangeByScoreWithScores(key, max, min));
  } else {
    return ResultUtil.stringIteratorToMap(client.zrevrangeByScore(key, max, min));
  }
}
项目:solr-redis    文件:ZRangeByScore.java   
@Override
public Map<String, Float> execute(final JedisCommands client, final SolrParams params) {
  final String key = ParamUtil.assertGetStringByName(params, "key");
  final String min = ParamUtil.tryGetStringByName(params, "min", "-inf");
  final String max = ParamUtil.tryGetStringByName(params, "max", "+inf");
  final boolean withScores = ParamUtil.tryGetBooleanByName(params, "with_scores", true);

  log.debug("Fetching ZRANGEBYSCORE from Redis for key: {} ({}, {})", key, min, max);

  if (withScores) {
    return ResultUtil.tupleIteratorToMap(client.zrangeByScoreWithScores(key, min, max));
  } else {
    return ResultUtil.stringIteratorToMap(client.zrangeByScore(key, min, max));
  }
}
项目:solr-redis    文件:HMGet.java   
@Override
public Map<String, Float> execute(final JedisCommands client, final SolrParams params) {
  final String key = ParamUtil.assertGetStringByName(params, "key");
  final String[] fields = ParamUtil.getStringByPrefix(params, "field");

  log.debug("Fetching HMGET from Redis for key: {} ({})", key, fields);

  return ResultUtil.stringIteratorToMap(client.hmget(key, fields));
}
项目:solr-redis    文件:ZRange.java   
@Override
public Map<String, Float> execute(final JedisCommands client, final SolrParams params) {
  final String key = ParamUtil.assertGetStringByName(params, "key");
  final long start = ParamUtil.tryGetIntByName(params, "range_start", 0);
  final long end = ParamUtil.tryGetIntByName(params, "range_end", -1);
  final boolean withScores = ParamUtil.tryGetBooleanByName(params, "with_scores", true);

  log.debug("Fetching ZRANGE from Redis for key: {} ({}, {})", key, start, end);

  if (withScores) {
    return ResultUtil.tupleIteratorToMap(client.zrangeWithScores(key, start, end));
  } else {
    return ResultUtil.stringIteratorToMap(client.zrange(key, start, end));
  }
}
项目:solr-redis    文件:LIndex.java   
@Override
public Map<String, Float> execute(final JedisCommands client, final SolrParams params) {
  final String key = ParamUtil.assertGetStringByName(params, "key");
  final int index = ParamUtil.tryGetIntByName(params, "index", 0);

  log.debug("Fetching LINDEX from Redis for key: {} ({})", key, index);

  return ResultUtil.stringIteratorToMap(Collections.singletonList(client.lindex(key, index)));
}
项目:solr-redis    文件:SMembers.java   
@Override
public Map<String, Float> execute(final JedisCommands client, final SolrParams params) {
  final String key = ParamUtil.assertGetStringByName(params, "key");

  log.debug("Fetching SMEMBERS from Redis for key: {}", key);

  return ResultUtil.stringIteratorToMap(client.smembers(key));
}
项目:solr-redis    文件:SRandMember.java   
@Override
public Map<String, Float> execute(final JedisCommands client, final SolrParams params) {
  final String key = ParamUtil.assertGetStringByName(params, "key");
  final int count = ParamUtil.tryGetIntByName(params, "count", 1);

  log.debug("Fetching SRANDMEMBER from Redis for key: {} ({})", key, count);

  // Workaround for https://github.com/xetorthio/jedis/issues/665
  return client instanceof Jedis ? ResultUtil.stringIteratorToMap(((Jedis) client).srandmember(key, count)) : null;
}
项目:solr-redis    文件:HGet.java   
@Override
public Map<String, Float> execute(final JedisCommands client, final SolrParams params) {
  final String key = ParamUtil.assertGetStringByName(params, "key");
  final String field = ParamUtil.assertGetStringByName(params, "field");

  log.debug("Fetching HGET from Redis for key: {} ({})", key, field);

  return ResultUtil.stringIteratorToMap(Collections.singletonList(client.hget(key, field)));
}
项目:easyooo-framework    文件:AbstractRedisOperation.java   
@Override
public String get(final String key) {
    return exec(new RedisCallback<String>() {
        @Override
        public String doCallback(JedisCommands jedis) {
            return jedis.get(key);
        }
    });
}