Browse Source

Move voting function to one place `votes.rkt`

master
Bonface Munyoki 2 years ago
parent
commit
15d27b45e4
Signed by: bonfacemunyoki GPG Key ID: F5BBAE1E0392253F
  1. 9
      private/github.rkt
  2. 11
      private/twitter.rkt
  3. 14
      private/votes.rkt

9
private/github.rkt

@ -111,11 +111,4 @@
`(,commits)))]))
(define (vote-commit! client key #:upvote? [upvote #t])
(let* [(n (if upvote 1 -1))
(zset-name "commit-score:")
(score (string->number (bytes->string/utf-8
(redis-hash-ref client key "score"))))]
(begin
(redis-hash-set! client key "score"
(number->string (+ score n)))
(redis-zset-incr! client zset-name key (* n 1000)))))
(vote! client "commit-score:" key #:upvote upvote))

11
private/twitter.rkt

@ -94,15 +94,8 @@
tweet-scores)))
(define (vote-tweet! client tweet-hash #:upvote? [upvote #t])
(let* [(n (if upvote 1 -1))
(key "tweet-score:")
(score (string->number (bytes->string/utf-8
(redis-hash-ref client tweet-hash "score"))))]
(begin
(redis-hash-set! client tweet-hash "score"
(number->string (+ score n)))
(redis-zset-incr! client key tweet-hash (* n 1000)))))
(define (vote-tweet! client key #:upvote? [upvote #t])
(vote! client "tweet-score" key #:upvote upvote))
;; Given a list of feed-tweets, store them in REDIS

14
private/votes.rkt

@ -4,7 +4,8 @@
(provide remove-expired-keys!
remove-all-keys!)
remove-all-keys!
vote!)
(define (remove-expired-keys! client zset-keys/list)
@ -22,9 +23,20 @@
keys)
#t))
(define (remove-all-keys! client key/regexp)
;; Remove any stale tweets
(map (lambda (key)
(redis-remove! client key))
(redis-keys client key/regexp))
#t)
(define (vote! client zset-key hash #:upvote? [upvote #t])
(let* [(n (if upvote 1 -1))
(score (string->number (bytes->string/utf-8
(redis-hash-ref client hash "score"))))]
(begin
(redis-hash-set! client hash "score"
(number->string (+ score n)))
(redis-zset-incr! client zset-key hash (* n 1000)))))
Loading…
Cancel
Save