.
This commit is contained in:
parent
895df0e05a
commit
3d0d2f8f81
@ -204,7 +204,18 @@ public class MyRedisCacheSource<V extends Object> extends RedisCacheSource<V> {
|
|||||||
return (List<T>) send("EVAL", CacheEntryType.OBJECT, (Type) null, null, bytes).join();
|
return (List<T>) send("EVAL", CacheEntryType.OBJECT, (Type) null, null, bytes).join();
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------- ------------------------------
|
//--------------------- set ------------------------------
|
||||||
|
public <T> T srandomItem(String key) {
|
||||||
|
byte[][] bytes = Stream.of(key, 1).map(x -> formatValue(CacheEntryType.OBJECT, (Convert) null, (Type) null, x)).toArray(byte[][]::new);
|
||||||
|
List<T> list = (List) send("SRANDMEMBER", null, (Type) null, key, bytes).join();
|
||||||
|
return list != null && !list.isEmpty() ? list.get(0) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> List<T> srandomItems(String key, int n) {
|
||||||
|
byte[][] bytes = Stream.of(key, n).map(x -> formatValue(CacheEntryType.OBJECT, (Convert) null, (Type) null, x)).toArray(byte[][]::new);
|
||||||
|
return (List) send("SRANDMEMBER", null, (Type) null, key, bytes).join();
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------- list ------------------------------
|
//--------------------- list ------------------------------
|
||||||
public CompletableFuture<Void> appendListItemsAsync(String key, V... values) {
|
public CompletableFuture<Void> appendListItemsAsync(String key, V... values) {
|
||||||
byte[][] bytes = Stream.concat(Stream.of(key), Stream.of(values)).map(x -> String.valueOf(x).getBytes(StandardCharsets.UTF_8)).toArray(byte[][]::new);
|
byte[][] bytes = Stream.concat(Stream.of(key), Stream.of(values)).map(x -> String.valueOf(x).getBytes(StandardCharsets.UTF_8)).toArray(byte[][]::new);
|
||||||
|
@ -36,13 +36,20 @@ public class RedisTest {
|
|||||||
a = source.getBit("a", 1);
|
a = source.getBit("a", 1);
|
||||||
System.out.println("bit-a-1: " + a);*/
|
System.out.println("bit-a-1: " + a);*/
|
||||||
|
|
||||||
source.remove("a");
|
/*source.remove("a");
|
||||||
|
|
||||||
// setnx
|
// setnx
|
||||||
System.out.println(source.setnx("a", 1));
|
System.out.println(source.setnx("a", 1));
|
||||||
source.remove("a");
|
source.remove("a");
|
||||||
System.out.println(source.setnx("a", 1));
|
System.out.println(source.setnx("a", 1));
|
||||||
|
|
||||||
|
// set
|
||||||
|
source.remove("abx1");
|
||||||
|
source.appendSetItems("abx1", "a", "b", "c");
|
||||||
|
List<String> list = source.srandomItems("abx1", 2);
|
||||||
|
String str = source.srandomItem("abx1"); //r
|
||||||
|
System.out.println(list);//[r1, r2] */
|
||||||
|
|
||||||
/*int[] arr = {0};
|
/*int[] arr = {0};
|
||||||
ExecutorService executor = Executors.newFixedThreadPool(10);
|
ExecutorService executor = Executors.newFixedThreadPool(10);
|
||||||
CountDownLatch latch = new CountDownLatch(10_0000);
|
CountDownLatch latch = new CountDownLatch(10_0000);
|
||||||
|
@ -5,9 +5,9 @@ import com.zdemo.IConsumer;
|
|||||||
import org.apache.kafka.clients.consumer.ConsumerRecords;
|
import org.apache.kafka.clients.consumer.ConsumerRecords;
|
||||||
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
||||||
import org.apache.kafka.common.errors.WakeupException;
|
import org.apache.kafka.common.errors.WakeupException;
|
||||||
import org.redkale.net.http.RestService;
|
|
||||||
import org.redkale.service.Service;
|
import org.redkale.service.Service;
|
||||||
import org.redkale.util.AnyValue;
|
import org.redkale.util.AnyValue;
|
||||||
|
import org.redkale.util.AutoLoad;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -22,7 +22,7 @@ import java.util.logging.Logger;
|
|||||||
/**
|
/**
|
||||||
* 消费
|
* 消费
|
||||||
*/
|
*/
|
||||||
@RestService
|
@AutoLoad(false)
|
||||||
public abstract class KafakConsumer extends AbstractConsumer implements IConsumer, Service {
|
public abstract class KafakConsumer extends AbstractConsumer implements IConsumer, Service {
|
||||||
|
|
||||||
public Logger logger = Logger.getLogger(this.getClass().getSimpleName());
|
public Logger logger = Logger.getLogger(this.getClass().getSimpleName());
|
||||||
|
@ -4,9 +4,9 @@ import com.zdemo.IProducer;
|
|||||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||||
import org.redkale.convert.json.JsonConvert;
|
import org.redkale.convert.json.JsonConvert;
|
||||||
import org.redkale.net.http.RestService;
|
|
||||||
import org.redkale.service.Service;
|
import org.redkale.service.Service;
|
||||||
import org.redkale.util.AnyValue;
|
import org.redkale.util.AnyValue;
|
||||||
|
import org.redkale.util.AutoLoad;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -20,7 +20,7 @@ import java.util.logging.Level;
|
|||||||
*
|
*
|
||||||
* @param
|
* @param
|
||||||
*/
|
*/
|
||||||
@RestService
|
@AutoLoad(false)
|
||||||
public class KafakProducer implements IProducer, Service {
|
public class KafakProducer implements IProducer, Service {
|
||||||
private KafkaProducer<String, String> producer;
|
private KafkaProducer<String, String> producer;
|
||||||
|
|
||||||
|
29
src/com/zdemo/pulsar/AService.java
Normal file
29
src/com/zdemo/pulsar/AService.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package com.zdemo.pulsar;
|
||||||
|
|
||||||
|
import com.zdemo.zhub.ZHubClient;
|
||||||
|
import org.redkale.net.http.RestMapping;
|
||||||
|
import org.redkale.net.http.RestService;
|
||||||
|
import org.redkale.service.Service;
|
||||||
|
import org.redkale.util.AnyValue;
|
||||||
|
import org.redkale.util.Utility;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@RestService
|
||||||
|
public class AService implements Service {
|
||||||
|
|
||||||
|
@Resource(name = "zhub")
|
||||||
|
private ZHubClient zhub;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(AnyValue config) {
|
||||||
|
zhub.timer("a", () -> {
|
||||||
|
System.out.println(Utility.now() + " timer RANK-DATA-RELOADALL 执行了");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@RestMapping
|
||||||
|
public void x() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ import com.zdemo.AbstractConsumer;
|
|||||||
import com.zdemo.IConsumer;
|
import com.zdemo.IConsumer;
|
||||||
import org.redkale.service.Service;
|
import org.redkale.service.Service;
|
||||||
import org.redkale.util.AnyValue;
|
import org.redkale.util.AnyValue;
|
||||||
|
import org.redkale.util.AutoLoad;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
@ -15,6 +16,7 @@ import java.net.Socket;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
@AutoLoad(false)
|
||||||
public class RedisConsumer extends AbstractConsumer implements IConsumer, Service {
|
public class RedisConsumer extends AbstractConsumer implements IConsumer, Service {
|
||||||
|
|
||||||
public Logger logger = Logger.getLogger(this.getClass().getSimpleName());
|
public Logger logger = Logger.getLogger(this.getClass().getSimpleName());
|
||||||
|
@ -4,6 +4,7 @@ import com.zdemo.IProducer;
|
|||||||
import org.redkale.convert.json.JsonConvert;
|
import org.redkale.convert.json.JsonConvert;
|
||||||
import org.redkale.service.Service;
|
import org.redkale.service.Service;
|
||||||
import org.redkale.util.AnyValue;
|
import org.redkale.util.AnyValue;
|
||||||
|
import org.redkale.util.AutoLoad;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -12,6 +13,7 @@ import java.net.InetSocketAddress;
|
|||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
@AutoLoad(false)
|
||||||
public class RedisProducer implements IProducer, Service {
|
public class RedisProducer implements IProducer, Service {
|
||||||
|
|
||||||
@Resource(name = "property.redis.host")
|
@Resource(name = "property.redis.host")
|
||||||
|
Loading…
Reference in New Issue
Block a user