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


Java RedisClient.create方法代码示例

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


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

示例1: init

import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
@Override
public void init(AbstractConfiguration config) {
    if (!config.getString("redis.type").equals("master_slave")) {
        throw new IllegalStateException("RedisSyncSingleStorageImpl class can only be used with master slave redis setup, but redis.type value is " + config.getString("redis.type"));
    }

    List<String> address = parseRedisAddress(config.getString("redis.address"), 6379);
    int databaseNumber = config.getInt("redis.database", 0);
    String password = StringUtils.isNotEmpty(config.getString("redis.password")) ? config.getString("redis.password") + "@" : "";

    // lettuce
    RedisURI lettuceURI = RedisURI.create("redis://" + password + address.get(0) + "/" + databaseNumber);
    this.lettuceMasterSlave = RedisClient.create(lettuceURI);
    this.lettuceMasterSlaveConn = MasterSlave.connect(this.lettuceMasterSlave, new Utf8StringCodec(), lettuceURI);
    this.lettuceMasterSlaveConn.setReadFrom(ReadFrom.valueOf(config.getString("redis.read")));

    // params
    initParams(config);
}
 
开发者ID:longkerdandy,项目名称:mithqtt,代码行数:20,代码来源:RedisSyncMasterSlaveStorageImpl.java

示例2: testAsync

import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
private static void testAsync() {

        System.out.println("TEST Lettuce async ======================================================");
        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();
    }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:26,代码来源:DoTestLettuceHookProxy.java

示例3: 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);
    }
}
 
开发者ID:Arraying,项目名称:Arraybot,代码行数:23,代码来源:Redis.java

示例4: 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();
}
 
开发者ID:3Cores,项目名称:sostream,代码行数:25,代码来源:TestRedisLettuce.java

示例5: startUp

import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
private void startUp() {
    logger.info("Starting RedisLettuceService");
    {
        logger.debug("Redis settings:");
        logger.debug("* host={}", cfgHost);
        logger.debug("* port={}", cfgPort);
        logger.debug("* db={}", cfgDb);
    }

    RedisURI redisURI = new RedisURI();
    redisURI.setHost(cfgHost);
    redisURI.setPort(cfgPort);
    redisURI.setDatabase(cfgDb);
    client = RedisClient.create(redisURI);
    connection = client.connect();
    asyncConnection = client.connect();
    syncCommands = connection.sync();
    asyncCommands = asyncConnection.async();
    asyncConnection.setAutoFlushCommands(false);

    logger.info("Connected to a redis client");
}
 
开发者ID:grouplens,项目名称:samantha,代码行数:23,代码来源:RedisLettuceService.java

示例6: findRedisConnection

import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
private static RedisClient findRedisConnection(String host, int port) {
	ClientResources clientResources = DefaultClientResources.builder()//
			.reconnectDelay(Delay.constant(10, TimeUnit.SECONDS))//
			.build();

	RedisURI redisUri = new RedisURI(host, port, 2, TimeUnit.SECONDS);

	ClientOptions clientOptions = ClientOptions.builder() //
			.disconnectedBehavior(DisconnectedBehavior.REJECT_COMMANDS)//
			.build();

	RedisClient redis = RedisClient.create(clientResources, redisUri);
	redis.setOptions(clientOptions);

	return redis;
}
 
开发者ID:ctripcorp,项目名称:x-pipe,代码行数:17,代码来源:LuttuceJedisCompareTest.java

示例7: createRedisClient

import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
private RedisClient createRedisClient(String host, int port) {
    RedisURI redisUri = new RedisURI(host, port, 2, TimeUnit.SECONDS);
    SocketOptions socketOptions = SocketOptions.builder()
            .connectTimeout(XPipeConsoleConstant.SOCKET_TIMEOUT, TimeUnit.SECONDS)
            .build();
    ClientOptions clientOptions = ClientOptions.builder() //
            .socketOptions(socketOptions)
            .disconnectedBehavior(ClientOptions.DisconnectedBehavior.REJECT_COMMANDS)//
            .build();

    DefaultClientResources clientResources = DefaultClientResources.builder()//
            .reconnectDelay(Delay.constant(1, TimeUnit.SECONDS))//
            .build();
    RedisClient redis = RedisClient.create(clientResources, redisUri);
    redis.setOptions(clientOptions);
    return redis;
}
 
开发者ID:ctripcorp,项目名称:x-pipe,代码行数:18,代码来源:RedisSessionTest.java

示例8: init

import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
@Override
public void init(AbstractConfiguration config) {
    if (!config.getString("redis.type").equals("single")) {
        throw new IllegalStateException("RedisSyncSingleStorageImpl class can only be used with single redis setup, but redis.type value is " + config.getString("redis.type"));
    }

    List<String> address = parseRedisAddress(config.getString("redis.address"), 6379);
    int databaseNumber = config.getInt("redis.database", 0);
    String password = StringUtils.isNotEmpty(config.getString("redis.password")) ? config.getString("redis.password") + "@" : "";

    // lettuce
    RedisURI lettuceURI = RedisURI.create("redis://" + password + address.get(0) + "/" + databaseNumber);
    this.lettuce = RedisClient.create(lettuceURI);
    this.lettuceConn = this.lettuce.connect();

    // params
    initParams(config);
}
 
开发者ID:longkerdandy,项目名称:mithqtt,代码行数:19,代码来源:RedisSyncSingleStorageImpl.java

示例9: init

import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
@Override
public void init(AbstractConfiguration config) {
    if (!config.getString("redis.type").equals("sentinel")) {
        throw new IllegalStateException("RedisSyncSingleStorageImpl class can only be used with sentinel redis setup, but redis.type value is " + config.getString("redis.type"));
    }

    List<String> address = parseRedisAddress(config.getString("redis.address"), 26379);
    int databaseNumber = config.getInt("redis.database", 0);
    String password = StringUtils.isNotEmpty(config.getString("redis.password")) ? config.getString("redis.password") + "@" : "";
    String masterId = config.getString("redis.master");

    // lettuce
    RedisURI lettuceURI = RedisURI.create("redis-sentinel://" + password + String.join(",", address) + "/" + databaseNumber + "#" + masterId);
    this.lettuceSentinel = RedisClient.create(lettuceURI);
    this.lettuceSentinelConn = MasterSlave.connect(this.lettuceSentinel, new Utf8StringCodec(), lettuceURI);
    this.lettuceSentinelConn.setReadFrom(ReadFrom.valueOf(config.getString("redis.read")));

    // params
    initParams(config);
}
 
开发者ID:longkerdandy,项目名称:mithqtt,代码行数:21,代码来源:RedisSyncSentinelStorageImpl.java

示例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();

        List<RedisURI> nodes = Arrays.asList(RedisURI.create("redis://host1"),
                RedisURI.create("redis://host2"),
                RedisURI.create("redis://host3"));

        StatefulRedisMasterSlaveConnection<String, String> connection = MasterSlave
                .connect(redisClient, new Utf8StringCodec(), nodes);
        connection.setReadFrom(ReadFrom.MASTER_PREFERRED);

        System.out.println("Connected to Redis");

        connection.close();
        redisClient.shutdown();
    }
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:19,代码来源:ConnectToMasterSlaveUsingElastiCacheCluster.java

示例11: init

import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
@Override
public void init(AbstractConfiguration config) {
    if (!config.getString("redis.type").equals("master_slave")) {
        throw new IllegalStateException("RedisSyncSingleStorage class can only be used with master slave redis setup, but redis.type value is " + config.getString("redis.type"));
    }

    List<String> address = parseRedisAddress(config.getString("redis.address"), 6379);
    int databaseNumber = config.getInt("redis.database", 0);
    String password = StringUtils.isNotEmpty(config.getString("redis.password")) ? config.getString("redis.password") + "@" : "";

    // lettuce
    RedisURI lettuceURI = RedisURI.create("redis://" + password + address.get(0) + "/" + databaseNumber);
    this.lettuceMasterSlave = RedisClient.create(lettuceURI);
    this.lettuceMasterSlaveConn = MasterSlave.connect(this.lettuceMasterSlave, new Utf8StringCodec(), lettuceURI);
    this.lettuceMasterSlaveConn.setReadFrom(ReadFrom.valueOf(config.getString("redis.read")));

    // redisson
    String masterNode = address.get(0);
    String[] slaveNodes = address.subList(1, address.size()).toArray(new String[address.size() - 1]);
    Config redissonConfig = new Config();
    redissonConfig.useMasterSlaveServers()
            .setMasterAddress(masterNode)
            .setLoadBalancer(new RoundRobinLoadBalancer())
            .addSlaveAddress(slaveNodes)
            .setReadMode(ReadMode.MASTER)
            .setDatabase(databaseNumber)
            .setPassword(StringUtils.isNotEmpty(password) ? password : null);
    this.redisson = Redisson.create(redissonConfig);

    // params
    initParams(config);
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:33,代码来源:RedisSyncMasterSlaveStorage.java

示例12: init

import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
@Override
public void init(AbstractConfiguration config) {
    if (!config.getString("redis.type").equals("sentinel")) {
        throw new IllegalStateException("RedisSyncSingleStorage class can only be used with sentinel redis setup, but redis.type value is " + config.getString("redis.type"));
    }

    List<String> address = parseRedisAddress(config.getString("redis.address"), 26379);
    int databaseNumber = config.getInt("redis.database", 0);
    String password = StringUtils.isNotEmpty(config.getString("redis.password")) ? config.getString("redis.password") + "@" : "";
    String masterId = config.getString("redis.master");

    // lettuce
    RedisURI lettuceURI = RedisURI.create("redis-sentinel://" + password + String.join(",", address) + "/" + databaseNumber + "#" + masterId);
    this.lettuceSentinel = RedisClient.create(lettuceURI);
    this.lettuceSentinelConn = MasterSlave.connect(this.lettuceSentinel, new Utf8StringCodec(), lettuceURI);
    this.lettuceSentinelConn.setReadFrom(ReadFrom.valueOf(config.getString("redis.read")));

    // redisson
    Config redissonConfig = new Config();
    redissonConfig.useSentinelServers()
            .setMasterName(masterId)
            .addSentinelAddress(address.toArray(new String[address.size()]))
            .setReadMode(ReadMode.MASTER)
            .setDatabase(databaseNumber)
            .setPassword(StringUtils.isNotEmpty(password) ? password : null);
    this.redisson = Redisson.create(redissonConfig);

    // params
    initParams(config);
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:31,代码来源:RedisSyncSentinelStorage.java

示例13: 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();
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:37,代码来源:TestRestService.java

示例14: 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";
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:31,代码来源:RedisService.java

示例15: lettuceAsyncTest

import com.lambdaworks.redis.RedisClient; //导入方法依赖的package包/类
@GET
@Path("lettuce_async_test")
@Produces(MediaType.TEXT_HTML + ";charset=utf-8")
public String lettuceAsyncTest() {

    System.out.println("TEST Lettuce async ======================================================");
    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();
    return "lettuce_async_test";
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:30,代码来源:RedisService.java


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