get value from hash

94 views
Skip to first unread message

Manish

unread,
Aug 13, 2012, 4:23:33 AM8/13/12
to redi...@googlegroups.com

i have one hash named "UserMst" with value [UserName, EMailID, FirstName,lastName etc]

i had stored it like 
redis-cli->hmset "UserMst:" + UserID UserName:[UserName], EMailID:[EMail], FirstName[FirstName]

i have one another set "BirthDayMst" which is contain Birth date and its UserID
redis-cli->add BirthdayMst:[Date] UserID

now i want to get current date's user list 
so i am trying 
redis-cli->sinter BirthDayMst:[date] get UserMst:*->EMailID

but it shows "<empty list or set>"

but if i am trying 

redis-cli->sinterstore tmp BirthDayMst:[date]  

redis-cli-> sort tmp by nosort get UserMst:*->EMailID

it gives me perfect result..

so what is the mistek 


Didier Spezia

unread,
Aug 13, 2012, 4:35:44 AM8/13/12
to redi...@googlegroups.com

You cannot use the syntax available in the SORT command in
all other commands.

With the SINTER command, you can only provide sets as parameters
(no get subcommand, no *, no ->, etc ...)

Regards,
Didier.

Manish

unread,
Aug 13, 2012, 4:57:33 AM8/13/12
to redi...@googlegroups.com
so how i get answer for above situation? please help me....

Didier Spezia

unread,
Aug 13, 2012, 5:19:53 AM8/13/12
to redi...@googlegroups.com

You can apply the sort command directly to the set:

redis 127.0.0.1:6379> hmset UserMst:1 username Bush emailid gb...@whitehouse.gov firstname W
OK
redis 127.0.0.1:6379> hmset UserMst:2 username Obama emailid bob...@whitehouse.gov firstname Barack
OK
redis 127.0.0.1:6379> sadd BirthDayMst:19550101 1 2
(integer) 2
redis 127.0.0.1:6379> sort BirthDayMst:19550101 by nosort get UserMst:*->emailid

Regards,
Didier.

Manish

unread,
Aug 13, 2012, 6:46:50 AM8/13/12
to redi...@googlegroups.com
thank you very much for reply... it is working

but i have to get all fields for hash.

therefor i have issued following command
redis-cli> sort BirthDayMst:19550101 by nosort hgetall UserMst:*

but it shows error : "ERR syntax error"

Didier Spezia

unread,
Aug 13, 2012, 7:47:04 AM8/13/12
to redi...@googlegroups.com

You cannot combine commands like this.

The SORT command is able to do what is described in the documentation,
and nothing more: http://redis.io/commands/sort 

If you know which fields of the hash you are interested in, you only need
one command (just repeat a number of get clauses in the command):

> sort BirthDayMst:19550101 by nosort get UserMst:*->emailid get UserMst:*->firstname get UserMst:*->useraname
2) "W"
3) "Bush"
5) "Barack"
6) "Obama"

If you really need to retrieve all the fields, then it cannot be achieved in one SORT
command. For this, you need two rountrips, the second being used to pipeline
several hgetall commands:

For instance:

> smembers BirthDayMst:19550101

1) "1"
2) "2"

> hgetall UserMst:1
> hgetall UserMst:2

1) "username"
2) "Bush"
3) "emailid"
5) "firstname"
6) "W"
1) "username"
2) "Obama"
3) "emailid"
5) "firstname"
6) "Barack"

Most Redis clients support pipelining.

Regards,
Didier.

Catherine Jung

unread,
Aug 13, 2012, 7:17:10 AM8/13/12
to redi...@googlegroups.com
You can't just whack hgetall in there - you need to specify the fields you want out like this:

sort BirthDayMst:19550101 by nosort GET UserMst:*->UserName GET UserMst:*-> EMailID GET UserMst:*->FirstName etc.

Catherine

On Mon, Aug 13, 2012 at 11:46 AM, Manish <sapkal...@gmail.com> wrote:
thank you very much for reply... it is working

but i have to get all fields for hash.

therefor i have issued following command
redis-cli> sort BirthDayMst:19550101 by nosort hgetall 

 
but it shows error : "ERR syntax error"




On Monday, August 13, 2012 1:53:33 PM UTC+5:30, Manish wrote:

i have one hash named "UserMst" with value [UserName, EMailID, FirstName,lastName etc]

i had stored it like 
redis-cli->hmset "UserMst:" + UserID UserName:[UserName], EMailID:[EMail], FirstName[FirstName]

i have one another set "BirthDayMst" which is contain Birth date and its UserID
redis-cli->add BirthdayMst:[Date] UserID

now i want to get current date's user list 
so i am trying 
redis-cli->sinter BirthDayMst:[date] get UserMst:*->EMailID

but it shows "<empty list or set>"

but if i am trying 

redis-cli->sinterstore tmp BirthDayMst:[date]  

redis-cli-> sort tmp by nosort get UserMst:*->EMailID

it gives me perfect result..

so what is the mistek 


--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To view this discussion on the web visit https://groups.google.com/d/msg/redis-db/-/sfI4Mv06hKEJ.

To post to this group, send email to redi...@googlegroups.com.
To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.

gradetwo

unread,
Aug 14, 2012, 12:16:43 AM8/14/12
to redi...@googlegroups.com
If u have large birthday sets, pls try below two steps.

1. smembers BirthdayMst:[Date]
2. hgetall UserMst:[UserID] use pipeline
Reply all
Reply to author
Forward
0 new messages