-
Notifications
You must be signed in to change notification settings - Fork 91
Redis json #1036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yisraelU
wants to merge
8
commits into
profunktor:series/2.x
Choose a base branch
from
yisraelU:redisJson
base: series/2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Redis json #1036
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
35a825c
initial algebra
yisraelU a2094f9
initial algebra
yisraelU d9bcbdf
additional fuinctions
yisraelU 54f50ba
doc
yisraelU ccd4fdc
compiles
yisraelU 2048f90
fix boxing
yisraelU 09c8861
merge
yisraelU ff97b63
avoid name collision for json
yisraelU File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
modules/effects/src/main/scala/dev/profunktor/redis4cats/algebra/json.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright 2018-2025 ProfunKtor | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.profunktor.redis4cats.algebra | ||
|
||
import dev.profunktor.redis4cats.algebra.json.JsonGetArgs | ||
import io.lettuce.core.json.arguments.{ JsonGetArgs => LJsonGetArgs, JsonRangeArgs } | ||
import io.lettuce.core.json.{ JsonPath, JsonType, JsonValue } | ||
|
||
trait JsonCommands[F[_], K, V] | ||
extends JsonArray[F, K, V] | ||
with JsonGet[F, K, V] | ||
with JsonSet[F, K, V] | ||
with JsonNumber[F, K, V] | ||
with JsonString[F, K, V] | ||
with JsonBoolean[F, K, V] { | ||
|
||
/** Clear container values (arrays/objects) and set numeric values to 0 | ||
* @return | ||
* Long the number of values removed plus all the matching JSON numerical values that are zeroed. | ||
*/ | ||
def jClear(key: K, path: JsonPath): F[Long] | ||
def jClear(key: K): F[Long] | ||
|
||
/** Deletes a value inside the JSON document at a given JsonPath | ||
* @return | ||
* Long the number of values removed (0 or more). | ||
*/ | ||
def jDel(key: K, path: JsonPath): F[Long] | ||
def jDel(key: K): F[Long] | ||
|
||
def jsonType(key: K, path: JsonPath): F[List[JsonType]] | ||
def jsonType(key: K): F[List[JsonType]] | ||
} | ||
trait JsonGet[F[_], K, V] { | ||
def jGet(key: K, path: JsonPath, paths: JsonPath*): F[List[JsonValue]] | ||
def jGet(key: K, arg: JsonGetArgs, path: JsonPath, paths: JsonPath*): F[List[JsonValue]] | ||
def jMget(path: JsonPath, key: K, keys: K*): F[List[JsonValue]] | ||
def jObjKeys(key: K, path: JsonPath): F[List[V]] | ||
def jObjLen(key: K, path: JsonPath): F[Long] | ||
} | ||
trait JsonSet[F[_], K, V] { | ||
def jMset(key: K, values: (JsonPath, JsonValue)*): F[Boolean] | ||
def jSet(key: K, path: JsonPath, value: JsonValue): F[Boolean] | ||
def jSetnx(key: K, path: JsonPath, value: JsonValue): F[Boolean] | ||
def jSetxx(key: K, path: JsonPath, value: JsonValue): F[Boolean] | ||
def jsonMerge(key: K, jsonPath: JsonPath, value: JsonValue): F[String]; | ||
} | ||
trait JsonNumber[F[_], K, V] { | ||
def numIncrBy(key: K, path: JsonPath, number: Number): F[List[Number]] | ||
} | ||
trait JsonString[F[_], K, V] { | ||
def strAppend(key: K, path: JsonPath, value: JsonValue): F[List[Long]] | ||
def strLen(key: K, path: JsonPath): F[Long] | ||
} | ||
trait JsonBoolean[F[_], K, V] { | ||
def toggle(key: K, path: JsonPath): F[List[Long]] | ||
} | ||
|
||
trait JsonArray[F[_], K, V] { | ||
def arrAppend(key: K, path: JsonPath, value: JsonValue*): F[Unit] | ||
def arrIndex(key: K, path: JsonPath, value: JsonValue, range: JsonRangeArgs): F[List[Long]] | ||
def arrInsert(key: K, path: JsonPath, index: Int, value: JsonValue*): F[List[Long]] | ||
def arrLen(key: K, path: JsonPath): F[List[Long]] | ||
def arrPop(key: K, path: JsonPath, index: Int): F[List[JsonValue]] | ||
def arrTrim(key: K, path: JsonPath, range: JsonRangeArgs): F[List[Long]] | ||
|
||
} | ||
|
||
object json { | ||
final case class JsonGetArgs( | ||
indent: Option[String], | ||
newline: Option[String], | ||
space: Option[String] | ||
) { | ||
def underlying: LJsonGetArgs = { | ||
val args = new LJsonGetArgs() | ||
indent.foreach(args.indent) | ||
newline.foreach(args.newline) | ||
space.foreach(args.space) | ||
args | ||
} | ||
} | ||
|
||
object JsonGetArgs | ||
} |
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
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What type does
.asJava
give back?