Skip to content

Instantly share code, notes, and snippets.

View brachi-wernick's full-sized avatar

Brachi Packter brachi-wernick

  • moonactive
  • Israel
View GitHub Profile
@brachi-wernick
brachi-wernick / main.go
Created February 24, 2020 21:43
get redis api
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)
@brachi-wernick
brachi-wernick / Dockerfile
Created February 24, 2020 21:37
go docker file
FROM golang:latest
RUN mkdir /app
ADD . /app/
WORKDIR /app
RUN go build -o my_app .
EXPOSE 8099
CMD ["/app/my_app"]
@brachi-wernick
brachi-wernick / main.go
Created February 24, 2020 21:36
GoJi hello world
package main
import (
"encoding/json"
"fmt"
"math/rand"
"net/http"
"time"
"goji.io"
@brachi-wernick
brachi-wernick / RedisGet.java
Created February 24, 2020 21:24
api to get data from redis
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();
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")));
@brachi-wernick
brachi-wernick / Dockerfile
Last active February 24, 2020 21:11
docker vert.x
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"]
@brachi-wernick
brachi-wernick / MainVerticle.java
Created February 24, 2020 20:59
Vertx hello world
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);
@brachi-wernick
brachi-wernick / MyFn.java
Last active February 7, 2020 11:58
MyFn with using factory option
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()
@brachi-wernick
brachi-wernick / RedisClientFactory.java
Last active February 7, 2020 11:54
RedisClientFactory
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()");
public interface RedisOptions extends PipelineOptions {
ValueProvider<String> getRedisHost();
void setRedisHost(ValueProvider<String> value);
ValueProvider<Integer> getRedisPort();
void setRedisPort(ValueProvider<Integer> value);