Question

Below is my script which inserts data from a csv located on one server into Redis on another server. If it worked..

I don't get an error but I don't show any data received on the redis side either. So Iam not sure which is worse.

#!/opt/python/bin/python


import csv
import redis
from redis import StrictRedis

reader = csv.reader(open("/opt/xyzxyz.csv"))
header = reader.next()


client = redis.StrictRedis(host='XXXXXXXXX.XX.XXX.X.XXX', port=6379, db=0)

for row in reader:
    key = "xyzxyz:%s" % (row[0], )
    doc = dict(zip(header, row))

    client.publish(key, doc)

Any thoughts on what I am missing from the above process? Or if there is something I am not doing on the redis side?

This is my first time working with Redis so it is kinda new to me.

Was it helpful?

Solution

You probably want to be using client.set(key, doc) rather than client.publish(key, doc).

Publish has a totally different meaning from set, which is more likely what you want.

Edit

(thanks for accepting, I'm just editing this to make it the actual solution to your problem)

The first parameter of client.publish is the channel you're publishing to. It sounds like in your case you're publishing to 'csv_filename:first_entry_of_rowwhen really you want to be publishing to justcsv_filename`.

Try changing the line key = "xyzxyz:%s" % (row[0],) to just key = "xyzxyz".

OTHER TIPS

Look out for these two things:

  1. Check the bind variable in redis.conf file. Either you comment it or add your ip address with space separated. Either bind 192.168.1.100, 10.0.0.1, your_ip or just comment that line out.
  2. Use client.set function instead of client.push.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top