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


Java Jedis.set方法代码示例

本文整理汇总了Java中redis.clients.jedis.Jedis.set方法的典型用法代码示例。如果您正苦于以下问题:Java Jedis.set方法的具体用法?Java Jedis.set怎么用?Java Jedis.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在redis.clients.jedis.Jedis的用法示例。


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

示例1: checkJedisIsReusedWhenReturned

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Test
public void checkJedisIsReusedWhenReturned() {

  JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort());
  Jedis jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.set("foo", "0");
  pool.returnResource(jedis);

  jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.incr("foo");
  pool.returnResource(jedis);
  pool.destroy();
  assertTrue(pool.isClosed());
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:17,代码来源:JedisPoolTest.java

示例2: select

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Test
public void select() {
  jedis.select(1);
  jedis.set("foo", "bar");
  jedis.watch("foo");
  Transaction t = jedis.multi();
  t.select(0);
  t.set("bar", "foo");

  Jedis jedis2 = createJedis();
  jedis2.select(1);
  jedis2.set("foo", "bar2");

  List<Object> results = t.exec();
  if(results.isEmpty()){
    results = null;
  }
  assertNull(results);
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:20,代码来源:TransactionCommandsTest.java

示例3: set

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public boolean set(byte[] key, byte[] value, int validSeconds){
	
	Jedis jedis = null;
	try{
		jedis = get();
		if (jedis == null)
			return false;
		jedis.set(key,value);
		jedis.expire(key, validSeconds);
		pool.returnResource(jedis);
	}catch(Exception e){
		pool.returnBrokenResource(jedis);
		return false;
	}
	return true;
}
 
开发者ID:x7-framework,项目名称:x7,代码行数:17,代码来源:JedisConnector_Cache.java

示例4: main

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public static void main(String[] args) throws UnknownHostException, IOException {
  Jedis jedis = new Jedis(hnp.getHost(), hnp.getPort());
  jedis.connect();
  jedis.auth("foobared");
  jedis.flushAll();

  long begin = Calendar.getInstance().getTimeInMillis();

  for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
    String key = "foo" + n;
    jedis.set(key, "bar" + n);
    jedis.get(key);
  }

  long elapsed = Calendar.getInstance().getTimeInMillis() - begin;

  jedis.disconnect();

  System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops");
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:21,代码来源:GetSetBenchmark.java

示例5: set

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
 * 简单的set
 * @param key
 * @param value
 */
public void set(String key ,Object value) throws Exception {
	Jedis jds = null;
	try {
		jds = getJedis();
		jds.select(0);
		byte[] svalue = SerializeUtil.serialize(value);
		jds.set(key.getBytes(), svalue);
       } catch (Exception e) {
           throw e;
       } finally {
       	if(jds != null)
		{
			jds.close();
		}
       }
}
 
开发者ID:wjggwm,项目名称:webside,代码行数:22,代码来源:RedisManager.java

示例6: main

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
    Bench<JedisPool> bench = new JedisBench() {
        @Override
        public void executeOperation(String data, JedisPool benchInstance, int threadNumber, int iteration,
                MetricRegistry metrics) {
            Jedis jedis = benchInstance.getResource();
            
            Timer.Context time = metrics.timer("bucket").time();
            String key = "bucket_" + threadNumber + "_" + iteration;
            jedis.set(key, (String) value);
            time.stop();
            
            jedis.close();
        }
    };
    
    Benchmark benchmark = new Benchmark(bench);
    benchmark.run(args);
}
 
开发者ID:redisson,项目名称:redisson-benchmark,代码行数:20,代码来源:BinaryBenchmark.java

示例7: set

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
 * String set command
 *
 * @param key
 * @param value
 * @param nxxx
 * @param expx
 * @param time
 * @return
 */
public String set(String key, String value, String nxxx, String expx, long time) {
    Jedis jedis = null;
    try {
        jedis = jedisPool.getResource();
        return jedis.set(key, value, nxxx, expx, time);

    } finally {
        if (jedis != null) {
            jedis.close();
        }
    }
}
 
开发者ID:baidu,项目名称:dlock,代码行数:23,代码来源:JedisClient.java

示例8: available

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public boolean available(){
    Jedis jedis = getJedis();
    if(jedis!=null){
        jedis.select(0);
        String key = "[email protected]";
        jedis.set(key,"available");
        if("available".equals(jedis.get(key))){
            jedis.del(key);
            return true;
        }
    }else{
        return false;
    }
    return false;
}
 
开发者ID:Kuangcp,项目名称:MythRedisClient,代码行数:16,代码来源:RedisPools.java

示例9: doTest

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
private static void doTest() throws Exception {
    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMinIdle(0);
    poolConfig.setMaxIdle(5);
    poolConfig.setMaxTotal(5);
    final JedisPool pool = new JedisPool(poolConfig, "127.0.0.1", 6379, 2000, "weimob123", 8);

    List<Thread> tds = new ArrayList<Thread>();
    final Integer temp = 0;
    final AtomicInteger ind = new AtomicInteger();
    for (int i = 0; i < 50; i++) {
        Thread hj = new Thread(new Runnable() {
            public void run() {
                for (int i; (i = ind.getAndIncrement()) < TOTAL_OPERATIONS; ) {
                    Jedis j = pool.getResource();
                    final String key = "foo" + i;
                    // redisUtil.setRedisData(key, key);
                    j.set(key.getBytes(), ConvertUtil.serialize(temp));
                    j.close();
                }
            }
        });
        tds.add(hj);
        hj.start();
    }

    for (Thread t : tds)
        t.join();
    pool.close();
    pool.destroy();
}
 
开发者ID:TwoDragonLake,项目名称:tdl-seckill,代码行数:32,代码来源:JedisTest.java

示例10: set

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
 * 设置 byte[] 过期时间
 * @param key
 * @param value
 * @param seconds 以秒为单位
 */
public synchronized static void set(byte[] key, byte[] value, int seconds) {
	try {
		Jedis jedis = getJedis();
		jedis.set(key, value);
		jedis.expire(key, seconds);
		jedis.close();
	} catch (Exception e) {
		LOGGER.error("Set key error : " + e);
	}
}
 
开发者ID:ChangyiHuang,项目名称:shuzheng,代码行数:17,代码来源:RedisUtil.java

示例11: set

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
 * 设置 byte[]
 * @param key
 * @param value
 */
public synchronized static void set(byte[] key, byte[] value) {
	try {
		Jedis jedis = getJedis();
		jedis.set(key, value);
		jedis.close();
	} catch (Exception e) {
		_log.error("Set key error : " + e);
	}
}
 
开发者ID:youngMen1,项目名称:-Spring-SpringMVC-Mybatis-,代码行数:15,代码来源:RedisUtil.java

示例12: lockQueue

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
private boolean lockQueue(String queueID) {
    if (locked.get() == null) {
        synchronized (this) {
            if (locked.get() == null) {
                locked.set(new AtomicInteger(0));
            }
        }
    }
    if (locked.get().incrementAndGet() > 1) {
        return true;
    }
    Jedis jedis = jedisPool.getResource();
    try {
        String redisLockKey = makeRedisLockKey(queueID);
        long lockRequestTime = System.currentTimeMillis();
        while (true) {
            String result = jedis.set(redisLockKey, "lockTheQueue", "NX", "EX", 120);
            if (StringUtils.isNotEmpty(result) && result.equalsIgnoreCase("OK")) {
                return true;
            }
            if (lockRequestTime + lockWaitTimeStamp > System.currentTimeMillis()) {
                locked.get().decrementAndGet();
                return false;
            }
            long sleepTime = jedis.ttl(redisLockKey) * 1000 - 10;
            if (sleepTime > lockRequestTime) {
                return false;
            }
            if (sleepTime > 0) {
                CommonUtil.sleep(sleepTime / 4);
            }
        }
    } finally {
        IOUtils.closeQuietly(jedis);
    }
}
 
开发者ID:virjar,项目名称:vscrawler,代码行数:37,代码来源:JedisQueueStore.java

示例13: startWithUrlString

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Test
public void startWithUrlString() {
  Jedis j = new Jedis("localhost", 6380);
  j.auth("foobared");
  j.select(2);
  j.set("foo", "bar");
  JedisPool pool = new JedisPool("redis://:[email protected]:6380/2");
  Jedis jedis = pool.getResource();
  assertEquals("PONG", jedis.ping());
  assertEquals("bar", jedis.get("foo"));
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:12,代码来源:JedisPoolTest.java

示例14: set

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public void set(byte[] key, byte[] value ) {

		Jedis jedis = null;
		try {
			jedis = get();
			if (jedis == null)
				return;
			jedis.set(key, value);
			pool.returnResource(jedis);
		} catch (Exception e) {
			pool.returnBrokenResource(jedis);
		}

	}
 
开发者ID:x7-framework,项目名称:x7,代码行数:15,代码来源:JedisConnector_Persistence.java

示例15: lockQueue

import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
private boolean lockQueue(String queueID) {
    if (locked.get() == null) {
        synchronized (this) {
            if (locked.get() == null) {
                locked.set(new AtomicInteger(0));
            }
        }
    }
    boolean ret = false;
    @Cleanup Jedis jedis = jedisPool.getResource();
    if (locked.get().incrementAndGet() > 1) {
        return true;
    }
    String redisLockKey = makeRedisLockKey(queueID);
    long lockRequestTime = System.currentTimeMillis();
    while (true) {
        String result = jedis.set(redisLockKey, "lockTheQueue", "NX", "EX", 120);
        if (StringUtils.isNotEmpty(result) && result.equalsIgnoreCase("OK")) {
            ret = true;
            break;
        }
        if (lockRequestTime + lockWaitTimeStamp < System.currentTimeMillis()) {
            locked.get().decrementAndGet();
            break;
        }
        long sleepTime = jedis.ttl(redisLockKey) * 1000 - 10;
        if (sleepTime > lockRequestTime) {
            return false;
        }
        if (sleepTime > 0) {
            CommonUtil.sleep(sleepTime);
        }
    }
    return ret;
}
 
开发者ID:virjar,项目名称:vscrawler,代码行数:36,代码来源:JedisSegmentQueueStore.java


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