How to convert SQL table to Redis data

Hi, I am new to redis and want to help here. I am using java and sql server 2008 and redis server. To interact with redis, I use jedis api for java. I know that redis is used to store key-based things. Each key has a meaning.

Problem:

I have the name of the user table that stores data like id, name, email, age, country. This is a sql table schema. Now this table has several rows (also some data). Now here my primary key is id, and its just for using the DB. It is not needed for me in the application.

Now in sql I can insert a new row, update the row, search for any user, delete the user.

I want to save this table data in redis. Then I want to perform similar operations on redis, for example, search, insert, delete. But if I have a good design in the section "Storing this information in the database and Redis", then these operations will be performed simply. Remember that I also have several tables. Therefore, you should store data in redis based on a table.

My problem

Any design or information you can advise me on how I can convert DB data to Redis and perform all operations. I ask about this because I know that Facebook also uses redis to store data. Then how they store the data.

Any help would be greatly appreciated.

+5
source share
1 answer

This is a very difficult question to answer, as you can do several ways.

The best way, in my opinion, is to use hashes. This is basically a nested nested key type. This way your key will match the hash so that you can store your username, password, etc.

One problem is indexing, you will need to have an identifier stored in a key. For example, each user should have this key: USER:21414

Secondly, if you do not want to look at commands like KEYS or SCAN , you will have to maintain your own list of users for repetition only if you need to do this. To do this, you need to look at lists or sorted sets.

Honestly, there is no true answer to this question; SQL style data is not mapped to key-value in any real way. Usually you have to do a lot more work.

I suggest reading as much as possible and starting here http://redis.io/commands and here http://redis.io/documentation .

I have no experience using Jedis, so I cannot help with this. If you need an example, I have an open source social networking site that uses Redis as its only data warehouse. You can take a look at the code to get some ideas https://github.com/pjuu/pjuu/blob/master/pjuu/auth/backend.py . It uses Python, but Redis is such an easy thing to use wherever there is no difference.

Edit: My site above not only uses Redis. An older branch should be checked, e.g. 0.4 or 0.3 :)

+1
source

Source: https://habr.com/ru/post/1202428/


All Articles