Giter Site home page Giter Site logo

jredisjson's Introduction

GitHub issues CircleCI macos Dockerhub Codecov

RedisJSON

Forum Discord

logo

Overview

RedisJSON is a Redis module that implements ECMA-404 The JSON Data Interchange Standard as a native data type. It allows storing, updating and fetching JSON values from Redis keys (documents).

Primary features

  • Full support of the JSON standard
  • JSONPath syntax for selecting elements inside documents
  • Documents are stored as binary data in a tree structure, allowing fast access to sub-elements
  • Typed atomic operations for all JSON values types
  • Secondary index support when combined with RediSearch

Quick start

docker run -p 6379:6379 --name redis-stack redis/redis-stack:latest

Documentation

Read the docs at https://redis.io/docs/latest/develop/data-types/json/

How do I Redis?

Learn for free at Redis University

Build faster with the Redis Launchpad

Try the Redis Cloud

Dive in developer tutorials

Join the Redis community

Work at Redis

Build

Make sure you have Rust installed: https://www.rust-lang.org/tools/install

Then, build as usual:

cargo build --release

When running the tests, you need to explicitly specify the test feature to disable use of the Redis memory allocator when testing:

cargo test

If you forget to do this, you'll see an error mentioning signal: 4, SIGILL: illegal instruction.

Run

Linux

redis-server --loadmodule ./target/release/librejson.so

Mac OS

redis-server --loadmodule ./target/release/librejson.dylib

Client libraries

Official clients

NRedisStack Jedis node-redis redis-py
Redis.OM Redis OM Spring redis-om-node redis-om

Community supported clients

Project Language License Author Stars Package Comment
Redisson Java Apache-2.0 Redisson Redisson-stars Maven
redis-modules-java Java Apache-2.0 Liming Deng @dengliming redis-modules-java-stars maven
ioredis-rejson Node.js MIT Felipe Schulz @schulzf ioredis-rejson-stars npm
go-rejson Go MIT Nitish Malhotra @nitishm go-rejson-stars
rejonson Go Apache-2.0 Daniel Krom @KromDaniel rejonson-stars
rueidis Go Apache-2.0 Rueian @rueian rueidis-stars
NReJSON .NET MIT/Apache-2.0 Tommy Hanks @tombatron NReJSON-stars nuget
phpredis-json PHP MIT Rafa Campoy @averias phpredis-json-stars composer
redislabs-rejson PHP MIT Mehmet Korkmaz @mkorkmaz redislabs-rejson-stars composer
rejson-rb Ruby MIT Pavan Vachhani @vachhanihpavan rejson-rb-stars rubygems
rustis Rust MIT Dahomey Technologies rustis-stars crate Documentation
coredis Python MIT Ali-Akber Saifee @alisaifee coredis-stars pypi Documentation

Acknowledgments

RedisJSON is developed with <3 at Redis Labs.

RedisJSON is made possible only because of the existence of this amazing open source project:

License

RedisJSON is licensed under the Redis Source Available License 2.0 (RSALv2) or the Server Side Public License v1 (SSPLv1).

jredisjson's People

Contributors

bsbodden avatar chayim avatar dependabot[bot] avatar dragnot avatar gkorland avatar itamarhaber avatar sazzad16 avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jredisjson's Issues

Move SafeEncoder into Jedis

Hi,

Some months ago the SafeEncoder was moved into Jedis.Utils. (redis/jedis#1689)

Given this I got some errors when building (which anyone would probably get if they install the current Jedis 3.0.0-SNAPSHOT into their local repository). Changing the import path to: import redis.clients.jedis.util.SafeEncoder; fixes it.

I hope that pointing this out is useful.

Cheers,

Gabriel

json append

String json = "{"setting":{"profit_ report":{"profit_ report_ tb":{"__ meta":{"text":"abc"}}}}}";

Want to append a property check:true , how to write the set method

Compliation issue

When trying to install the JReJSON,

mvn clean install -Dmaven.test.skip=true

It throws an error,
[ERROR] C:\Softwares\JReJSON-master\src\main\java\com\redislabs\modules\rejson\JReJSON.java:[133,20] error: void cannot be dereferenced
did anyone get past this issue? If yes please let me know how.

Couldn't make a connection

Hi ,

I've started a redis-redisjson container and loaded the module as seen below:
image

now when trying to reach out the server from my java client - using 1.2.0 version I
keep get this message inside the JreJSON client:
java.lang.Exception
at org.apache.commons.pool2.impl.BaseGenericObjectPool.(BaseGenericObjectPool.java:147)
at org.apache.commons.pool2.impl.GenericObjectPool.(GenericObjectPool.java:110)
at redis.clients.jedis.util.Pool.initPool(Pool.java:45)
at redis.clients.jedis.util.Pool.(Pool.java:24)
at redis.clients.jedis.JedisPoolAbstract.(JedisPoolAbstract.java:15)
at redis.clients.jedis.JedisPool.(JedisPool.java:221)
at redis.clients.jedis.JedisPool.(JedisPool.java:165)
at redis.clients.jedis.JedisPool.(JedisPool.java:137)
at redis.clients.jedis.JedisPool.(JedisPool.java:76)
at redis.clients.jedis.JedisPool.(JedisPool.java:120)
at redis.clients.jedis.JedisPool.(JedisPool.java:103)
at redis.clients.jedis.JedisPool.(JedisPool.java:26)
at com.redislabs.modules.rejson.JReJSON.(JReJSON.java:99)
at io.redis.jedis.jedisdemo.JedisDemoApplication.start(JedisDemoApplication.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:305)
at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:190)
at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:153)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:403)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:360)
at org.springframework.boot.context.event.EventPublishingRunListener.running(EventPublishingRunListener.java:103)
at org.springframework.boot.SpringApplicationRunListeners.running(SpringApplicationRunListeners.java:77)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:330)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
at io.redis.jedis.jedisdemo.JedisDemoApplication.main(JedisDemoApplication.java:47) .

The code is trivial as in your examples and my container is listening to port 6379
`` JReJSON client = new JReJSON();
JReJSON client1 = new JReJSON("localhost", 6379);
JReJSON client2 = new JReJSON("127.0.0.1", 6379);
all these clients are failing .
May you please advise?

Thanks

How to get every single value from a special json

I have a json like following

`json.set doc . '{"":"empty", "\\":"slash","\'":"quote","\n":"enter", "\"":"double quote", "\'\'":"quote quote", "\t":"tab", "/":"value"}'`

if I want to get value "empty". I can use json.get doc "['']"
but how can I get other key 's value?

select db will have a error

config:

spring:
  redis:
    database: 6
    host: ${extraEnvHost}
    port: 6379
    password: ${redis.pwd}
    pool:
      minIdle: 1
      maxIdle: 10
      maxWait: 3
      maxActive: 8

@Component
public class JedisCompent {
    @Autowired
    private RedisConnectionFactory connectionFactory;
    @Autowired
    private Jedis jedis;

    @Bean
    public Jedis jedis(){
        Field jedisField = ReflectionUtils.findField(JedisConnection.class, "jedis");
        ReflectionUtils.makeAccessible(jedisField);
        Jedis jedis = (Jedis) ReflectionUtils.getField(jedisField, connectionFactory.getConnection());
        return jedis;
    }

    @Bean
    public JReJSON jReJSON(){
        return new JReJSON(jedis);
    }
}

@Slf4j
@RestController
@RequestMapping("/redis")
public class ExController {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private JReJSON jReJSON;
    @Autowired
    private Jedis jedis;

    @GetMapping(value = "/useRedisJSON")
    public int useRedisJSON(){
        long stime = SystemClock.now();

        jedis.set("kkkk","asdfasdf");

        String testJsonObjectName = "robben";
        jReJSON.set(testJsonObjectName,new Object());  //success in db6
        jReJSON.set(testJsonObjectName,21,new Path(".age"));   //error:   ERR new objects must be created at the root
        return 0;
    }
}

As shown in the figure above,Sometimes it fails!

Sometimes in db6 have a "robben" object is "{}" ,but After multiple executions,in db0 will get a right result({"age":21}). why?

if my don't set db in application.yml,All correct!

Is it because the jedis I created did not use the connection pool?

gson convert error

my test data is here
{"uid":1806217,"app":"znt","device_id":"879ce681_d5c7_4bbe_ae48_1e0a11c3bce1","create_time":"2022-02-23 10:17:14"}

the uid attribute is long

i have tried jReJSON.get(key, String.class, new Path("$.uid")),

image
image

i tried the jReJSON.get(key, List.class, new Path("$.uid")), or jReJSON.get(key, Object.class, new Path("$.uid"))
the resp is List but the item type is Double. the data is 1806217.0

then i try the jReJSON.get(key, String.class, new Path(".uid")), and convert is to a long manual

when i get moew than one property,
image

i have to defined a class that contains $.app and $.uid member ?

i think gson convert is worthless, can you remove it or provide an no convert method ?

ClassCastException on json.get

Exception in thread "main" java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to main$HM in line 5.

How does Java get multiple attributes?

How does Java get multiple attributes?

`
127.0.0.1:6379> json.get a
"{"name":"abcd","age":1,"type":1}"
127.0.0.1:6379> json.get a name age
"{"age":1,"name":"abcd"}"

`
截屏2022-01-18 18 38 22

Encoding gets lost in read-after-write

The Java driver for RedisJSON corrupts encoding when writing a value and then reading it again. Below is the code to reproduce the issue.

// the encoded string
String input = "Commodore’s Assemblers: Part 1: MOS Cross-Assembler";

// test with JReJSON
JReJSON jj = new JReJSON("localhost", 6379);
jj.set("test-json", input);
String o1 = jj.get("test-json");

System.out.println(o1.equals(input)); // prints false on OpenJDK 11

Note the issue is not exhibited when using Spring's RedisTemplate:

// initialize connection factory
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration("localhost", 6379);
JedisConnectionFactory jcf = new JedisConnectionFactory(redisStandaloneConfiguration);

// initialize redis template
RedisTemplate<String, Object> template = new RedisTemplate<>();

template.setConnectionFactory(this.redisConnectionFactory());
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new StringRedisSerializer());

// test
template.opsForValue().set("test-val", input);
String o2 = template.opsForValue().get("test-val");

System.out.println(o2.equals(input)); // prints true 

Set cache with expiration time

Hello,
Can you please add a method to set cache with expiration time? Currently, the cache doesn’t expire. Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.