-
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Redis & TimeToLive to Persistence module (#2383)
- Loading branch information
Showing
16 changed files
with
554 additions
and
69 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
"@effect/experimental": patch | ||
--- | ||
|
||
add TimeToLive module to @effect/experimental | ||
|
||
A trait for attaching expiry information to objects. | ||
|
||
```ts | ||
import * as TimeToLive from "@effect/experimental"; | ||
import { Duration, Exit } from "effect"; | ||
|
||
class User { | ||
[TimeToLive.symbol](exit: Exit.Exit<unknown, unknown>) { | ||
return Exit.isSuccess(exit) ? Duration.seconds(60) : Duration.zero; | ||
} | ||
} | ||
``` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@effect/experimental": patch | ||
--- | ||
|
||
add Redis Persistence module |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@effect/experimental": minor | ||
--- | ||
|
||
add TimeToLive support to Persistence module |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"effect": patch | ||
--- | ||
|
||
add Duration.isFinite api, to determine if a duration is not Infinity |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
services: | ||
redis: | ||
image: redis:alpine | ||
ports: | ||
- "6379:6379" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as Redis from "@effect/experimental/Persistence/Redis" | ||
import { persisted } from "@effect/experimental/RequestResolver" | ||
import * as TimeToLive from "@effect/experimental/TimeToLive" | ||
import { runMain } from "@effect/platform-node/NodeRuntime" | ||
import { Schema } from "@effect/schema" | ||
import { Effect, Exit, PrimaryKey, ReadonlyArray, RequestResolver } from "effect" | ||
|
||
class User extends Schema.Class<User>("User")({ | ||
id: Schema.number, | ||
name: Schema.string | ||
}) {} | ||
|
||
class GetUserById extends Schema.TaggedRequest<GetUserById>()("GetUserById", Schema.string, User, { | ||
id: Schema.number | ||
}) { | ||
[PrimaryKey.symbol]() { | ||
return `GetUserById:${this.id}` | ||
} | ||
[TimeToLive.symbol](exit: Exit.Exit<User, string>) { | ||
return Exit.isSuccess(exit) ? 30000 : 0 | ||
} | ||
} | ||
|
||
Effect.gen(function*(_) { | ||
const resolver = yield* _( | ||
RequestResolver.fromEffectTagged<GetUserById>()({ | ||
GetUserById: (reqs) => { | ||
console.log("uncached requests", reqs.length) | ||
return Effect.forEach(reqs, (req) => Effect.succeed(new User({ id: req.id, name: "John" }))) | ||
} | ||
}), | ||
persisted("users") | ||
) | ||
|
||
const users = yield* _( | ||
Effect.forEach(ReadonlyArray.range(1, 5), (id) => Effect.request(new GetUserById({ id }), resolver), { | ||
batching: true | ||
}) | ||
) | ||
|
||
console.log(users) | ||
}).pipe( | ||
Effect.scoped, | ||
Effect.provide(Redis.layerResult({})), | ||
runMain | ||
) |
This file contains 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
This file contains 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
Oops, something went wrong.