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

Example in README is broken, raise exception wrong number of arguments for 'hset' command #179

Closed
raceychan opened this issue Mar 31, 2022 · 5 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@raceychan
Copy link

below is the detail of the exception:

File "/root/myproject/mystatement/src/deps/event_store.py", line 64, in main
await andrew.save()
File "/root/deps/miniconda3/envs/spps/lib/python3.8/site-packages/aredis_om/model/model.py", line 1303, in save
await db.hset(self.key(), mapping=document)
File "/root/deps/miniconda3/envs/spps/lib/python3.8/site-packages/aioredis/client.py", line 1064, in execute_command
return await self.parse_response(conn, command_name, **options)
File "/root/deps/miniconda3/envs/spps/lib/python3.8/site-packages/aioredis/client.py", line 1080, in parse_response
response = await connection.read_response()
File "/root/deps/miniconda3/envs/spps/lib/python3.8/site-packages/aioredis/connection.py", line 868, in read_response
raise response from None
aioredis.exceptions.ResponseError: wrong number of arguments for 'hset' command

above exception happened after running:

class Customer(HashModel):
    first_name: str
    last_name: str
    email: str
    join_date: datetime.date
    age: int
    bio: Optional[str]

# First, we create a new `Customer` object:
andrew = Customer(
    first_name="Andrew",
    last_name="Brookins",
    email="andrew.brookins@example.com",
    join_date=datetime.date.today(),
    age=38,
    bio="Python developer, works at Redis, Inc.",
)

print(andrew.pk)
await andrew.save()
a = await Customer.get(andrew.pk)
print(a)

pip show aioredis:
Name: aioredis
Version: 2.0.0

pip show redis-om
Name: redis-om
Version: 0.0.20

@simonprickett
Copy link
Contributor

What version of Redis server are you running this against please? HSET started to accept multiple name/value pairs from Redis 4 onwards (https://redis.io/commands/hset/) and if you are using an older Redis server you'll need to move to at least version 5, preferably 6.

@raceychan
Copy link
Author

What version of Redis server are you running this against please? HSET started to accept multiple name/value pairs from Redis 4 onwards (https://redis.io/commands/hset/) and if you are using an older Redis server you'll need to move to at least version 5, preferably 6.

thanks, would check on that and update.

@raceychan

This comment was marked as resolved.

@simonprickett simonprickett self-assigned this Apr 27, 2022
@simonprickett simonprickett added the documentation Improvements or additions to documentation label Apr 27, 2022
@simonprickett
Copy link
Contributor

Hi there - this is working for me, I did have to change example.com in the email from the README to something else as the email validator appears to actually check for a valid domain... other than that it worked as shown in the README:

import datetime
from typing import Optional

from pydantic import EmailStr

from redis_om import HashModel


class Customer(HashModel):
    first_name: str
    last_name: str
    email: EmailStr
    join_date: datetime.date
    age: int
    bio: Optional[str]

# First, we create a new `Customer` object:
andrew = Customer(
    first_name="Andrew",
    last_name="Brookins",
    email="andrew.brookins@whatever.com",
    join_date=datetime.date.today(),
    age=38,
    bio="Python developer, works at Redis, Inc."
)

# The model generates a globally unique primary key automatically
# without needing to talk to Redis.
print(andrew.pk)
# > "01FJM6PH661HCNNRC884H6K30C"

# We can save the model to Redis by calling `save()`:
andrew.save()

# Expire the model after 2 mins (120 seconds)
andrew.expire(120)

# To retrieve this customer with its primary key, we use `Customer.get()`:
assert Customer.get(andrew.pk) == andrew

@raceychan
Copy link
Author

you are right, it works well after i change to a new machine. not sure wts wrong here tho.

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

No branches or pull requests

2 participants