本文整理汇总了Java中redis.clients.jedis.Jedis.auth方法的典型用法代码示例。如果您正苦于以下问题:Java Jedis.auth方法的具体用法?Java Jedis.auth怎么用?Java Jedis.auth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redis.clients.jedis.Jedis
的用法示例。
在下文中一共展示了Jedis.auth方法的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());
}
示例2: testResetStateWithFullyExecutedTransaction
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Test
public void testResetStateWithFullyExecutedTransaction() {
Jedis jedis2 = new Jedis(jedis.getClient().getHost(), jedis.getClient().getPort());
jedis2.auth("foobared");
Transaction t = jedis2.multi();
t.set("mykey", "foo");
t.get("mykey");
List<Object> resp = t.exec();
assertNotNull(resp);
assertEquals(2, resp.size());
jedis2.resetState();
jedis2.close();
}
示例3: 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();
Pipeline p = jedis.pipelined();
for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
String key = "foo" + n;
p.set(key, "bar" + n);
p.get(key);
}
p.sync();
long elapsed = Calendar.getInstance().getTimeInMillis() - begin;
jedis.disconnect();
System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops");
}
示例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");
}
示例5: timeoutConnection
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Test(expected = JedisConnectionException.class)
public void timeoutConnection() throws Exception {
jedis = new Jedis("localhost", 6379, 15000);
jedis.auth("foobared");
jedis.configSet("timeout", "1");
Thread.sleep(2000);
jedis.hmget("foobar", "foo");
}
示例6: getNumActiveReturnsTheCorrectNumber
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Test
public void getNumActiveReturnsTheCorrectNumber() {
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000);
Jedis jedis = pool.getResource();
jedis.auth("foobared");
jedis.set("foo", "bar");
assertEquals("bar", jedis.get("foo"));
assertEquals(1, pool.getNumActive());
Jedis jedis2 = pool.getResource();
jedis.auth("foobared");
jedis.set("foo", "bar");
assertEquals(2, pool.getNumActive());
pool.returnResource(jedis);
assertEquals(1, pool.getNumActive());
pool.returnResource(jedis2);
assertEquals(0, pool.getNumActive());
pool.destroy();
}
示例7: getResource
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
private Jedis getResource() {
Jedis resource = jedisPool.getResource();
if (StringUtils.isBlank(password)) {
return resource;
} else {
resource.auth(password);
return resource;
}
}
示例8: makeObject
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Override
public PooledObject<Jedis> makeObject() throws Exception {
final HostAndPort hostAndPort = this.hostAndPort.get();
JaRedis.Builder builder = new JaRedis.Builder();
builder
.host(hostAndPort.getHost())
.port(hostAndPort.getPort())
.connectionTimeout(connectionTimeout)
.soTimeout(soTimeout);
Jedis jedis = builder.build();
try {
jedis.connect();
if (null != this.password) {
jedis.auth(this.password);
}
if (database != 0) {
jedis.select(database);
}
if (clientName != null) {
jedis.clientSetname(clientName);
}
} catch (JedisException je) {
jedis.close();
throw je;
}
return new DefaultPooledObject<>(jedis);
}
示例9: 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");
Jedis jedis = new Jedis("redis://:[email protected]:6380/2");
assertEquals("PONG", jedis.ping());
assertEquals("bar", jedis.get("foo"));
}
示例10: setUp
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
super.setUp();
nj = new Jedis(hnp.getHost(), hnp.getPort(), 500);
nj.connect();
nj.auth("foobared");
nj.flushAll();
}
示例11: testBitfield
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Test
public void testBitfield() {
Jedis jedis = new Jedis("redis://localhost:6380");
jedis.auth("foobared");
jedis.del("mykey");
try {
List<Long> responses = jedis.bitfield("mykey", "INCRBY","i5","100","1", "GET", "u4", "0");
assertEquals(1l, responses.get(0).longValue());
assertEquals(0l, responses.get(1).longValue());
} finally {
jedis.del("mykey");
}
}
示例12: setUp
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
node1 = new Jedis(nodeInfo1.getHost(), nodeInfo1.getPort());
node1.auth("cluster");
node1.flushAll();
node2 = new Jedis(nodeInfo2.getHost(), nodeInfo2.getPort());
node2.auth("cluster");
node2.flushAll();
}
示例13: checkCloseableConnections
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Test
public void checkCloseableConnections() throws Exception {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, config, 1000,
"foobared", 2);
Jedis jedis = pool.getResource();
jedis.auth("foobared");
jedis.set("foo", "bar");
assertEquals("bar", jedis.get("foo"));
pool.returnResource(jedis);
pool.close();
assertTrue(pool.isClosed());
}
示例14: startWithUrl
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Test
public void startWithUrl() throws URISyntaxException {
Jedis j = new Jedis("localhost", 6380);
j.auth("foobared");
j.select(2);
j.set("foo", "bar");
Jedis jedis = new Jedis(new URI("redis://:[email protected]st:6380/2"));
assertEquals("PONG", jedis.ping());
assertEquals("bar", jedis.get("foo"));
}
示例15: connectWithoutShardInfo
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* Tests opening a default SSL/TLS connection to redis.
*/
@Test
public void connectWithoutShardInfo() {
// The "rediss" scheme instructs jedis to open a SSL/TLS connection.
Jedis jedis = new Jedis(URI.create("rediss://localhost:6390"));
jedis.auth("foobared");
jedis.get("foo");
jedis.close();
}