本文整理汇总了Java中org.redisson.Redisson.create方法的典型用法代码示例。如果您正苦于以下问题:Java Redisson.create方法的具体用法?Java Redisson.create怎么用?Java Redisson.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.redisson.Redisson
的用法示例。
在下文中一共展示了Redisson.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mapsLocalCache2
import org.redisson.Redisson; //导入方法依赖的package包/类
void mapsLocalCache2(Waiter waiter) {
Config config = new Config();
config.useSingleServer().setAddress("http://127.0.0.1:6379");
RedissonClient client = Redisson.create(config);
LocalCachedMapOptions options = LocalCachedMapOptions.defaults().maxIdle(10 * 1000).timeToLive(10 * 1000);
RLocalCachedMap<String, Integer> map = client.getLocalCachedMap("myMap", options);
System.out.println("KEY BEFORE: " + map.get("key"));
try {
Thread.sleep(2000);
}
catch(InterruptedException e) {
e.printStackTrace();
}
System.out.println("KEY AFTER: " + map.get("key"));
waiter.assertEquals(map.get("key"), 25);
}
示例2: createInstance
import org.redisson.Redisson; //导入方法依赖的package包/类
@Override
public RedissonClient createInstance(int connections, String host) {
Config c = new Config();
// c.setUseLinuxNativeEpoll(true);
// c.useClusterServers()
c.useSingleServer()
.setTimeout(10000000)
.setAddress(host)
.setConnectionPoolSize(connections).setConnectionMinimumIdleSize(connections);
// .addNodeAddress(host)
// .setMasterConnectionPoolSize(connections).setMasterConnectionMinimumIdleSize(connections);
c.setCodec(StringCodec.INSTANCE);
RedissonClient r = Redisson.create(c);
r.getKeys().flushdb();
return r;
}
示例3: mapsItemChange2
import org.redisson.Redisson; //导入方法依赖的package包/类
void mapsItemChange2(Waiter waiter){
Config config = new Config();
config.useSingleServer().setAddress("http://127.0.0.1:6379");
RedissonClient client = Redisson.create(config);
LocalCachedMapOptions options = LocalCachedMapOptions.defaults().maxIdle(10 * 1000).timeToLive(10 * 1000);
RLocalCachedMap<String, FinalValue<Integer>> map = client.getLocalCachedMap("myMap", options);
FinalValue<Integer> value = map.get("test");
System.out.println("Value Before: " + value.get());
try {
Thread.sleep(2000);
}
catch(InterruptedException e) {
e.printStackTrace();
}
value = map.get("test");
System.out.println("Value After: " + value.get());
waiter.assertEquals(value.get(), 18);
}
示例4: provider
import org.redisson.Redisson; //导入方法依赖的package包/类
public static RedissonClient provider() {
if (client == null) {
Config config = new Config();
config.useSingleServer().setAddress("redis://" + REDIS_HOST + ":6379");
client = Redisson.create(config);
}
return client;
}
示例5: init
import org.redisson.Redisson; //导入方法依赖的package包/类
@Override
public void init(AbstractConfiguration config) {
if (!config.getString("redis.type").equals("single")) {
throw new IllegalStateException("RedisSyncSingleStorage 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();
// redisson
Config redissonConfig = new Config();
redissonConfig.useSingleServer()
.setAddress(address.get(0))
.setDatabase(databaseNumber)
.setPassword(StringUtils.isNotEmpty(password) ? password : null);
this.redisson = Redisson.create(redissonConfig);
// params
initParams(config);
}
示例6: main
import org.redisson.Redisson; //导入方法依赖的package包/类
public static void main(String[] args) {
Config config = new Config();
config.useClusterServers()
.addNodeAddress("127.0.0.1:7001", "127.0.0.1:7002", "127.0.0.1:7003");
RedissonClient redisson = Redisson.create(config);
RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config);
nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("myExecutor", 5));
RedissonNode node = RedissonNode.create(nodeConfig);
node.start();
RScheduledExecutorService e = redisson.getExecutorService("myExecutor");
e.schedule(new RunnableTask(), 10, TimeUnit.SECONDS);
e.schedule(new CallableTask(), 4, TimeUnit.MINUTES);
e.schedule(new RunnableTask(), CronSchedule.of("10 0/5 * * * ?"));
e.schedule(new RunnableTask(), CronSchedule.dailyAtHourAndMinute(10, 5));
e.schedule(new RunnableTask(), CronSchedule.weeklyOnDayAndHourAndMinute(12, 4, Calendar.MONDAY, Calendar.FRIDAY));
e.shutdown();
node.shutdown();
}
示例7: main
import org.redisson.Redisson; //导入方法依赖的package包/类
public static void main(String[] args) {
// connects to 127.0.0.1:6379 by default
RedissonClient redisson = Redisson.create();
RSortedSet<String> sortedSet = redisson.getSortedSet("mySortedSet");
sortedSet.add("1");
sortedSet.add("2");
sortedSet.add("3");
for (String string : sortedSet) {
// iteration through bulk loaded values
}
String firstValue = sortedSet.first();
String lastValue = sortedSet.last();
boolean removedValue = sortedSet.remove("1");
sortedSet.removeAll(Arrays.asList("1", "2", "3"));
sortedSet.containsAll(Arrays.asList("4", "1", "0"));
redisson.shutdown();
}
示例8: main
import org.redisson.Redisson; //导入方法依赖的package包/类
public static void main(String[] args) {
// connects to 127.0.0.1:6379 by default
RedissonClient redisson = Redisson.create();
RHyperLogLog<String> hyperLogLog = redisson.getHyperLogLog("hyperLogLog");
hyperLogLog.add("1");
hyperLogLog.add("2");
hyperLogLog.add("3");
hyperLogLog.addAll(Arrays.asList("10", "20", "30"));
RHyperLogLog<String> hyperLogLog1 = redisson.getHyperLogLog("hyperLogLog1");
hyperLogLog1.add("4");
hyperLogLog1.add("5");
hyperLogLog1.add("6");
RHyperLogLog<String> hyperLogLog2 = redisson.getHyperLogLog("hyperLogLog2");
hyperLogLog1.add("4");
hyperLogLog1.add("5");
hyperLogLog1.add("6");
hyperLogLog2.mergeWith(hyperLogLog1.getName());
hyperLogLog2.countWith(hyperLogLog1.getName());
redisson.shutdown();
}
示例9: main
import org.redisson.Redisson; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
// connects to 127.0.0.1:6379 by default
RedissonClient redisson = Redisson.create();
CountDownLatch latch = new CountDownLatch(1);
RTopic<String> topic = redisson.getTopic("topic2");
topic.addListener(new MessageListener<String>() {
@Override
public void onMessage(String channel, String msg) {
latch.countDown();
}
});
topic.publish("msg");
latch.await();
redisson.shutdown();
}
示例10: main
import org.redisson.Redisson; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
// connects to 127.0.0.1:6379 by default
RedissonClient redisson = Redisson.create();
RLock lock = redisson.getLock("lock");
lock.lock(2, TimeUnit.SECONDS);
Thread t = new Thread() {
public void run() {
RLock lock1 = redisson.getLock("lock");
lock1.lock();
lock1.unlock();
};
};
t.start();
t.join();
lock.unlock();
redisson.shutdown();
}
示例11: main
import org.redisson.Redisson; //导入方法依赖的package包/类
public static void main(final String[] args) {
final Config config = new Config();
config.useSingleServer()
.setAddress("redis-14926.c10.us-east-1-3.ec2.cloud.redislabs.com:14926")
.setConnectionMinimumIdleSize(1)
.setConnectionPoolSize(2);
final RedissonClient client = Redisson.create(config);
try {
final RemoteInterface service = client.getRemoteService().get(RemoteInterface.class);
final long result = service.myMethod(21L);
System.out.println("result = " + result);
} finally {
client.shutdown();
}
}
示例12: main
import org.redisson.Redisson; //导入方法依赖的package包/类
public static void main(final String[] args) {
final Config config = new Config();
config.useSingleServer()
.setAddress("redis-14926.c10.us-east-1-3.ec2.cloud.redislabs.com:14926")
.setConnectionMinimumIdleSize(1)
.setConnectionPoolSize(2);
// connects to 127.0.0.1:6379 by default
final RedissonClient server = Redisson.create(config);
final RedissonClient client = Redisson.create(config);
try {
server.getRemoteService().register(RemoteInterface.class, new RemoteImpl());
final RemoteInterface service = client.getRemoteService().get(RemoteInterface.class);
final long result = service.myMethod(21L);
System.out.println("result = " + result);
} finally {
client.shutdown();
server.shutdown();
}
}
示例13: main
import org.redisson.Redisson; //导入方法依赖的package包/类
public static void main(final String[] args) throws InterruptedException, ExecutionException {
final Config config = new Config();
config.useSingleServer()
.setAddress("redis-14926.c10.us-east-1-3.ec2.cloud.redislabs.com:14926")
.setConnectionMinimumIdleSize(1)
.setConnectionPoolSize(2);
final RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config);
nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("myExecutor", 1));
final RedissonNode node = RedissonNode.create(nodeConfig);
node.start();
final RedissonClient client = Redisson.create(config);
final RExecutorService e = client.getExecutorService("myExecutor");
System.out.println("executorService.isShutdown :" + e.isShutdown());
System.out.println("executorService.isTerminated :" + e.isTerminated());
//e.execute(new RunnableTask());
final Future<String> result = e.submit(new CallableTask());
System.out.println("result =" + result.get());
e.shutdown();
node.shutdown();
}
示例14: main
import org.redisson.Redisson; //导入方法依赖的package包/类
public static void main(String[] args) {
Config config = new Config();
config.useSingleServer()
.setAddress("168.168.3.59:6379");
Redisson redisson = Redisson.create(config);
long s = System.nanoTime();
RSet<String> set = redisson.getSet("anySet");
set.add("a");
long e = System.nanoTime();
System.out.println("need time" + (e - s)/1000000);
long s1 = System.nanoTime();
RSortedSet rss = redisson.getSortedSet("rs");
rss.add("ddddddddddd");
long e1 = System.nanoTime();
System.out.println("need time" + (e1 - s1)/1000000 + " ms");
}
示例15: connectRedis
import org.redisson.Redisson; //导入方法依赖的package包/类
/**
* Connects to a redis server with given config.<br>
* It is recommended to set the address and authentification to the config.<br>
* Example: {@link org.redisson.config.SingleServerConfig#setAddress(URI)}
*
* @param config The redisson config
*/
public void connectRedis(Config config) {
if(this.client != null) return;
this.config = config;
if(config != null) {
this.client = Redisson.create(config);
}
}