This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var rdb *redis.ClusterClient | |
| func main() { | |
| mux := goji.NewMux() | |
| mux.HandleFunc(pat.Get("/hello/:name"), hello) | |
| mux.HandleFunc(pat.Get("/get"), get) | |
| rdb = createRedis() | |
| http.ListenAndServe(":8099", mux) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM golang:latest | |
| RUN mkdir /app | |
| ADD . /app/ | |
| WORKDIR /app | |
| RUN go build -o my_app . | |
| EXPOSE 8099 | |
| CMD ["/app/my_app"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "encoding/json" | |
| "fmt" | |
| "math/rand" | |
| "net/http" | |
| "time" | |
| "goji.io" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void get(RoutingContext routingContext) { | |
| long start = System.nanoTime(); | |
| String userId = String.valueOf(new Random().nextInt(1000000)); | |
| String redisKey = "{" + userId + "}" + userId; | |
| RFuture<String> async = RedisClient.getRedisClient().<String>getBucket(redisKey).getAsync(); | |
| async.onComplete((val, throwable) -> { | |
| long end = System.nanoTime(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class RedisClient { | |
| private static RedissonClient redisClient; | |
| public static synchronized void newInstance(){ | |
| if(redisClient==null) { | |
| Config config = new Config(); | |
| config.setCodec(new StringCodec()); | |
| config.setThreads(Integer.parseInt(System.getenv("threads"))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM java:8-jre | |
| ENV VERTICLE_FILE starter-1.0.0-SNAPSHOT-fat.jar | |
| # Set the location of the verticles | |
| ENV VERTICLE_HOME /usr/verticles | |
| EXPOSE 8882 | |
| # Copy your fat jar to the container | |
| COPY target/$VERTICLE_FILE $VERTICLE_HOME/ | |
| # Launch the verticle | |
| WORKDIR $VERTICLE_HOME | |
| ENTRYPOINT ["sh", "-c"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MainVerticle extends AbstractVerticle | |
| { | |
| @Override | |
| public void start(Promise<Void> startPromise) throws Exception { | |
| Router router = Router.router(vertx); | |
| router.get("/hello").handler(this::hello); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MyFn extends DoFn<String, String> { | |
| @ProcessElement | |
| public void processElement(ProcessContext context,PipelineOptions options) { | |
| RedisOptions redisOptions = options.as(RedisOptions.class); | |
| RedissonClient redissonClient = redisOptions.getRedissonClient(); | |
| //some logic enrichment | |
| redis.get() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class RedisClientFactory implements DefaultValueFactory<RedissonClient> { | |
| @Override | |
| public RedissonClient create(PipelineOptions options) { | |
| RedisOptions redisOptions = options.as(RedisOptions.class); | |
| Config config = new Config(); | |
| config.useSingleServer() | |
| .setAddress("redis://" + redisOptions.getRedisHost().get() + ":" + redisOptions.getRedisPort().get()"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface RedisOptions extends PipelineOptions { | |
| ValueProvider<String> getRedisHost(); | |
| void setRedisHost(ValueProvider<String> value); | |
| ValueProvider<Integer> getRedisPort(); | |
| void setRedisPort(ValueProvider<Integer> value); | |
NewerOlder