@@ -783,7 +783,7 @@ var _ = Describe("Ring Tx timeout", func() {
783783 })
784784})
785785
786- var _ = Describe ("Ring GetShards and GetShardByKey " , func () {
786+ var _ = Describe ("Ring GetShardClients and GetShardClientForKey " , func () {
787787 var ring * redis.Ring
788788
789789 BeforeEach (func () {
@@ -799,8 +799,12 @@ var _ = Describe("Ring GetShards and GetShardByKey", func() {
799799 Expect (ring .Close ()).NotTo (HaveOccurred ())
800800 })
801801
802- It ("GetShards returns active shard clients" , func () {
803- shards := ring .GetShards ()
802+ It ("GetShardClients returns active shard clients" , func () {
803+ shards := ring .GetShardClients ()
804+ // Note: This test will pass even if Redis servers are not running,
805+ // because GetShardClients only returns clients that are marked as "up",
806+ // and newly created shards start as "up" until the first health check fails.
807+
804808 if len (shards ) == 0 {
805809 // Expected if Redis servers are not running
806810 Skip ("No active shards found (Redis servers not running)" )
@@ -812,22 +816,24 @@ var _ = Describe("Ring GetShards and GetShardByKey", func() {
812816 }
813817 })
814818
815- It ("GetShardByKey returns correct shard for keys" , func () {
819+ It ("GetShardClientForKey returns correct shard for keys" , func () {
816820 testKeys := []string {"key1" , "key2" , "user:123" , "channel:test" }
817821
818822 for _ , key := range testKeys {
819- client , err := ring .GetShardByKey (key )
823+ client , err := ring .GetShardClientForKey (key )
820824 Expect (err ).NotTo (HaveOccurred ())
821825 Expect (client ).NotTo (BeNil ())
822826 }
823827 })
824828
825- It ("GetShardByKey is consistent for same key" , func () {
829+ It ("GetShardClientForKey is consistent for same key" , func () {
826830 key := "test:consistency"
827831
832+ // Call GetShardClientForKey multiple times with the same key
833+ // Should always return the same shard
828834 var firstClient * redis.Client
829835 for i := 0 ; i < 5 ; i ++ {
830- client , err := ring .GetShardByKey (key )
836+ client , err := ring .GetShardClientForKey (key )
831837 Expect (err ).NotTo (HaveOccurred ())
832838 Expect (client ).NotTo (BeNil ())
833839
@@ -839,17 +845,19 @@ var _ = Describe("Ring GetShards and GetShardByKey", func() {
839845 }
840846 })
841847
842- It ("GetShardByKey distributes keys across shards" , func () {
848+ It ("GetShardClientForKey distributes keys across shards" , func () {
843849 testKeys := []string {"key1" , "key2" , "key3" , "key4" , "key5" }
844850 shardMap := make (map [string ]int )
845851
846852 for _ , key := range testKeys {
847- client , err := ring .GetShardByKey (key )
853+ client , err := ring .GetShardClientForKey (key )
848854 Expect (err ).NotTo (HaveOccurred ())
849855 shardMap [client .String ()]++
850856 }
851857
858+ // Should have at least 1 shard (could be all keys go to same shard due to hashing)
852859 Expect (len (shardMap )).To (BeNumerically (">=" , 1 ))
860+ // But with multiple keys, we expect some distribution
853861 Expect (len (shardMap )).To (BeNumerically ("<=" , 2 )) // At most 2 shards (our setup)
854862 })
855863})
0 commit comments