This commit is contained in:
lxy 2021-03-05 10:59:13 +08:00
parent b9c6360241
commit 6a4a6bbf7e
7 changed files with 57 additions and 6 deletions

View File

@ -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();
}
//--------------------- ------------------------------
//--------------------- 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 ------------------------------
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);

View File

@ -36,13 +36,20 @@ public class RedisTest {
a = source.getBit("a", 1);
System.out.println("bit-a-1: " + a);*/
source.remove("a");
/*source.remove("a");
// setnx
System.out.println(source.setnx("a", 1));
source.remove("a");
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};
ExecutorService executor = Executors.newFixedThreadPool(10);
CountDownLatch latch = new CountDownLatch(10_0000);

View File

@ -5,9 +5,9 @@ import com.zdemo.IConsumer;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.common.errors.WakeupException;
import org.redkale.net.http.RestService;
import org.redkale.service.Service;
import org.redkale.util.AnyValue;
import org.redkale.util.AutoLoad;
import javax.annotation.Resource;
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 Logger logger = Logger.getLogger(this.getClass().getSimpleName());

View File

@ -4,9 +4,9 @@ import com.zdemo.IProducer;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.redkale.convert.json.JsonConvert;
import org.redkale.net.http.RestService;
import org.redkale.service.Service;
import org.redkale.util.AnyValue;
import org.redkale.util.AutoLoad;
import javax.annotation.Resource;
import java.io.File;
@ -20,7 +20,7 @@ import java.util.logging.Level;
*
* @param
*/
@RestService
@AutoLoad(false)
public class KafakProducer implements IProducer, Service {
private KafkaProducer<String, String> producer;

View 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() {
}
}

View File

@ -4,6 +4,7 @@ import com.zdemo.AbstractConsumer;
import com.zdemo.IConsumer;
import org.redkale.service.Service;
import org.redkale.util.AnyValue;
import org.redkale.util.AutoLoad;
import javax.annotation.Resource;
import java.io.BufferedReader;
@ -15,6 +16,7 @@ import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
@AutoLoad(false)
public class RedisConsumer extends AbstractConsumer implements IConsumer, Service {
public Logger logger = Logger.getLogger(this.getClass().getSimpleName());

View File

@ -4,6 +4,7 @@ import com.zdemo.IProducer;
import org.redkale.convert.json.JsonConvert;
import org.redkale.service.Service;
import org.redkale.util.AnyValue;
import org.redkale.util.AutoLoad;
import javax.annotation.Resource;
import java.io.IOException;
@ -12,6 +13,7 @@ import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.logging.Level;
@AutoLoad(false)
public class RedisProducer implements IProducer, Service {
@Resource(name = "property.redis.host")