문제

I'm interested in using Node.js as a socket server for stream-based communication with tens of thousands of clients. Clients will be sending votes for particular pieces of content and receiving near-real-time updates of aggregated vote tallies from the server.

The datastore needs to support:

  1. Storing the votes
  2. Summarising the votes in near-realtime
  3. Preventing multiple votes within an arbitrary time period (e.g. clients can only vote once for a piece of content every 1 minute)

Something that already has client libraries for Node.js would be preferable.

도움이 되었습니까?

해결책

I would highly recommend Redis. It is a key/value store with set and list operations. It also supports atomic operations for counters. There is a client for Redis for Node.js available on github. Here is how I would implement your features:

Storing the votes

INCR votes:option:<option>

Summarizing the votes

MGET votes:option:<option1> votes:option:<option2> ... votes:option:<optionN>

Preventing multiple votes (create an expiring lock key for client IP)

EXPIRE lock:<encoded ip> 60
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top