I am trying to decode Django's session data stored in redis DB to JSON object. I have got session data from redis DB into a variable djangoSessionData
, when in do console.log of this data, it looks like this:
���} �(�_auth_user_backend��)django.contrib.auth.backends.ModelBackend��_auth_us er_hash_auth_user_id��2��user_unique_key��abc�u.65��
When I query redis directly and see session data value, it is like this:
"\x80\x04\x95\xaf\x00\x00\x00\x00\x00\x00\x00}\x94(\x8c\x12_auth_user_backend\x94\x8c)django.contrib.auth.backends.ModelBackend\x94\x8c\x0f_auth_user_hash\x94\x8c(6d34e7154c4d217233c7346177325969d1832565\x94\x8c\r_auth_user_id\x94\x8c\x012\x94\x8c\x0fuser_unique_key\x94\x8c\x03abc\x94u."
I am trying to decode it into JSON string using:
var sessionData = new Buffer(djangoSessionData, 'base64').toString();
But when I console.log sessionData
, it looks like this:
������z��i���cjx(r���&ں�[i���
�ץ�$zwj�a����Z��߇�מ�ݵ�m�s���^��n}��u�}���ں��ǫ�'v�ǫ����翑��m˿
So looks like it is not decoding properly, how can it be decoded to JSON object in Node.js
Edit: I am using Django 1.9 and saving session to redis DB using:
SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db'