Skip to content
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

Member data type error #39

Closed
jgadbois opened this issue May 23, 2013 · 9 comments
Closed

Member data type error #39

jgadbois opened this issue May 23, 2013 · 9 comments

Comments

@jgadbois
Copy link
Contributor

Using leaderboard 2.2.1.

This is the same issue that I opened the other day. I recently upgraded to redis-rb version 3 and upgraded leaderboard. On my development and staging servers I am fine. On production I get a lot of errors. The error seems to be related to calling:

leader = leaderboard.member_at(1, :with_member_data=>true)

When I attempt to access my member data (leader[:member_data]["workout_exercise"]) I get the following error:

TypeError: can't convert String into Integer

Any idea what could be going on?

@jeffarena
Copy link

The return value from leader[:member_data] is likely an Array, which you're attempting to access as if it's a Hash.

@jgadbois
Copy link
Contributor Author

I'm putting in a hash though and it's a hash on development and production. Does 2.2.1 handle adding member data differently from older versions?

@jgadbois
Copy link
Contributor Author

Here's how records get put in my leaderboard

        Records::LeaderboardFactory.create(base(exercise_id)).rank_member(user.id, record, { workout_exercise: workout_exercise.id, workout: workout_exercise.workout_id, exercise: exercise_id, nickname: user.nickname, slug: user.cached_slug, workout_date: workout_exercise.workout.workout_date.to_i })

I actually have thousands of leaderboards and I'm using a Factory class that I wrote to instantiate/fetch the leaderboard, but you can see the rank_member call is putting in a hash.

@jgadbois
Copy link
Contributor Author

Also - when I rollback my code, I can still access the leaderboard member data fine with the older gem version (which means it is getting stored correctly as a hash even with the newer versions)

@jgadbois
Copy link
Contributor Author

Ok - here's more info: Member data is indeed being converted to an array instead of staying in a hash:

["workout_exercise", "109135", "workout", "14375", "exercise", "14301", "nickname", "user1", "slug", "user1", "workout_date", "1369180800"]

irb(main):004:0> REDIS
=> #<Redis client v3.0.4 for redis://184.73.236.163:11184/0>
irb(main):005:0> Leaderboard::VERSION
=> "2.2.1"

@jgadbois
Copy link
Contributor Author

According to the Redis docs hgetall returns an array not a hash, which means member_data is an array since it just calls hgetall. However, before updating, member_data has been a hash, not an array. Any idea if it's a change in leaderboard or a change in REDIS or a change in both?

@czarneckid
Copy link
Member

The difference between leaderboard 2.x and 3.x is that in 2.x, optional member data is stored as a hash in Redis per-member, where in 3.x, optional member data is stored as a string as part of a hash in Redis for all members. More details in the original proposal, #26.

@jgadbois
Copy link
Contributor Author

I totally forgot about that :) For now I was able to get it working using leaderboard 2.x with redis-rb 3 by just manually converting member data from an array back to a hash like my code expected. I'll think about a migration path so I can use the latest version of leaderboard. Sorry for all the back and forth, totally forgot about that.

@czarneckid
Copy link
Member

No problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants