本文整理汇总了Java中com.lambdaworks.redis.RedisClient.connect方法的典型用法代码示例。如果您正苦于以下问题:Java RedisClient.connect方法的具体用法?Java RedisClient.connect怎么用?Java RedisClient.connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lambdaworks.redis.RedisClient
的用法示例。
在下文中一共展示了RedisClient.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
@Override
public void start() {
try {
if ( config.isCluster() ) {
RedisClusterClient clusterClient = createClusterClient( config.getHosts() );
this.redisClient = clusterClient;
log.connectingToRedis( config.getHosts().toString(), config.getTimeout() );
connection = clusterClient.connect( new Utf8StringCodec() );
}
else {
RedisClient client = createClient( config.getHosts().getFirst() );
this.redisClient = client;
log.connectingToRedis( config.getHosts().toString(), config.getTimeout() );
connection = client.connect( new Utf8StringCodec() );
}
}
catch (RuntimeException e) {
// return a ServiceException to be stack trace friendly
throw log.unableToInitializeRedis( e );
}
}
示例2: connect
import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
/**
* Connects to the Redis server.
* @param configuration The configuration object.
* @throws Exception If an error occurs.
*/
public void connect(Configuration configuration) throws Exception {
if(sync != null) {
return;
}
RedisURI.Builder uri = RedisURI.Builder.redis(configuration.getRedisHost(), configuration.getRedisPort())
.withDatabase(configuration.getRedisIndex());
if(!configuration.getRedisAuth().isEmpty()) {
uri.withPassword(configuration.getRedisAuth());
}
RedisClient client = RedisClient.create(uri.build());
StatefulRedisConnection<String, String> connection = client.connect();
sync = connection.sync();
for(Category category : Category.values()) {
logger.info("Registered the category {} with the type {}.", category, category.getEntry().getType());
category.getEntry().setCategory(category);
}
}
示例3: insertionRemoval
import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
@Test
public void insertionRemoval() throws NumberFormatException, InterruptedException, ExecutionException {
RedisClient redis = RedisClient.create("redis://127.0.0.1:6379");
StatefulRedisConnection<String, String> redisConn = redis.connect();
RedisAsyncCommands<String, String> redisCmd = redisConn.async();
long iterations = 1000;
for (long i = 0; i < iterations; i++) {
redisCmd.set(String.valueOf(i), String.valueOf(i + 1));
}
for (long i = 0; i < iterations; i++) {
long v = Long.valueOf(redisCmd.get(String.valueOf(i)).get());
assertEquals(i + 1, v);
}
for (long i = 0; i < iterations; i++) {
redisCmd.del(String.valueOf(i));
}
redisConn.close();
redis.shutdown();
}
示例4: initialize
import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
private void initialize() {
redisClient = new RedisClient(
plugin.getConfig().getString("redishost"), plugin.getConfig()
.getInt("redisport"));
redisPubSubConnection = redisClient.connectPubSub();
redisPubSubConnection.addListener(redisListener);
redisPubSubConnection.auth(plugin.getConfig().getString("redispass"));
redisPubSubConnection.subscribe(channels);
redisSendClient = new RedisClient(plugin.getConfig().getString(
"redishost"), plugin.getConfig().getInt("redisport"));
redis = redisSendClient.connect();
redis.auth(plugin.getConfig().getString("redispass"));
plugin.getServer().getScheduler()
.runTaskTimerAsynchronously(plugin, new Heartbeat(), 600, 1200);
System.out.println("Redis: Connection completed.");
}
示例5: testLettuce
import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
@POST
@Path("testLettuce")
public void testLettuce(String jsonString) {
RedisClient redisClient = RedisClient.create("redis://localhost:6379/0");
RedisConnection<String, String> conn1 = redisClient.connect();
conn1.set("foo", "bar");
String value = conn1.get("foo");
System.out.println(value);
conn1.close();
redisClient.shutdown();
RedisClient client = RedisClient.create("redis://localhost:6379/0");
RedisAsyncConnection<String, String> conn = client.connectAsync();
conn.set("foo", "bar");
conn.get("foo");
conn.lpush("lll", "a");
conn.lpush("lll", "b");
conn.lpush("lll", "c");
conn.lpop("lll");
conn.lpop("lll");
conn.lpop("lll");
conn.hset("mmm", "abc", "123");
conn.hset("mmm", "def", "456");
conn.hgetall("mmm");
conn.del("foo", "lll", "mmm");
conn.close();
client.shutdown();
}
示例6: lettucetest
import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
@GET
@Path("lettucetest")
@Produces(MediaType.TEXT_HTML + ";charset=utf-8")
public String lettucetest() {
System.out.println("TEST Lettuce sync ======================================================");
RedisClient redisClient = RedisClient.create("redis://localhost:6379/0");
RedisConnection<String, String> conn = redisClient.connect();
conn.set("foo", "bar");
conn.get("foo");
conn.lpush("lll", "a");
conn.lpush("lll", "b");
conn.lpush("lll", "c");
conn.lpop("lll");
conn.lpop("lll");
conn.lpop("lll");
conn.hset("mmm", "abc", "123");
conn.hset("mmm", "def", "456");
conn.hgetall("mmm");
conn.del("foo", "lll", "mmm");
conn.close();
redisClient.shutdown();
return "lettucetest";
}
示例7: testSync
import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
private static void testSync() {
System.out.println("TEST Lettuce sync ======================================================");
RedisClient redisClient = RedisClient.create("redis://localhost:6379/0");
RedisConnection<String, String> conn = redisClient.connect();
System.out.println("Connected to Redis");
conn.set("foo", "bar");
String value = conn.get("foo");
System.out.println(value);
conn.close();
redisClient.shutdown();
}
示例8: setConnection
import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
private static void setConnection() {
// RedisClient redisClient = RedisClient.create(new RedisURI("127.0.0.1", 6379, 10L, TimeUnit.SECONDS));
RedisClient redisClient = RedisClient.create("redis://127.0.0.1:6379");
// RedisClient redisClient = RedisClient.create(new RedisURI.Builder.redis("127.0.0.1", 6379).build());
connection = redisClient.connect();
connection1 = redisClient.connect();
}
示例9: connect
import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
@Override
public void connect() throws IOException
{
client = new RedisClient(host, port);
connection = client.connect();
connection.select(dbIndex);
}
示例10: main
import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
public static void main(String[] args) {
// Syntax: redis://[[email protected]]host[:port][/databaseNumber]
RedisClient redisClient = RedisClient.create("redis://[email protected]:6379/0");
StatefulRedisConnection<String, String> connection = redisClient.connect();
System.out.println("Connected to Redis");
connection.close();
redisClient.shutdown();
}
示例11: main
import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
public static void main(String[] args) {
// Syntax: redis://[[email protected]]host[:port][/databaseNumber]
DefaultClientResources clientResources = DefaultClientResources.builder() //
.dnsResolver(new DirContextDnsResolver()) // Does not cache DNS lookups
.build();
RedisClient redisClient = RedisClient.create(clientResources, "redis://[email protected]:6379/0");
StatefulRedisConnection<String, String> connection = redisClient.connect();
System.out.println("Connected to Redis");
connection.close();
redisClient.shutdown();
}
示例12: main
import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"com/lambdaworks/examples/SpringTest-context.xml");
RedisClient client = context.getBean(RedisClient.class);
StatefulRedisConnection<String, String> connection = client.connect();
RedisCommands<String, String> sync = connection.sync();
System.out.println("PING: " + sync.ping());
connection.close();
MySpringBean mySpringBean = context.getBean(MySpringBean.class);
System.out.println("PING: " + mySpringBean.ping());
context.close();
}
示例13: main
import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
public static void main(String[] args) {
// Syntax: redis://[[email protected]]host[:port][/databaseNumber]
RedisClient redisClient = RedisClient.create(RedisURI.create("redis://[email protected]:6379/0"));
StatefulRedisConnection<String, String> connection = redisClient.connect();
System.out.println("Connected to Redis");
RedisCommands<String, String> sync = connection.sync();
sync.set("foo", "bar");
String value = sync.get("foo");
System.out.println(value);
connection.close();
redisClient.shutdown();
}
示例14: connection
import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
@Bean(destroyMethod = "close")
StatefulRedisConnection<String, String> connection(RedisClient redisClient) {
return redisClient.connect();
}
示例15: main
import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
public static void main(String[] args) {
// Syntax: rediss://[[email protected]]host[:port][/databaseNumber]
// Adopt the port to the stunnel port in front of your Redis instance
RedisClient redisClient = RedisClient.create("rediss://[email protected]:6443/0");
StatefulRedisConnection<String, String> connection = redisClient.connect();
System.out.println("Connected to Redis using SSL");
connection.close();
redisClient.shutdown();
}