im是Redis的新功能,并尝试显示已排序的特定值的排序集。 Redis有办法做到这一点吗?
DECLARE @Database NVARCHAR(255)
DECLARE @Table NVARCHAR(255)
DECLARE @cmd NVARCHAR(1000)
DECLARE DatabaseCursor CURSOR READ_ONLY FOR
SELECT name FROM master.sys.databases
WHERE name IN ('YOUR DATABASE NAME') -- databases
AND state = 0 -- database is online
AND is_in_standby = 0 -- database is not read only for log shipping
ORDER BY 1
OPEN DatabaseCursor
FETCH NEXT FROM DatabaseCursor INTO @Database
WHILE @@FETCH_STATUS = 0
BEGIN
SET @cmd = 'DECLARE TableCursor CURSOR READ_ONLY FOR SELECT ''['' + table_catalog + ''].['' + table_schema + ''].['' +
table_name + '']'' as tableName FROM [' + @Database + '].INFORMATION_SCHEMA.TABLES WHERE table_type = ''BASE TABLE'''
-- create table cursor
EXEC (@cmd)
OPEN TableCursor
FETCH NEXT FROM TableCursor INTO @Table
WHILE @@FETCH_STATUS = 0
BEGIN
BEGIN TRY
SET @cmd = 'ALTER INDEX ALL ON ' + @Table + ' REBUILD'
PRINT @cmd -- uncomment if you want to see commands
EXEC (@cmd)
END TRY
BEGIN CATCH
PRINT '---'
PRINT @cmd
PRINT ERROR_MESSAGE()
PRINT '---'
END CATCH
FETCH NEXT FROM TableCursor INTO @Table
END
CLOSE TableCursor
DEALLOCATE TableCursor
FETCH NEXT FROM DatabaseCursor INTO @Database
END
CLOSE DatabaseCursor
DEALLOCATE DatabaseCursor
我只想与朋友一起显示带有分数的排序集。
SADD friends "Sarah"
SADD friends "Lisa"
SADD friends "Tim"
ZADD users 200 "Sarah"
ZADD users 133 "Lisa"
ZADD users 410 "Peter"
ZADD users 280 "Tim"
ZADD users 205 "Hans"
答案 0 :(得分:2)
您可以使用ZINTERSTORE,因为它也可以与常规SET一起使用。请注意,它将使用1作为元素分数,但是您可以使用权重0删除它:
ZINTERSTORE aux_zset 2 friends users weights 0 1
结果ZSET有您的答案:
127.0.0.1:6379> zrange aux_zset 0 -1 withscores
1) "Lisa"
2) "133"
3) "Sarah"
4) "200"
5) "Tim"
6) "280"