PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, September 5, 2022

[FIXED] How can ı use GEOADD in Python ? (Redis)

 September 05, 2022     python, redis     No comments   

Issue

I want the store geospatial information in Redis. I am executing the following code

from redis import Redis

redis_con = Redis(host="localhost", port=6379)
redis_con.geoadd("Sicily", 13.361389, 38.115556, "Palermo")

But ı got error like that

raise DataError("GEOADD allows either 'nx' or 'xx', not both")

redis.exceptions.DataError: GEOADD allows either 'nx' or 'xx', not both

Solution

This will work for you:

from redis import Redis

redis_con = Redis(host="localhost", port=6379)
coords = (13.361389, 38.115556, "Palermo")
redis_con.geoadd("Sicily", coords)

The signature for geoadd is:

geoadd(name, values, nx=False, xx=False, ch=False)
    name: Union[bytes, str, memoryview]
    values: Sequence[Union[bytes, memoryview, str, int, float]]
    nx (bool, default: False)
    xx (bool, default: False)
    ch (bool, default: False) 

You need to specify your coordinates as a sequence like a list or tuple, because right now you're specifying arguments so that the method thinks you've specified nx, xx, and ch.



Answered By - wkl
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing