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.
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 just
csv_filename`.
Try changing the line key = "xyzxyz:%s" % (row[0],)
to just key = "xyzxyz"
.