質問編集履歴
1
試したことを追加しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -249,3 +249,61 @@
|
|
249
249
|
|
250
250
|
|
251
251
|
```
|
252
|
+
|
253
|
+
試したこと
|
254
|
+
|
255
|
+
rails,redisサーバーの再起動
|
256
|
+
|
257
|
+
redis_deleteを削除し、def redis_delete
|
258
|
+
|
259
|
+
REDIS.zrem "comments", params[:id]
|
260
|
+
|
261
|
+
endを追加
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
```ここに言語を入力
|
266
|
+
|
267
|
+
class Comment < ApplicationRecord
|
268
|
+
|
269
|
+
validates :user_id, {presence: true}
|
270
|
+
|
271
|
+
after_destroy do
|
272
|
+
|
273
|
+
REDIS.zrem "comments", self.id
|
274
|
+
|
275
|
+
end
|
276
|
+
|
277
|
+
def redis_access
|
278
|
+
|
279
|
+
REDIS.zincrby "comments", 1, self.id
|
280
|
+
|
281
|
+
end
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
def redis_page_view
|
286
|
+
|
287
|
+
REDIS.zscore("comments", self.id).floor
|
288
|
+
|
289
|
+
end
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
def Comment.most_popular(limit: 3)
|
294
|
+
|
295
|
+
most_popular_ids = REDIS.zrevrangebyscore "comments", "+inf", 0, limit: [0, 3]
|
296
|
+
|
297
|
+
where(id: most_popular_ids).sort_by{ |comment| most_popular_ids.index(comment.id.to_s) }
|
298
|
+
|
299
|
+
end
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
end
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
```
|