by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jun 02 21:04

    github-actions[bot] on gh-pages

    updated site updated site updated site and 18 more (compare)

  • Jun 02 20:51

    gvolpe on master

    Automating site publishing Syncing with origin/master (compare)

  • Jun 02 19:54

    mergify[bot] on master

    Update sbt-tpolecat to 0.1.12 Merge pull request #307 from sc… (compare)

  • Jun 02 19:54
    mergify[bot] closed #307
  • Jun 02 18:58
    mergify[bot] closed #308
  • Jun 02 18:58

    mergify[bot] on master

    Update sbt-mdoc to 2.2.1 Merge pull request #308 from sc… (compare)

  • Jun 02 18:51
    scala-steward opened #308
  • Jun 02 18:51
    scala-steward opened #307
  • Jun 02 17:27

    gvolpe on master

    Testing the update of documenta… (compare)

  • Jun 02 17:22

    gvolpe on master

    Run CI build only when the Scal… (compare)

  • Jun 02 17:14

    gvolpe on automated-publishing

    (compare)

  • Jun 02 17:14

    gvolpe on master

    Automated microsite publishing … (compare)

  • Jun 02 17:14
    gvolpe closed #305
  • Jun 02 17:05
    gvolpe synchronize #305
  • Jun 02 17:05

    gvolpe on automated-publishing

    publish-site.dhall (compare)

  • Jun 01 14:45
    gvolpe closed #244
  • Jun 01 14:45
    gvolpe commented #244
  • Jun 01 12:56

    mergify[bot] on master

    Update munit, munit-scalacheck … Merge pull request #306 from sc… (compare)

  • Jun 01 12:56
    mergify[bot] closed #306
  • Jun 01 12:50
    scala-steward opened #306
Buk Lau
@mk9023_gitlab
Thank you @gvolpe for great documentation on codecs. Having read all of it I will take your advices at I will do my own serialisation/deserialisation because I will be using your library in my Scala Play application and the class dependency inject the redis client is a Singleton class. So I only want one Redis client active at any time and be able to re-use it. Thank you sir.
Gabriel Volpe
@gvolpe
:+1:
Gabriel Volpe
@gvolpe
More on codecs: profunktor/redis4cats#296
Buk Lau
@mk9023_gitlab
@gvolpe does your library come with configuration feature for redis server? For example I want to control how long to wait if redis4cats cannot connect to redis server because maybe it is down. Do you have such configuration?
Gabriel Volpe
@gvolpe
Hi @mk9023_gitlab , that's a good question. The library doesn't provide this option at the moment but it should be easy to add support for it. The underlying Redis client takes in a ClientOptions as an argument which has the following defaults:
    public static final boolean DEFAULT_PING_BEFORE_ACTIVATE_CONNECTION = false;
    public static final boolean DEFAULT_AUTO_RECONNECT = true;
    public static final boolean DEFAULT_CANCEL_CMD_RECONNECT_FAIL = false;
    public static final boolean DEFAULT_PUBLISH_ON_SCHEDULER = false;
    public static final boolean DEFAULT_SUSPEND_RECONNECT_PROTO_FAIL = false;
    public static final int DEFAULT_REQUEST_QUEUE_SIZE = Integer.MAX_VALUE;
    public static final DisconnectedBehavior DEFAULT_DISCONNECTED_BEHAVIOR = DisconnectedBehavior.DEFAULT;
    public static final SocketOptions DEFAULT_SOCKET_OPTIONS = SocketOptions.create();
    public static final SslOptions DEFAULT_SSL_OPTIONS = SslOptions.create();
    public static final TimeoutOptions DEFAULT_TIMEOUT_OPTIONS = TimeoutOptions.create();
    public static final int DEFAULT_BUFFER_USAGE_RATIO = 3;
I can work on it and release it as part of the upcoming RC3 so you can try it out if you wish to
Gabriel Volpe
@gvolpe
Here it goes @mk9023_gitlab : profunktor/redis4cats#297
Buk Lau
@mk9023_gitlab
wow, that's really fast @gvolpe :)
also I have a problem now. I am trying to integration your library with my Scala Play application. What I am finding is that for every HTTP request, the library tries to make new connection to Redis every time. This is not acceptable for me as it takes then 1 or 2 seconds to connect and then once command is done then library is closing connection. What I like is for library to keep connection to Redis open for duration of web application running. Is this possible sir?
Gavin Bisesi
@Daenyth
@mk9023_gitlab It sounds like you probably are calling use inside each request
Buk Lau
@mk9023_gitlab
yes that's right @Daenyth
Gavin Bisesi
@Daenyth

The scope of use is the scope of the Resource lifetime. It's similar to java try-with-resources or python context managers.

The code should instead accept a redis client as a constructor parameter, and reuse the same one. use would be called in one place, near your main method of your application.

See this for more: https://typelevel.org/blog/2018/06/07/shared-state-in-fp.html

Buk Lau
@mk9023_gitlab
thank you @Daenyth - I will look there
Gavin Bisesi
@Daenyth
Here's a full-stack example application (from the excellent "Practical FP in scala" book)
https://github.com/gvolpe/pfps-shopping-cart/blob/master/modules/core/src/main/scala/shop/Main.scala

If you aren't using IOApp you can still do it, you'd instead use one of the unsafeRun methods in your java-ish main method.

And if your application is set up so that some framework has main and you don't control things, that's more complicated to set up, and it won't be as clean, but can be made to work as you want using whatever tool's dependency injection stuff

Buk Lau
@mk9023_gitlab
Yes, I am not sure if you are familiar with Scala Play web framework but I can create Module where I can create a Redis4Cats client and create Redis connection there. Once created then I can dependency inject into my classes. I think this is what I should do. I will experiemnting.
Gavin Bisesi
@Daenyth
If play gives you setup/shutdown hooks then you'd use clientResouce.allocated.unsafeRunSync() to get the object and its shutdown handler
you can stash those in a var, then tie them into the hooks
super not a fan of play's dep injection style - fp scala (tbh all scala, and I've done it well in python too...) is much easier if you just use constructor parameters rather than all the magic and ceremony
Buk Lau
@mk9023_gitlab
@Daenyth thanks with your advices I got it Redis4Cats working nicely with Scala Play framework. I'm wondering if I can use a different logger other than SLF4J with https://github.com/ChristopherDavenport/log4cats . I want to use this: https://logging.apache.org/log4j/2.x/ - will this be possible with Redis4Cats. I tried but I don't know how. Thanks
Gabriel Volpe
@gvolpe
Yes, you can @mk9023_gitlab. Just need to create your own instance of Log
implicit val log4jInstance: Log[IO] = new Log[IO] {...}
Gavin Bisesi
@Daenyth
@mk9023_gitlab As Gabriel says, you can log to basically any backend. Check out the log4cats repo, there's support for a variety of systems
Buk Lau
@mk9023_gitlab
Yes, thanks for the advices. I have Log4J2 working now. It's really working well and fast.
Volodymyr Barna
@RobertoUa
Is there an implementation of Redlock in redis4cats?
Gabriel Volpe
@gvolpe
Not as far as I'm aware
Gabriel Volpe
@gvolpe
FYI: Monday or Tuesday next week I'll make a final 0.10.0 release if nothing comes up.
Christopher Davenport
@ChristopherDavenport
Did anyone get time for mapK yet?
Gabriel Volpe
@gvolpe
No one did yet, I can have a look
Gabriel Volpe
@gvolpe
There you go @ChristopherDavenport profunktor/redis4cats#300
If the automated CI release goes well, it'll be on Maven Central quite soon :rocket:
Gabriel Volpe
@gvolpe
:shipit:
ybasket
@ybasket
Hey, has anyone ever seen a 2 second delay when closing the redis connection? After the logs about releasing Commands and Redis, there’s a pretty precise and stable delay of 2 seconds before the release returns. I can reproduce this behaviour in a k8s deployed service with AWS ElastiCache, locally against a dockered redis and even in the redis4cats RedisSpec, so I assume it’s either a bug or some unfortunate configuration?
Background: Due to the use of blocking redis commands like brPopLPush, we open a new redis connection for certain requests. This works reasonably fast when connecting, but takes this extra time while shutting down the Resource[..., RedisCommands[...]]
ybasket
@ybasket
Nailed it down to some hardcoded timeout in lettuce, a shutdown timeout for a netty thread pool. So not strictly redis4cats-related, but be aware it exists
Gabriel Volpe
@gvolpe
Interesting finding @ybasket . I think I noticed it in the test suite but never paid attention.
Any reasons why the delay exists?
ybasket
@ybasket
Still digging deeper, but I’m pretty sure it’s the 2s from DefaultClientResources.shutdown() (Line 584) – it’s an overload to a method which allows passing some timeouts. Maybe redis4cats should expose a way to configure these timeouts, would be very simple to pass them down to lettuce, not much code in between. Do you already have any plans to create some redis4cats configuration class which could optionally be passed when creating the client?
In the meantime, I’m thinking of .starting the release into a separate fiber to bypass the delay it causes in the business logic
Gabriel Volpe
@gvolpe
Configuring the client is already possible @ybasket so it may be just one of the config options Lettuce exposes? https://redis4cats.profunktor.dev/client.html#client-configuration
ybasket
@ybasket
From what I see scrolling through ClientOptions, these values aren’t part of it, so they would need to be exposed separately
Gabriel Volpe
@gvolpe
Okay, I'm definitely up for adding the option of configuring such timeout
ybasket
@ybasket
Cool, I guess I can find time for making a PR soon-ish. Shall we then make it some case class RedisOptions(…) (name to be challenged) which can be extended when other options like this pop up?
Gabriel Volpe
@gvolpe
Yeah I guess that'd be fine. In Fs2-Rabbit there's an Fs2RabbitConfig, for example. The only issue with adding fields to case classes is that (I think) they are not binary compatible. Probably @Daenyth has some ideas around this
Gavin Bisesi
@Daenyth
Traits
If you want bincompat you need the config class people interact with to be a trait with builder-style methods
Adding new fields to a case class replaces the old copy signature, is the bincompat break
cats folks could probably give more ideas on how to work around that conveniently