0

This is copy of the code in mining the social web book.

I am a new in this field and with redis too. I want to understand what does $ mean in this context. Also the print with %s, What does it mean?

This is the source code below (from: https://github.com/ptwobrussell/Mining-the-Social-Web):

import sys
import redis

from twitter__util import getRedisIdByScreenName

# A pretty-print function for numbers
from twitter__util import pp

r = redis.Redis()
screen_names=['user1','user2']
def friendsFollowersInCommon(screen_names):
    r.sinterstore('temp$friends_in_common',
        [getRedisIdByScreenName(screen_name, 'friend_ids')
         for screen_name in screen_names]
    )

r.sinterstore('temp$followers_in_common',
    [getRedisIdByScreenName(screen_name, 'follower_ids')
     for screen_name in screen_names]
)

print 'Friends in common for %s: %s' % (', '.join(screen_names),
                                        pp(r.scard('temp$friends_in_common')))

print 'Followers in common for %s: %s' % (', '.join(screen_names),
                                          pp(r.scard('temp$followers_in_common')))

# Clean up scratch workspace

r.delete('temp$friends_in_common')
r.delete('temp$followers_in_common')

if __name__ == "__main__":
    if len(screen_names) < 2:
        print >> sys.stderr, "Please supply at least two screen names."
        sys.exit(1)

friendsFollowersInCommon(screen_names[1:])
Santosh Kumar
  • 26,475
  • 20
  • 67
  • 118
user1511208
  • 67
  • 1
  • 3
  • 9

1 Answers1

1

$ symbol is just a part of key name. It separates name parts. I usually use : for the same purpose (e.g. users:123)

%s part is 's string formatting.

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
  • what about this part ? r.sinterstore('temp$followers_in_common', [getRedisIdByScreenName(screen_name, 'follower_ids') for screen_name in screen_names] – user1511208 Jul 23 '12 at 10:03
  • I mean, the [] the first part is method then for loop .what does this mean? – user1511208 Jul 23 '12 at 10:11
  • This is python's list comprehension. I suggest that you familiarize yourself with the language (python) before you learn new technology (redis). – Sergio Tulentsev Jul 23 '12 at 10:13