gg_1234
gg_1234

Reputation: 117

Spring Session Token

Explored spring session and redis it looks really good.

Trying to solve one question for a long time , how to retrieve list of session token from redis db based on the spring session token value in the hash .

I know its not a relational database and there is no straightforward way to achieve but is that a way to figure this out which is really important for us to solve problems

I read in blogs we need to keep a set to track , are there any ways to acheive this when using spring session. i am not even sure how to do this

Any help is highly appreciated .

Thank you

Upvotes: 1

Views: 898

Answers (2)

Deepak Kumar
Deepak Kumar

Reputation: 1699

Useful Commands:

  1. redis-cli : To enter into redis console Example:

    root@root>redis-cli

    127.0.0.1:6379> _

  2. keys * :Shows all keys stored in redis DB
    Example:

    127.0.0.1:6379>keys *

    “spring:session:expirations:1440354840000“

    “spring:session:sessions:3b606f6d-3d30-4afb-bea6-ef3a4adcf56b“

  3. monitor : To monitor the redis DB

    127.0.0.1:6379> monitor

    OK

    1441273902.701071 [0 127.0.0.1:49137] "PING" 1441273920.000888 [0 127.0.0.1:49137] "SMEMBERS"

  4. hgetall SESSION_ID :To check all the keys stored inside a session
    example: :

    127.0.0.1:6379>hgetall spring:session:sessions:3b606f6d-3d30-4afb-bea6-ef3a4adcf56b

  5. flushall Remove all keys from the DB.

    Example :

    127.0.0.1:6379> flushall

    ok

Upvotes: 1

Paul McCready
Paul McCready

Reputation: 11

Open redis-cli then run

127.0.0.1:6379> keys *
1) "spring:session:expirations:1435594380000"
2) "spring:session:sessions:05adb1d7-c7db-4ffb-99f7-47d7bd1867ee"

127.0.0.1:6379> type spring:session:sessions:05adb1d7-c7db-4ffb-99f7-47d7bd1867ee
hash

127.0.0.1:6379> hgetall spring:session:sessions:05adb1d7-c7db-4ffb-99f7-47d7bd1867ee
 1) "sessionAttr:SPRING_SECURITY_CONTEXT"
 2) ""
 3) "sessionAttr:javax.servlet.jsp.jstl.fmt.request.charset"
 4) "\xac\xed\x00\x05t\x00\x05UTF-8"
 5) "creationTime"
 6) "\xac\xed\x00\x05sr\x00\x0ejava.lang.Long;\x8b\xe4\x90\xcc\x8f#\xdf\x02\x00\x01J\x00\x05valuexr\x00\x10java.lang.Number\x86\xac\x95\x1d\x0b\x94\xe0\x8b\x02\x00\x00xp\x00\x00\x01N?\xfb\xb6\x83"
 7) "maxInactiveInterval"
 8) "\xac\xed\x00\x05sr\x00\x11java.lang.Integer\x12\xe2\xa0\xa4\xf7\x81\x878\x02\x00\x01I\x00\x05valuexr\x00\x10java.lang.Number\x86\xac\x95\x1d\x0b\x94\xe0\x8b\x02\x00\x00xp\x00\x00\a\b"
 9) "lastAccessedTime"
10) "\xac\xed\x00\x05sr\x00\x0ejava.lang.Long;\x8b\xe4\x90\xcc\x8f#\xdf\x02\x00\x01J\x00\x05valuexr\x00\x10java.lang.Number\x86\xac\x95\x1d\x0b\x94\xe0\x8b\x02\x00\x00xp\x00\x00\x01N?\xfb\xb6\xa6"

127.0.0.1:6379> 

Upvotes: 0

Related Questions