-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
store json data in redis #798
Comments
You probably want to use a hash in Redis. With a hash you can use One note, JS Objects can be nested, but Redis Hashes are only a single level. So, if your data looks something like this:
You'll need to use flat before storing it in redis. I wrote an article about that process. |
@stockholmux my data is stored in variable member. so how would i go about it? |
The proper way is hashed as explained above, and flat, as also explained. Although that member_string = JSON.stringify member
redis_client.set 'your_key', member_string
# something like that
# if your object is already flat then you can (just):
redis_client.hmset 'hash_key', member
# something like that, been awhile |
@abhinav76 It really depends on how you are accessing the data, but you'll likely want to access by your
Later, if you want to get that hash and all the fields you'd do:
You may also want to look into some sort of secondary store to keep track of all your |
thanks @kulicuu and @stockholmux . |
My redis data looks like below:
"{\"f_name\":\"\",\"profile\":{\"member_username\":\"nikhil371\",\"member_gender\":\"Male\",\"member_dob\":0,\"member_country\":\"\",\"state\":\"\",\"city\":\"\",\"hair_colour\":\"\",\"hairstyle\":\"\",\"eye_colour\":\"\",\"eyesight\":\"\",\"complexion\":\"\",\"height\":\"\",\"body_ENGINE\":\"\",\"exercise\":\"\",\"religion\":\"\",\"religious_beliefs\":\"\",\"education\":\"\",\"occupation\":\"\",\"annual_income\":\"\",\"ethnicity\":\"\",\"nationality\":\"\",\"languages\":\"\",\"diet\":\"\",\"smoke\":\"\",\"drink\":\"\",\"current_relationship_status\":\"\",\"preferred_relationship\":\"\",\"profile_tagline\":\"\",\"screened\":\"N\",\"photo_status\":\"None\",\"hidden\":\"N\",\"record_date\":0,\"update_date\":0,\"ip\":\"\",\"member_id\":10548,\"time_stamp\":0,\"photo_key\":\"\",\"profile_personality\":{\"member_username\":\"nikhil371\",\"feature\":\"xcvbnkm\",\"zodiac\":\"vbnim\",\"favorites\":\"qerrb\",\"motto\":\"cvbn\",\"irritated\":\"aguweihjok\",\"sexiest\":\"atwvyebuinmo\",\"good_evening\":\"ywsbciobnom\",\"like_to_do\":\"vdsfd371\",\"outgoing\":\"ev\",\"prefer_to\":\"ebvjnk\",\"record_date\":371,\"update_date\":372,\"profile_other_info\":{\"id\":10516,\"member_username\":\"nikhil371\",\"describe_yourself\":\"tyuh\",\"views\":371,\"admin_login\":\"\",\"screening_assigned_to\":\"\"}}}}"
|
@kulicuu If you used Using hashes, you can update a single field by doing something like this |
I agree it's to be frowned upon-- and thanks @stockholmux for elaborating on the discussion of why that is--, but it's worth mentioning it as a shortcut. For context, here's something I wrote about 8 months ago. I have had to defer the major refactor which would have moved most of the models into Redis' Lua scripts. |
@stockholmux i tried to use flat and it gives me error: MAximum call stack size exceeded .. |
I am very new to redis. So what i want is store the data retrieved from database. Now do i have to use client.set() for every key-value pair returned by database or is there any other way i can save all the data with one command? Data is of the form:
{
"member_username": "nikhil567",
"member_gender": "Male",
"member_dob": 0,
"member_country": "",
}
The text was updated successfully, but these errors were encountered: