A Dating Tool for Returning Inmates
Tags: database, redis, tutorial, discuss
Published: 2022-07-01 14:28:00

This would be the first blog post of this series that teaches how to build a dating tool for returning inmates using RedisJSON and RediSearch. This first part of the series talks about the various data dimensions in matchmaking returning inmates, and how to collect some of this data and store these data in RedisJSON.

And I hope that by the end of this tutorial, you have developed the capacity to store JSON documents using RedisJSON, be familiar with Redis Cloud and Redis Stack, and achieve the first part of a tool to help the returning inmates fit into the society better.

###Let us Begin! 

The pain of ex-inmates returning to society cannot be underestimated. As seen in the movie, [the Shawshank Redemption](https://en.wikipedia.org/wiki/The_Shawshank_Redemption), getting out of the system (the now usual way of life in prison) into the society is not that easy, especially for ex-inmates who stayed for a long while. Still, this remains a neglected problem in most societies. 

So that we don’t give an ex-inmate the option of crime, let’s get them reintegrated into society faster. Dating a person who has also been in the system could be a faster way to achieve that. To matchmake both entities, we need to consider their peculiar dating interests. The more data we have for these interests, the more we can give the perfect match. Usually, when building a social tool that involves complex relationships amongst entities, it is recommended to use a graph database such as [RedisGraph](https://redis.io/docs/stack/graph/). We may explore this later as we progress. But not to complicate things, for now, we would rather store these interests coming from various Omni-channels such as social media, sms, online forms, text, etc. in JSON. Often, this is the first step of the data analysis process known as data collection. 

In data analysis, the data collection phase involves collecting data from various channels as unrestrictive as possible to be able to make inferences and visualize data patterns. We would be studying these data collected in JSON to detect patterns which would then inform our functional requirements for our dating tool. You don’t want to build what is not going to be useful, you know. A beautiful way in collecting this kind of data across manual, automated, and semi-automated systems is by using JSON. 

###What is JSON and Why Store data in JSON?

The JavaScript Object Notation (JSON) standard is a standard for transferring multiple data structures among applications and systems. And it is very popular among developers. The name “Jason” is not even half as popular with this group of people. While you are thinking about what made this JSON data representation standard so common, and why it is known to be the de-facto standard for REST API and many other API standard alternatives, let’s try to see for ourselves with our dating use case.

###A Perfect Data Store for Our Use-Case

The various data sources of interest for the matchmaking app may include gender, race, sexual orientation, date of birth, correctional center, years served and because of more peculiar needs, this data may not have to follow a strict schema. For instance, some data dimensions such as social media handles may be compulsory if ingesting this data from social media but not compulsory for someone trying to matchmake via a text platform. 

Therefore, a database that does not force schema on us is suitable. And a data format that would suit well and be fast in transferability of data across systems would be useful. And JSON fits well for that use-case with little complexities. Asides from this, the data format is great for adding metadata to each data item as in the case of dating. For extra information on each data component, metadata could be added for more granularity of the interests.  Storing data as JSON is not only great for temporary needs, but we can also have a much more permanent store of this JSON data. This is one type of document database. There are 2 types of document databases (non-relational databases that store data as a collection of documents). NoSQL databases are the first types that are non-relational, but the documents can be queried in a declarative manner, and the second type are JSON document databases which stores data non-relationally as JSON. And since we have seen how awesome JSON is, we sure are adopting the JSON document database.

###RedisJSON

By far, [RedisJSON](https://redis.io/docs/stack/json/) is the best JSON document database out there. Yeah! RedisJSON is fast as a bolt! On storing JSON data, it is super easy. In querying JSON data, it provides a myriad of opportunities for complex queries. The whole setup is a breeze and follows some of the best DevOps standards. With docker, you can get it up and running in seconds. You can have it on-premise or even on the most popular cloud platforms including RedisCloud. Faster writes! Master might! Low latency!

###Store Data in RedisJSON 
At this point, we have our data being collated from various sources into JSON. An online form has been advertised to returning inmates and the filled form gets the data in JSON, some are sending text messages, others are communicating via social media, and all are being converted to JSON data. Even the Prison Warden is waiting to be hooked up with one of the returnees that share interests from the received text.

How do we then store these JSON documents to RedisJSON? For me, I love the fastest route. I create a [free Redis Enterprise Cloud account](https://redis.com/try-free/). Once you click on “Get Started”, you will receive an email with a link to activate your account and complete your signup process. I select my preferred cloud Vendor, and then a database is created for my enterprise automatically as seen below. 

![Olufemi Redis Database](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/22l5wsskitpiqgfa8ljj.png)

Guess what? I also have RedisJSON coming out of the box. As you can see, RedisJSON is one module out of the several extensions of Redis known as [Redis Stack](https://redis.io/docs/stack/). For a list of other services provided by Redis Stack, visit [Redis Stack](https://redis.io/docs/stack/). You can also check the [installation guide](https://redis.io/docs/stack/get-started/install/) on other methods asides the RedisCloud.



![Redis Extensions](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xzhtdboi5739wj69aotx.jpeg)
 


 
To be honest, how fast was that? Why don’t we add some comfort to the speed? You would need to interact and see visualizations of your newly created database even from your local computer. Provisions of that and more are made available via [RedisInsight](https://redis.com/redis-enterprise/redis-insight/). 

Download RedisInsight v2 on your local system from this [link](https://redis.com/redis-enterprise/redis-insight/) and you should have the below. Add the database with your cloud details:


![Redis Insight](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8sq9y4imjxerole72wgg.png)


Worked! We can see our database setup.


![Redis Insight Database Showcase](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ajku0ihbk6tgklcfrvgv.png)
 
Click on the database. And on the left-side bar of the next page, click the pencil icon for workbench. Let’s run some commands:

Let’s assume we are ingesting a returning inmate’s interest from a text message converter that says specify height, sexual orientation, body size and correctional center separated by whitespaces. We can decide to store it like this:

```
JSON.SET criteria .  ' "6ft Bi Muscular Michigan" '
```

And if we get OK as the result as seen below, it has been stored.

####Result:
```
OK
```

This is called a Scalar storage, which simply means what is being stored is a string of characters.

To insert the data by Object Storage which rather takes it as a JSON object, we write this command:

```
JSON.SET criteria_object $ '{ "criteria": { "height": "6ft", "sexual_orientation": Bi,"body_size": muscular,  ,"correctional_center": Michigan }  } '
```

And if we get OK as the result as seen below, we are good to go.
####Result:
```
OK
```

Another kind of storage, stores an array of JSON objects(multiple information):

```
JSON.SET criteria_array .  '{"criteria":[         {"height":"6ft", "sexual_orientation":"asexual", "age":20},         
{"height":"4ft", "sexual_orientation":":"straight", "age":28},       
{"height":"3ft", "sexual_orientation":":"lesbian", "age":63},         
{"height":"5ft", "sexual_orientation":":"bi", "age":41}    ]}   '
```

And if we get OK as the result as seen below, we are good to go.

####Result:
```
OK
```

And if we go to our RedisInsight dashboard, we can see that we have this data stored up for our use.

For the next tutorials, we would see how we can set this data into RedisJSON by building an online form, querying the data dimensions for the different sets of match criteria, and probably prepping up for another brilliant tool- [RediSearch!](https://redis.io/docs/stack/search/)  

Let’s get this project interesting!!!! Suggest contents for datasets on the comment box below and criteria for matching.

###**This post is in collaboration with Redis**.

###You can check the following references for ideas:

-	[Try Redis Cloud for free](https://redis.com/try-free/?utm_campaign=write_for_redis)
-	[Watch this video on the benefits of Redis Cloud over other Redis providers](https://www.youtube.com/watch?v=vyxdC1qK4NE)
-	[Redis Developer Hub - tools, guides, and tutorials about Redis](https://developer.redis.com/?utm_campaign=write_for_redis)
-	[RedisInsight Desktop GUI](https://redis.io/docs/stack/insight/?utm_campaign=write_for_redis)