Skip to content

pairs_to_dict forces float cast for values #18

Closed
@SJD

Description

@SJD

Heya Andy, thanks for the speedy turnaround on the new hash functions. I notice however that the pairs_to_dict function is forcing values to be cast as float via a map call. Is this intended? It means I can't put string values into a hash.

r.hset('foo', 'bar', 'zoo')
1
r.hgetall('foo')
Traceback (most recent call last):
File "", line 1, in
File "redis/client.py", line 902, in hgetall
File "redis/client.py", line 325, in format_inline
File "redis/client.py", line 247, in execute_command
File "redis/client.py", line 242, in _execute_command
File "redis/client.py", line 310, in parse_response
File "redis/client.py", line 207, in
File "redis/client.py", line 158, in pairs_to_dict
ValueError: invalid literal for float(): zoo

Not sure what side effect there would be from removing the float call - other than everything coming back as a string. Maybe instead of mapping to float, it could use a function like this?

def map_type(value):
... try:
... return '.' in value and float(value) or int(value)
... except ValueError:
... return value

Anyway, thought I would let you know =]

Cheers
Sam

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions